Home > Mobile >  cv2.VideoCapture(0) takes 20seconds
cv2.VideoCapture(0) takes 20seconds

Time:07-14

Is it normal that cv2.VideoCapture takes 20 seconds?

import numpy as np
import cv2 as cv

cap = cv.VideoCapture(0)   #takes long

if not cap.isOpened():
    print("Cannot open camera")
    exit()
while True:
    # Capture frame-by-frame
    ret, frame = cap.read()
    # if frame is read correctly ret is True
    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)
    cv.imshow('frame', gray)
    if cv.waitKey(1) == ord('q'):
        break
cap.release()
cv.destroyAllWindows()

video rendering is ok.

CodePudding user response:

Here is the trick

cap= cv2.VideoCapture(0, cv2.CAP_DSHOW)
  • Related