Closed isemaj closed 5 years ago
Try to set environment variables OPENCV_LOG_LEVEL=DEBUG
and OPENCV_VIDEOIO_DEBUG=1
Your environment is mixing key packages from conda-forge and defaults. Also, it’s unclear to me if a camera input should work inside of Juptyerlab.
First try to create a fresh env with only conda-forge packages, then try your code with only python in a shell rather than through jupyterlab.
i can't really open my video camera either (ran things from the bare python console)
this points to some hints, maybe https://stackoverflow.com/questions/29249611/videocapture-does-not-work-in-anaconda
Maybe we should rebuild 3.4 with qt 5.9 in this case.
If it works in OpenCV 3.4, then this PR should help you out in a few hours https://github.com/conda-forge/opencv-feedstock/pull/157
>>> cap = cv.VideoCapture(0)
[ INFO:0] VIDEOIO: Enabled backends(4, sorted by priority): FFMPEG(1000); GSTREAMER(990); CV_IMAGES(980); CV_MJPEG(970)
[ WARN:0] VIDEOIO(GSTREAMER): trying capture cameraNum=0 ...
[ INFO:0] VideoIO pluigin (GSTREAMER): glob is 'libopencv_videoio_gstreamer*.so', 1 location(s)
[ INFO:0] - /opt/conda/lib/python3.7/site-packages/../..: 0
[ INFO:0] Found 0 plugin(s) for GSTREAMER
[ WARN:0] VIDEOIO(GSTREAMER): backend is not available (plugin is missing, or can't be loaded due dependencies or it is not compatible)
As I can see from recipe OpenCV is built without V4L and GStreamer support (WITH_V4L
and WITH_GSTREAMER
) which usually open camera. FFMpeg backend does not support camera.
It is possible to create videoio plugins for FFmpeg and GStreamer on Linux since OpenCV 4.1, you need to add option -DVIDEOIO_PLUGIN_LIST=ffmpeg,gstreamer
and make sure GStreamer and FFmpeg are found by cmake. With the described method these dependency become optional.
I think we can do -DVIDEOIO_PLUGIN_LIST=ffmpeg
relatively easily. let me try to compile locally first.
tried to compile it with all your flags locally, didn't seem to have an effect. I might try again tomorrow.
It is working now what I did is to install opencv-python
via pip
. I know that is not a reliable solution but enough for a simple task. But I will try all your suggestions.
Not sure if it is just my computer, but even with gstreamer
$ python
Python 3.7.1 | packaged by conda-forge | (default, Feb 18 2019, 01:42:00)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
>>> cap = cv.VideoCapture(0)
[ INFO:0] VIDEOIO: Enabled backends(4, sorted by priority): FFMPEG(1000); GSTREAMER(990); CV_IMAGES(980); CV_MJPEG(970)
[ WARN:0] VIDEOIO(GSTREAMER): trying capture cameraNum=0 ...
[ INFO:0] VideoIO pluigin (GSTREAMER): glob is 'libopencv_videoio_gstreamer*.so', 1 location(s)
[ INFO:0] - /home/mark2/miniconda3/envs/opencv/lib/python3.7/site-packages/../..: 1
[ INFO:0] Found 1 plugin(s) for GSTREAMER
[ INFO:0] load /home/mark2/miniconda3/envs/opencv/lib/python3.7/site-packages/../../libopencv_videoio_gstreamer.so => OK
[ INFO:0] Video I/O: loaded plugin 'GStreamer OpenCV Video I/O plugin'
[ WARN:0] VIDEOIO(GSTREAMER): can't create capture
>>> cap = cv.VideoCapture()
>>> cap.isOpened()
False
>>> cap.open(0)
[ WARN:0] VIDEOIO(GSTREAMER): trying capture cameraNum=0 ...
[ WARN:0] VIDEOIO(GSTREAMER): can't create capture
False
>>> cap.open(1)
[ WARN:0] VIDEOIO(GSTREAMER): trying capture cameraNum=1 ...
[ WARN:0] VIDEOIO(GSTREAMER): can't create capture
False
>>>
Maybe @sdvillal can chime in. It seems you fixed this issue in the past?
pip seems to use V4L2 on my system
$ python
Python 3.7.3 | packaged by conda-forge | (default, Mar 27 2019, 23:01:00)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2 as cv
>>> cap = cv.VideoCapture(0)
[ INFO:0] VIDEOIO: Enabled backends(5, sorted by priority): FFMPEG(1000); GSTREAMER(990); V4L2(980); CV_IMAGES(970); CV_MJPEG(960)
[ WARN:0] VIDEOIO(GSTREAMER): trying capture cameraNum=0 ...
[ INFO:0] VideoIO pluigin (GSTREAMER): glob is 'libopencv_videoio_gstreamer*.so', 1 location(s)
[ INFO:0] - /home/mark2/miniconda3/envs/opencv/lib/python3.7/site-packages/cv2: 0
[ INFO:0] Found 0 plugin(s) for GSTREAMER
[ WARN:0] VIDEOIO(GSTREAMER): backend is not available (plugin is missing, or can't be loaded due dependencies or it is not compatible)
[ WARN:0] VIDEOIO(V4L2): trying capture cameraNum=0 ...
[ WARN:0] VIDEOIO(V4L2): created, isOpened=1
>>> cap.read()
@hmaarrfk , as I can see gst_plugins_base does not contain v4l2src plugin (https://github.com/conda-forge/gstreamer-feedstock/blob/master/recipe/meta.yaml). I don't know if there is a Conda package with this plugin available, but in Ubuntu it is located in the "good" plugins package. There is a chance that GStreamer from conda-forge package can load plugins from the system or other location (GST_PLUGIN_PATH environment variable) and then camera will work. Or maybe it is possible to add "good" plugins to the the conda-forge package (https://gstreamer.freedesktop.org/src/gst-plugins-good/).
On my system it is possible to open the camera with system GStreamer, so I believe the problem is in missing plugin:
Python 3.6.7 (default, Oct 22 2018, 11:32:17)
[GCC 8.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cap = cv2.VideoCapture(0)
[ INFO:0] global ../opencv/modules/videoio/src/videoio_registry.cpp (185) VideoBackendRegistry VIDEOIO: Enabled backends(6, sorted by priority): FFMPEG(1000); GSTREAMER(990); V4L2(980); CV_IMAGES(970); CV_MJPEG(960); FIREWIRE(950)
[ WARN:0] global ../opencv/modules/videoio/src/cap.cpp (163) open VIDEOIO(GSTREAMER): trying capture cameraNum=0 ...
[ WARN:0] global ../opencv/modules/videoio/src/cap.cpp (175) open VIDEOIO(GSTREAMER): created, isOpened=1
>>>
Is it possible to build OpenCV with V4L support on Linux in conda-forge environment? This backend does not have external dependencies because it uses system calls to work with camera. The only build-time dependency is linux header: linux/videodev2.h
.
what would happen if a user didnt have v4l2 installed?
would they be able to use conda-forge opencv?
V4L2 interface is part of Linux kernel. There are two mutually exclusive backends:
WITH_V4L
<linux/videodev2.h>
for buildWITH_LIBV4L
So I suggest to enable WITH_V4L
option to use first backend on Linux for 3.4.x and 4.x. Only concern is Linux kernel headers availability in conda build environment.
Builing with V4L sounds reasonable. I think this is why we use such old Centos 6 to ensure broad compatibility when linking with linux headers. Somebody should probably test it locally before making the PR.
Start docker, build some package, get it out of docker, test it on something like Ubuntu 19.04????
Than you @mshabunin I can confirm this works with a webcam on ubuntu 18.04
Issue:
Cannot open camera using the
cv.VideoCapture(0)
.I'm trying to run this code on jupyter lab
Then the output is
Environment (
conda list
):Details about
conda
and system (conda info
):