Skip to content

Error on ContourAreas #3

Description

@thelwyn

Hi,

While initially playing your code i was running into this error:

`
File "C:/Users/thinkpad/Desktop/read_serial.py", line 56, in
if cv2.contourArea(c) < 300:

error: OpenCV(4.0.1-dev) C:\Users\thinkpad\Documents\openCV4Win\opencv-master\opencv\modules\imgproc\src\shapedescr.cpp:274: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'cv::contourArea'`

I fixed it by adding one variable in this line:

#cnts = cv2.findContours(dilate.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE) cnts,hierarchy = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)

It seens related to how different versions of OpenCv need different numbers of parameters for findContours.

I would have thought that the next line would cover for that, but apparently not:
cnts = cnts[0] if imutils.is_cv2() else cnts[1]

Anyway, I got it working, and I actually post this issue because I didn't find another way to thank you and send my greetings :)
Cheers!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions