Want to find contours -> ValueError: not enough values to unpack (expected 3, got 2), this appears

前端 未结 2 1757
心在旅途
心在旅途 2020-12-02 22:49

My simple python code is this

import cv2

img=cv2.imread(\'Materials/shapes.png\')

blur=cv2.GaussianBlur(img,(3,3),0)
gray=cv2.cvtColor(blur,cv2.COLOR_BGR2G         


        
2条回答
  •  不知归路
    2020-12-02 22:56

    Well explained in this python code example, the best way to make your code version-proof is with this following syntax:

    # check OpenCV version
    major = cv2.__version__.split('.')[0]
    if major == '3':
        ret, contours, hierarchy = cv2.findContours(im.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    else:
        contours, hierarchy = cv2.findContours(im.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    

    This provides you a code that could run on last or older version of OpenCV.

提交回复
热议问题