5

I am trying to run the website code to create the image.

When I run the code it gives me an error:

cv2.error: OpenCV(4.1.0) 
/Users/travis/build/skvark/opencv-python/opencv/modules/imgproc/src/shapedescr.cpp:274: 
error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) 
in function 'contourArea'

I am not sure about the reason behind it.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
qing zhang
  • 125
  • 1
  • 4
  • 13

2 Answers2

10

The repo is clearly written for OpenCV 3.x. But, you are running on OpenCV 4.1. Repo code takes find_contour's second return value for contours( find_contours(...)[1] ). You should change 1 to 0.

Sıddık Açıl
  • 957
  • 8
  • 18
3

cnts = cv2.findContours(...)[0]

this should solve your problem as in OpenCV (4>) findContours(...)[0] gives you the contours

Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Sahana M
  • 485
  • 6
  • 4