This is the code we developed in Video Lesson #6 showing how to launch a webcam quicker and with less delay in OpenCV running on windows. The video above explains the code step by step, but for your convenience, I include the code below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import cv2 print(cv2.__version__) width=1280 height=720 cam=cv2.VideoCapture(1,cv2.CAP_DSHOW) cam.set(cv2.CAP_PROP_FRAME_WIDTH, width) cam.set(cv2.CAP_PROP_FRAME_HEIGHT,height) cam.set(cv2.CAP_PROP_FPS, 30) cam.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc(*'MJPG')) while True: ignore, frame = cam.read() cv2.imshow('my WEBcam', frame) cv2.moveWindow('my WEBcam',0,0) if cv2.waitKey(1) & 0xff ==ord('q'): break cam.release() |