python - 使用 cv2.findContours() OpenCV 时出现 ValueError

标签 python opencv

我想检测汽车牌照的字符。我看到了this post昨天,但是当我运行该程序时出现此错误:

   contours,hierarchy = cv2.findContours(imgBWcopy.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) 
ValueError: too many values to unpack"

为什么?有人有不同的检测字符的方法吗?

最佳答案

根据 documentation 中的示例, cv2.findContours() 返回 3 个值,您必须声明变量以准确存储 3 个值。

See, there are three arguments in cv2.findContours() function, first one is source image, second is contour retrieval mode, third is contour approximation method. And it outputs the image, contours and hierarchy. contours is a Python list of all the contours in the image. Each individual contour is a Numpy array of (x,y) coordinates of boundary points of the object.

image,contours,hierarchy = cv2.findContours(imgBWcopy.copy(), cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)

关于python - 使用 cv2.findContours() OpenCV 时出现 ValueError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30423049/

相关文章:

opencv - 使用 visual studio 2013 时在 Opencv 2.4.10 中加载文件时出错

python - Project Euler 10 - 为什么第一个 python 代码比第二个运行得快得多?

python - 边际 Openoffice python

python - 如何根据图像中的蛇纹石对坐标进行排序?

c++ - 使用opencv减去图像

opencv - 相机校准

python - 导入 numpy : `pthread_creat error in blas_thread_init function` 时出现 OpenBLAS 错误

python - Pandas 每天的时间范围

python - 使用 findContour 和生成的轮廓近似线段以找到线交点

python - 使用 opencv 在另一个图像中查找相似图像