Ask Your Question
0

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

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

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 -0500 )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 -0500 )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 -0500 )edit

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

berak gravatar imageberak ( 2018-09-10 06:51:08 -0500 )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 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

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

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 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

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

Seen: 4,227 times

Last updated: Sep 10 '18