LineFiller icon indicating copy to clipboard operation
LineFiller copied to clipboard

Opencv version compatibility issue

Open choigww opened this issue 3 years ago • 0 comments

Hi, thanks for your work.

While testing your codes, I found an error:

/content/LineFiller/linefiller/trappedball_fill.py in get_border_point(points, rect, max_height, max_width)
    284 
    285     # Get shape.
--> 286     _, contours, _ = cv2.findContours(fill, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    287     approx_shape = cv2.approxPolyDP(contours[0], 0.02 * cv2.arcLength(contours[0], True), True)
    288 

ValueError: not enough values to unpack (expected 3, got 2)

I guess there is a version compatibility issue for opencv, since cv2.findContours may return 2 or 3 values according to the opencv version.

I think the solution is simple:

# as is
_, contours, _ = cv2.findContours(fill, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

# to be
contours = cv2.findContours(fill, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2]

Thanks.

choigww avatar Sep 08 '21 02:09 choigww