[英]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.