首页 > 解决方案 > TypeError: stat: path 应该是字符串、字节、os.PathLike 或整数,而不是 cv2.VideoCapture ,使用 mtcnn 使用神经网络检测?

问题描述

我试图从我的网络摄像头中检测人脸,但它只检测到出现在第一帧中的第一张人脸,然后它会崩溃,我已经使用 mtcnn 进行检测操作

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()

当第一帧没有人脸时,它会挤压,并增加错误。

TypeError:“NoneType”对象不可迭代

我想即使没有面孔,它也会继续捕捉和寻找面孔。在第一帧中检测到第一张脸后引发了这个错误:

TypeError: stat: path 应该是字符串、字节、os.PathLike 或整数,而不是 cv2.VideoCapture

http://dpaste.com/04WXP33

谢谢你的帮助

标签: pythonpytorchface-detectionface-recognition

解决方案


推荐阅读