1
votes

Videocapture demo

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()

The video capture demo ( opencv 3.2.0 ), on my Debian computer, does not work, and I do not understand how to fix it. I tried it on windows and it worked perfectly.

I tried both with VideoCapture (-1) VideoCapture (0) But it doesn't seem to work..

How can I fix it? thank you

OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 9748 Traceback (most recent call last): File "ok.py", line 11, in gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) cv2.error: /io/opencv/modules/imgproc/src/color.cpp:9748: error: (-215) scn == 3 || scn == 4 in function cvtColor

$ v4l2-ctl --list-devices 
UVC Camera (046d:0809)(usb-0000:00:14.0-3):     /dev/video1

USB2.0 HD UVC WebCam (usb-0000:00:14.0-5):  /dev/video0

i tried

ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 output.mkv  

and webcam works..

1
Try directly capturing using ffplay from the command line.Vorac
@Vorac webcam works, but with the opencv, example script, give me an erroruser2804916
What is the value of ret and frame after the cap.read() call?Hannes Ovrén
ret=False frame = Noneuser2804916
How did you install OpenCV? Using pip?Eliezer Bernart

1 Answers

0
votes

Why is it VideoCapture(1)? Do you have two cameras on your system?

You tested

ffmpeg -f v4l2 -framerate 25 -video_size 640x480 -i /dev/video0 output.mkv 

on /dev/video0 so it should be VideoCapture(0).