Ask Your Question
0

VIDEOIO ERROR: V4L: can't open camera by index 0

asked 2018-09-10 04:00:10 -0600

chtsngn gravatar image

Hello,

I'm triggering a Python file with PHP.

$return = shell_exec("/usr/bin/python3.6 create.py 2>&1")

Python File

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

Return this value

VIDEOIO ERROR: V4L: can't open camera by index 0

What is the problem?

edit retag flag offensive close merge delete

Comments

  • are you sure, it HAS a camera plugged in ?

  • try with -1 as index.

berak gravatar imageberak ( 2018-09-10 04:26:58 -0600 )edit

Type following command on terminal to check list of video devices connected to your system. ls ~/../../dev/video* If video0 is not present then replug your camera.

ak1 gravatar imageak1 ( 2018-09-10 05:12:21 -0600 )edit

@berak i tried this `cv2.VideoCapture(-1)

@ak1 file exists. Listed.

When you run the Python file, the camera turns on. However, it does't work when triggered by PHP.

chtsngn gravatar imagechtsngn ( 2018-09-10 06:38:51 -0600 )edit

oh, can it be that php does not have user rights to do that ?

berak gravatar imageberak ( 2018-09-10 06:51:08 -0600 )edit

It doesn't give anything like 'permission error'. When I changed the permissions I got 'permission error'. I don't think it's a permission error.

chtsngn gravatar imagechtsngn ( 2018-09-10 06:59:40 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2018-09-12 13:55:04 -0600

yo gravatar image

sudo modprobe bcm2835-v4l2

edit flag offensive delete link more

Comments

by using your tips, problems solved. thanks a lot !

cv_hk gravatar imagecv_hk ( 2019-01-04 01:56:06 -0600 )edit

This command works but i have use this cmd as many times as i use to run my script ??

vinayak tyagi gravatar imagevinayak tyagi ( 2019-04-18 10:26:49 -0600 )edit

The command "sudo modprobe bcm2835-v4l2" didn't work on my side.

I'm stuck for 3 days now with my Logitech USB Cam plugged to my rpi where I installed Opencv 4.0 following the great tutorial from Adrian Rosebrock (link) The "vs = VideoStream(src=0).start()" generate the error "(python: num_process): GStreamer-CRITICAL **: gst_element_get_state: assertion 'GST_IS_ELEMENT (element)' failed" and the process hang.

Then when I unplug the USB Cam, the process get out of hang state and return the following message:

VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV VIDEOIO ERROR: V4L: can't open camera by index 0 VIDIOC_REQBUFS: No such device

The same USB Cam works fine on my PC.

projectdrone2 gravatar imageprojectdrone2 ( 2019-05-02 15:52:17 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-09-10 04:00:10 -0600

Seen: 55,084 times

Last updated: Sep 10 '18