I am trying to use the opencv library in Java to take pictures using the webcam (Logitech C270). In my code, I have the following:
VideoCap(){
cap = new VideoCapture(0);
cap.open(0);
}
Which is the function that creates the new video capture device. Running the program gives the following error:
[ WARN:0@0.198] global cap_v4l.cpp:003 open VIDEOIO(V4L2:/dev/video0): can't open camera by index
[Error:0@0.201] global obsensor_uvc_stream_channel.cpp:156 getStreamChannelGroup Camera index out of range
I have tried placing various values inside the VideoCapture constructor (-1, 0, , 1) all of them give the same error. I have confirmed that Opencv compiled with V4L2.
Running v4l2-ctl --list-devices confirms that the webcam is detected, and I also ran cheese and was able to get video input
Following this suggestion I ran this command: sudo chmod 777 /dev/video0, which did not solve the problem.
I also tried this suggestion which also did not affect the issue