gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 22:18:23 25 4
gpt4 key购买 nike

我一直在使用 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)

关于python-3.x - 使用opencv查找轮廓(图像处理),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54861303/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com