Yolov5 customize webcam
Posted: Wed Jun 08, 2022 12:10 am
Code: Select all
diff --git a/utils/dataloaders.py b/utils/dataloaders.py
index 23ee2d5..5d140ee 100755
--- a/utils/dataloaders.py
+++ b/utils/dataloaders.py
@@ -321,7 +321,12 @@ class LoadStreams:
import pafy
s = pafy.new(s).getbest(preftype="mp4").url # YouTube URL
s = eval(s) if s.isnumeric() else s # i.e. s = '0' local webcam
- cap = cv2.VideoCapture(s)
+ cap = cv2.VideoCapture(s, cv2.CAP_V4L2)
+ cap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))
+ cap.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
+ cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)
+ cap.set(cv2.CAP_PROP_FPS, 60)
+
assert cap.isOpened(), f'{st}Failed to open {s}'
w = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
h = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))