python - 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
谢谢你的帮助
解决方案
推荐阅读
- python - Django 检查服务器是否已经在运行
- java - 在 Java VS C# 中调用参数可以为空的方法
- python - 满足条件后如何停止python程序(在jupyter笔记本中)
- makefile - Variable expansion in target dependencies
- neo4j - Setting a property key for a node based on another node in a relationship
- haskell - 这种类型的孔怎么塞?
- elasticsearch - Kibana error on startup (incompatible nodes)
- javascript - 检查函数值而不是返回值时显示警告
- python - Importing modules that import other modules from other directories in Python 3.6
- reactjs - React 开发工具空白组件