TypeError: stat: path should be string, bytes, os.PathLike or integer, not cv2.VideoCapture ,detect using neural network using mtcnn?

问题


i've tried to detect faces from my webcam , but it was only detect the first face which appeared in the first frame , then it will crush , i have used mtcnn to detection operation

import cv2  
i = 0
capture = cv2.VideoCapture(0)  
while(True):      
    ret, frame = capture.read()

    frames_tracked = []
    print('\rTracking frame: {}'.format(i + 1), end='')
    frame_pil = cv2.cvtColor(frame,cv2.COLOR_BGR2RGB)
    frame_pil = Image.fromarray(frame_pil)
    boxes,_ = mtcnn.detect(frame_pil)
    frame_draw = frame_pil.copy()
    draw = ImageDraw.Draw(frame_draw)     
    for box in boxes:
        draw.rectangle(box.tolist(), outline=(255, 0, 0), width=6)          

        frames_tracked.append(frame_draw.resize((640, 360), Image.BILINEAR))      
    d = display.display(frames_tracked[0], display_id=True)
    i = 1     
    try:        
        while True:
            d.update(frames_tracked[i % len(frames_tracked)]) 
            i += 1     
    except KeyboardInterrupt:
        pass

if cv2.waitKey('q') == 27:     
   break  

capture.release() 
cv2.destroyAllWindows()

while there is no face in the first frame it will crush , and rise the error

TypeError: 'NoneType' object is not iterable

i want to even there is no faces it will remain capturing and looking for faces . after detecting the first face in the first frame raised this error :

TypeError: stat: path should be string, bytes, os.PathLike or integer, not cv2.VideoCapture

http://dpaste.com/04WXP33

thanks for helping

来源:https://stackoverflow.com/questions/59955290/typeerror-stat-path-should-be-string-bytes-os-pathlike-or-integer-not-cv2-v


更多相关内容:请点击查看