Capture Video from Camera using cv2.VideoCapture(0) not working

asked 2020-07-24 04:52:28 -0500

akjampot gravatar image

updated 2020-08-05 22:53:20 -0500

supra56 gravatar image


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) 


ret, frame =

gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)


if cv2.waitKey(1) & 0xFF == ord('q'): 




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.

edit retag flag offensive close merge delete


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.

mvuori gravatar imagemvuori ( 2020-08-06 00:43:21 -0500 )edit