[英]Error when running object detection model with webcam PyTorch
我正在尝试使用我的网络摄像头作为活体检测源来运行我的自定义模型,但是我收到了错误:
cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'imshow'
> Overload resolution failed:
> - imshow() missing required argument 'mat' (pos 2)
> - imshow() missing required argument 'mat' (pos 2)
> - imshow() missing required argument 'mat' (pos 2)
我的代码如下:
import torch
import cv2
# Model
model = torch.hub.load('ultralytics/yolov5', 'custom', 'best.pt')
# Image
vid = cv2.VideoCapture(0, cv2.CAP_DSHOW)
vid.open(0)
while (True):
# Capture the video frame
# by frame
ret, frame = vid.read()
# Display the resulting frame
results = model(frame)
results.render()
cv2.imshow(results)
# the 'q' button is set as the
# quitting button you may use any
# desired button of your choice
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# After the loop release the cap object
vid.release()
# Destroy all the windows
cv2.destroyAllWindows()
我在这里做错了什么? 我认为结果不是 cv2.imshow 想要的正确格式,但我不太清楚我需要做什么来纠正这个问题,谢谢!
cv2.imshow 需要一个窗口标题。 cv2.imshow("some window title", results)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.