import cv2
import numpy as np
cap=cv2.VideoCapture(0)
hsvVals=[0,0,63,179,160,255]
def threading(img):
hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
lower = np.array([hsvVals[0], hsvVals[1], hsvVals[2]])
upper = np.array([hsvVals[3], hsvVals[4], hsvVals[5]])
mask = cv2.inRange(hsv, lower, upper)
return mask
def getContours(imgThres, img):
contours,hieracrhy = cv2.findContours(imgThres, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)#外侧扫描,所有边界点
if len(contours) != 0:
biggest = max(contours, key=cv2.contourArea)
x, y, w, h = cv2.boundingRect(biggest)
cx = x + w // 2
cy = y + h // 2
cv2.drawContours(img, biggest, -1, (255, 0, 255), 7)
cv2.circle(img, (cx, cy), 10, (0, 255, 0), cv2.FILLED)
while True:
_,img=cap.read()
img=cv2.resize(img,(480,360))
#img=cv2.flip(img,0)
imgThres=threading(img)
getContours(imgThres,img)
cv2.imshow('Output',img)
cv2.imshow("Path", imgThres)
cv2.waitKey(1)
ValueError: too many values to unpack (expected 2)
请问有人知道这是什么情况吗?
消除报错,使程序运行下去