ValueError: not enough values
ValueError: not enough values
我尝试了 运行 下面的代码,但遇到了 ValueError。我的预期输出是代码将打开四个摄像头 windows,它们都是不同的。谁能帮帮我?
下面是我的代码。
import cv2
firstframe = None
video = cv2.VideoCapture(0)
while True:
check, frame = video.read()
status = 0
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21, 21), 0)
if firstframe is None:
firstframe = gray
continue
delta_frame = cv2.absdiff(firstframe,gray)
thresh_frame = cv2.threshold(delta_frame, 30, 255, cv2.THRESH_BINARY)[1]
thresh_frame = cv2.dilate(thresh_frame, None, iterations=2)
(_,cnts,_) = cv2.findContours(thresh_frame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for contour in cnts:
if cv2.contourArea(contour) < 10000:
continue
status = 1
(x, y, w, h) = cv2.boundingRect(contour)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3)
cv2.imshow("Gray Frame", gray)
cv2.imshow("Delta Frame", delta_frame)
cv2.imshow("Threshold Frame", thresh_frame)
cv2.imshow("Normal Frame", frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
print(status)
video.release()
cv2.destroyAllWindows
我得到的错误是这样的:
cnts = cv2.findContours(thresh_frame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)
cv2.findContours
returns 2 件事(而不是 3 件事)。这两个是 contours,hierarchy
.
从 (_,cnts,_) = cv2.findContours...
更改为 contours,hierarchy = cv2.findContours...
我尝试了 运行 下面的代码,但遇到了 ValueError。我的预期输出是代码将打开四个摄像头 windows,它们都是不同的。谁能帮帮我?
下面是我的代码。
import cv2
firstframe = None
video = cv2.VideoCapture(0)
while True:
check, frame = video.read()
status = 0
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
gray = cv2.GaussianBlur(gray, (21, 21), 0)
if firstframe is None:
firstframe = gray
continue
delta_frame = cv2.absdiff(firstframe,gray)
thresh_frame = cv2.threshold(delta_frame, 30, 255, cv2.THRESH_BINARY)[1]
thresh_frame = cv2.dilate(thresh_frame, None, iterations=2)
(_,cnts,_) = cv2.findContours(thresh_frame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for contour in cnts:
if cv2.contourArea(contour) < 10000:
continue
status = 1
(x, y, w, h) = cv2.boundingRect(contour)
cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 3)
cv2.imshow("Gray Frame", gray)
cv2.imshow("Delta Frame", delta_frame)
cv2.imshow("Threshold Frame", thresh_frame)
cv2.imshow("Normal Frame", frame)
key = cv2.waitKey(1)
if key == ord('q'):
break
print(status)
video.release()
cv2.destroyAllWindows
我得到的错误是这样的:
cnts = cv2.findContours(thresh_frame.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
ValueError: not enough values to unpack (expected 3, got 2)
cv2.findContours
returns 2 件事(而不是 3 件事)。这两个是 contours,hierarchy
.
从 (_,cnts,_) = cv2.findContours...
更改为 contours,hierarchy = cv2.findContours...