【目标检测】YOLOv5 5.0调用摄像头报错的处理

  • Post author:
  • Post category:其他

问题描述

调试好YOLOv5后想测试一下调用笔记本摄像头,网上的教程是通过修改detect.py文件来实现的。
在这里插入图片描述或者运行命令python detect.py --source 0
但是却报错了
在这里插入图片描述
in __init__ if 'youtube.com/' in url or 'youtu.be/' in url: # if source is YouTube video TypeError: argument of type 'int' is not iterable

解决方案

修改dataset.py文件
第一处:
在这里插入图片描述

# if 'youtube.com/' in url or 'youtu.be/' in url:  # if source is YouTube video
#     check_requirements(('pafy', 'youtube_dl'))
#     import pafy
#     url = pafy.new(url).getbest(preftype="mp4").url
# cap = cv2.VideoCapture(url)
cap = cv2.VideoCapture(0,cv2.CAP_DSHOW)

第二处:
在这里插入图片描述 # time.sleep(1 / self.fps) # wait time if(self.fps !=0):time.sleep(1 / self.fps) # wait time

修改成功后按上面的方法运行即可调用摄像头。

参考博客


版权声明:本文为AlwaysNoError原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。