Capture Video from Camera using cv2.VideoCapture(0) not working
Hi,
I am trying to execute the following code regarding video capture from webcam on my laptop. I am using Python3 with OpenCV4 on windows 7.
import numpy as np
import cv2
cap =cv2.VideoCapture(0)
while(True):
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
While executing the code the camera opens but the camera display windows shows a still blurred multiple gray image instead of the live video. I am using IDLE python IDE for execution of the code. It says some VideoCodec_RGB24
error. For crosscheck whether I have installed the python and OpenCV properly or not, I used a code that reads mp4 file using the command..
cap = cv2.VideoCapture('video1.mp4')
.
The program is able to read from the mp4 file and it displays the videos too. Please advise to fix the problem.
First two advices are about asking help: 1) If "it says some VideoCodec_RGB24 error", report what the error exactly is, in full, and other possible outout. 2) Descripe your camera model and how it is attached. Also, report your exact OpenCV version, as there may be differences in behaviour, compatibity and problems.