Python 3.x 使用opencv(图像处理)查找轮廓

Python 3.x 使用opencv(图像处理)查找轮廓,python-3.x,opencv,image-processing,opencv3.0,Python 3.x,Opencv,Image Processing,Opencv3.0,我一直在从事一个项目“汽车牌照检测器”,我正在使用opencv实现该项目。在更新了我的Python版本和opencv之后,我在查找轮廓时出错,如下所示: imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # find all contours ValueError: not enough values to unpack (

我一直在从事一个项目“汽车牌照检测器”,我正在使用
opencv
实现该项目。在更新了我的
Python版本
opencv
之后,我在查找轮廓时出错,如下所示:

imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)   # find all contours
ValueError: not enough values to unpack (expected 3, got 2)
这是我使用的代码:

def findPossibleCharsInScene(imgThresh):
listOfPossibleChars = []                # this will be the return value

intCountOfPossibleChars = 0

imgThreshCopy = imgThresh.copy()

imgContours, contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)   # find all contours

height, width = imgThresh.shape
imgContours = np.zeros((height, width, 3), np.uint8)

for i in range(0, len(contours)):                       # for each contour

    if Main.showSteps == True: # show steps ###################################################
        cv2.drawContours(imgContours, contours, i, Main.SCALAR_WHITE)
    # end if # show steps #####################################################################

    possibleChar = PossibleChar.PossibleChar(contours[i])

    if DetectChars.checkIfPossibleChar(possibleChar):                   # if contour is a possible char, note this does not compare to other chars (yet) . . .
        intCountOfPossibleChars = intCountOfPossibleChars + 1           # increment count of possible chars
        listOfPossibleChars.append(possibleChar)                        # and add to list of possible chars
    # end if
# end for

if Main.showSteps == True: # show steps #######################################################
    print("\nstep 2 - len(contours) = " + str(len(contours)))  # 2362 with MCLRNF1 image
    print("step 2 - intCountOfPossibleChars = " + str(intCountOfPossibleChars))  # 131 with MCLRNF1 image
    cv2.imshow("2a", imgContours)
# end if # show steps #########################################################################

return listOfPossibleChars
# end function
我应该做哪些更改来更正它?

我认为cv2.findContours()函数只返回2个值。您应该将代码更改为以下内容

contours, npaHierarchy = cv2.findContours(imgThreshCopy, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

为了补充您的答案,它从2个返回值(至少版本2.4.x)更改为3(我可以确认版本3.4和3.5),现在又是2(版本4.x)。这就是为什么它如此令人困惑的原因,很多教程都有错误,这取决于我所使用的OpenCV版本,这正是我所面临的问题