OpenCV轮廓-需要两个以上的值来解压 [英] OpenCV Contours - need more than 2 values to unpack
本文介绍了OpenCV轮廓-需要两个以上的值来解压的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用以下代码实现轮廓.
I am trying to implement contours using the following code..
im = cv2.imread('C:\Users\Prashant\Desktop\T.jpg')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
img = cv2.drawContour(im, contours, -1, (0,255,0), 3)
cv2.imshow('Image1',img)
但是我不断出现以下错误.
but i am continously getting the following error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 540, in runfile
execfile(filename, namespace)
File "C:/Users/Prashant/.spyder2/.temp.py", line 17, in <module>
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
ValueError: need more than 2 values to unpack
函数findContours是否需要更多参数? 我该怎么做才能纠正它.
do the function findContours need more arguments? wht could i do to correct it.
推荐答案
在OpenCV 2中, findContours
仅返回两个值,contours
和hierarchy
.当python尝试将这两个值分配给该语句左侧给出的三个名称时,就会发生错误:
In OpenCV 2, findContours
returns just two values, contours
and hierarchy
. The error occurs when python tries to assign those two values to the three names given on left in this statement:
image, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
这篇关于OpenCV轮廓-需要两个以上的值来解压的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文