Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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): # Capture frame-by-frame ret, frame = cap.read() # Our operations on the frame come here gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

# Display the resulting frame
cv2.imshow('frame',gray)
if cv2.waitKey(1) & 0xFF == ord('q'):
    break

When everything done, release the capture

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 readsmp4 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.

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 Python3 with opencv4 OpenCV4 on windows 7.

import numpy as np np

import cv2

cap = cv2.VideoCapture(0)

while(True): # Capture frame-by-frame =cv2.VideoCapture(0)

while(True):

ret, frame = cap.read() # Our operations on the frame come here cap.read()

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

# Display the resulting frame
cv2.imshow('frame',gray)

cv2.imshow('frame',gray)

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

When everything done, release the capture

cap.release() 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 OpenCV properly or not, I used a code that readsmp4 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.

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

np import cv2 cap =cv2.VideoCapture(0)

import cv2

while(True):

cap =cv2.VideoCapture(0)

while(True):

ret, frame = cap.read()

cap.read()

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

cv2.COLOR_BGR2GRAY) cv2.imshow('frame',gray)

cv2.imshow('frame',gray)

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

break

break cap.release()

cap.release()

cv2.destroyAllWindows()

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 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 command.. cap = cv2.VideoCapture('video1.mp4'). 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.