Opencv3.3.0 Findcontours Error
Solution 1:
What is
(2,2)? The fourth positional argument forfindContours()is the outputcontoursarray. But you're not passing it a valid format for thecontoursarray (which is an array of points). If it's supposed to be theoffsetand you don't want to provide the additional positional arguments, you need to call it by keyword likeoffset=(2,2). This is the reason for the actual error. I'm not sure why this worked in the previous version, as it accepted the same arguments in the same order, and Python has been like this forever; if the arguments are optional, you need to provide enough positional arguments up to the argument, or provide it a keyword.findContours()returns three values in OpenCV 3 (in OpenCV 2 it was just two values),contoursis the second return value; should be_, contours, _ = findContours(...)Also you don't have to wrap into a
tuplein python for assignment, you can just dox, y, z = fun(), no need to do(x, y, z) = fun(). Additionally you could just ask for the second return value by indexing the result likecontours = cv2.findContours(...)[1]
So this should clear you up:
cnts = cv2.findContours(gray, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE, offset=(2,2))[1]
These docs for OpenCV 3 have the Python syntax, so you can browse there if any of your other prior code breaks, and see if the syntax has changed.
Post a Comment for "Opencv3.3.0 Findcontours Error"