Python/Contour OpenCV返回“要解包的值太多”

2024-05-20 12:28:53 发布

您现在位置:Python中文网/ 问答频道 /正文

我对本教程有一个问题:https://docs.opencv.org/3.0-beta/doc/py_tutorials/py_imgproc/py_contours/py_contour_features/py_contour_features.html 实际上,当我试图执行以下代码时,我遇到了这个错误:

import numpy as np
import cv2

img = cv2.imread("onepoint.png", 0)

canny_img = cv2.Canny(img,150,200)
ret,thresh = cv2.threshold(canny_img,127,255,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)

cnt = contours[0]
M = cv2.moments(cnt)
print M

错误如下:

^{pr2}$

我不明白为什么会发生这个错误。我知道cv2.findContours (thresh, 1, 2)返回给我3个“数组”,但是为什么呢?如果一个人在善意地向我解释我是一个接受者:(

我想把这个picture的词框起来。在

我对OpenCV完全陌生,我想你会理解的

提前感谢


Tags: pyhttpsimportdocsimg错误教程cv2