我通过打开cv2不断收到此错误以进行人脸检测

问题描述 投票:0回答:1
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'

我收到此错误。请提供错误和代码帮助。

python machine-learning face-detection cv2
1个回答
0
投票

用此更改cv2.threshold行retval, delta = cv2.threshold(diff,30,255,cv2.THRESH_BINARY)

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