“在Python opencv2中解压缩的值太多(预期2)”>

问题描述 投票:-1回答:1

我在收到错误消息时遇到问题

成功,img = cv2.imread('stop.jpg',0)ValueError:太多值无法解包(预期2)

我正在使用以下脚本:

def getContours(img, imgContour):
contours, hierarchy = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)[-2:]

for cnt in contours:
    area = cv2.contourArea(cnt)
    if area > 1000:
        cv2.drawContours(imgContour, contours, -1, (255, 0, 255), 7)
        peri = cv2.arcLength(cnt, True)
        approx = cv2.approxPolyDP(cnt, 0.02 * peri, True)
        # print(len(approx))
        x, y, w, h = cv2.boundingRect(approx)
        cv2.rectangle(imgContour, (x, y), (x + w, y + h), (0, 255, 0), 5)

        cv2.putText(imgContour, "Point: " + str(len(approx)), (x + w + 20, y + 20), cv2.FONT_HERSHEY_COMPLEX, .7,
                    (0, 255, 0), 2)
        cv2.putText(imgContour, "Area: " + str(int(area)), (x + w + 20, y + 45), cv2.FONT_HERSHEY_COMPLEX, 0.7,
                    (0, 255, 0), 2)


success, img = cv2.imread('stop.jpg', 0)
imgContour = img.copy()

imgBlur = cv2.GaussianBlur(img, (7, 7), 1)
imgGray = cv2.cvtColor(imgBlur, cv2.COLOR_BGR2GRAY)

threshold1 = cv2.getTrackbarPos("Threshold1", "Parameter")
threshold2 = cv2.getTrackbarPos("Threshold2", "Parameter")
imgCanny = cv2.Canny(imgGray, threshold1, threshold2)
kernel = np.ones((5, 5))
imgDil = cv2.dilate(imgCanny, kernel, iterations=1)

getContours(imgDil, imgContour)

我该如何解决?

我遇到一个错误消息成功的问题,img = cv2.imread('stop.jpg',0)ValueError:太多的值无法解包(预期2)我正在使用以下脚本:def .. 。

python opencv opencv-contour
1个回答
0
投票

[imread仅返回一件事,因此将行更改为

© www.soinside.com 2019 - 2024. All rights reserved.