gpt4 book ai didi

python - 我通过 open cv2 进行人脸检测时不断收到此错误

转载 作者:行者123 更新时间:2023-11-30 09:59:11 24 4
gpt4 key购买 nike

import cv2,time

first_frame=None

video = cv2.VideoCapture(0,cv2.CAP_DSHOW)

while True:

check,frame=video.read()
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
gray=cv2.GaussianBlur(gray,(21,21),0)
if first_frame is None:
first_frame=gray
continue
diff = cv2.absdiff(first_frame,gray)
delta=cv2.threshold(diff,30,255,cv2.THRESH_BINARY)
delta=cv2.dilate(delta,None,iterations=0)
_,cnt,_=cv2.findContours(delta,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
for contou in cnt:
if cv2.contourArea(contou)<1000:
continue
(x,y,w,h)=cv2.boundingRect(contou)
cv2.rectangle(frame,(x,y),(x+w,y+h),(0,255,0),3)

cv2.imshow('frame',frame)
cv2.imshow('gray',gray)
cv2.imshow('diffe',diff)
cv2.imshow('delta', delta)
key=cv2.waitKey(1)
if key==ord('q'):
break
video.release()

cv2.destroyAllWindows()
delta=cv2.dilate(delta,None,iterations=0) 
TypeError: Expected Ptr<cv::UMat> for argument '%s'

我收到此错误。请帮忙解决错误和代码。

最佳答案

用这个改变 cv2.threshold 行
retval, delta = cv2.threshold(diff,30,255,cv2.THRESH_BINARY)

检查this link有关 cv2.threshold 函数及其返回值的说明

关于python - 我通过 open cv2 进行人脸检测时不断收到此错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59723313/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com