conda-forge / opencv-feedstock

A conda-smithy repository for opencv.
BSD 3-Clause "New" or "Revised" License
63 stars 59 forks source link

Cannot open camera on OpenCV 4.1.0 on linux #155

Closed isemaj closed 5 years ago

isemaj commented 5 years ago

Issue:

Cannot open camera using the cv.VideoCapture(0).

I'm trying to run this code on jupyter lab

import numpy as np
import cv2 as cv

cap = cv.VideoCapture(0)

if not cap.isOpened():
    print("Cannot open camera")
    exit()

while True:
    # Capture frame-by-frame
    ret, frame = cap.read()

    # if frame is read correctly ret is True
    if not ret:
        print("Can't receive frame (stream end?). Exiting...")
        break

    # Our operations on the frame come here
    gray = cv.cvtColor(frame, cv.COLOR_BGR2GRAY)

    # Display the resulting frame
    cv.imshow('frame', gray)
    if cv.waitKey(1) & 0xFF == ord('q'):
        break

# When everything is done, release the capture
cap.release()
cv.destroyAllWindows()

Then the output is

Cannot open camera
Can't receive frame (stream end?). Exiting...


Environment (conda list):

``` $ conda list # packages in environment at /home/me/anaconda3/envs/myenv: # # Name Version Build Channel _ipyw_jlab_nb_ext_conf 0.1.0 py36he11e457_0 _py-xgboost-mutex 2.0 cpu_0 conda-forge absl-py 0.7.1 py36_0 conda-forge alabaster 0.7.12 py36_0 anaconda-client 1.7.2 py36_0 anaconda-navigator 1.6.9 py36h11ddaaa_0 anaconda-project 0.8.2 py36_0 asn1crypto 0.24.0 py36_0 astor 0.7.1 py_0 conda-forge astroid 2.2.5 py36_0 astropy 3.1.2 py36h7b6447c_0 atk 2.25.90 hb9dd440_1002 conda-forge atomicwrites 1.3.0 py36_1 attrs 19.1.0 py36_1 babel 2.6.0 py36_0 backcall 0.1.0 py36_0 backports 1.0 py36_1 backports.os 0.1.1 py36_0 backports.shutil_get_terminal_size 1.0.0 py36_2 beautifulsoup4 4.7.1 py36_1 bitarray 0.8.3 py36h14c3975_0 blas 1.0 mkl blaze 0.11.3 py36h4e06776_0 bleach 3.1.0 py36_0 blosc 1.15.0 hd408876_0 bokeh 1.0.4 py36_0 boto 2.49.0 py36_0 bottleneck 1.2.1 py36h035aef0_1 bzip2 1.0.6 h14c3975_5 c-ares 1.15.0 h14c3975_1001 conda-forge ca-certificates 2019.3.9 hecc5488_0 conda-forge cairo 1.16.0 ha4e643d_1000 conda-forge certifi 2019.3.9 py36_0 conda-forge cffi 1.12.2 py36h2e261b9_1 chardet 3.0.4 py36_1 click 7.0 py36_0 cloudpickle 0.8.0 py36_0 clyent 1.2.2 py36_1 colorama 0.4.1 py36_0 conda-verify 2.0.0 py36h98955d8_0 contextlib2 0.5.5 py36h6c84a62_0 cryptography 2.5 py36hb7f436b_1 conda-forge cycler 0.10.0 py36h93f1223_0 cython 0.29.6 py36he6710b0_0 cytoolz 0.9.0.1 py36h14c3975_1 dask 1.1.4 py36_1 dask-core 1.1.4 py36_1 datashape 0.5.4 py36h3ad6b5c_0 dbus 1.13.6 he372182_0 conda-forge decorator 4.4.0 py36_1 defusedxml 0.5.0 py36_1 distributed 1.26.0 py36_1 docutils 0.14 py36hb0f60f5_0 entrypoints 0.3 py36_0 et_xmlfile 1.0.1 py36hd6bccc3_0 expat 2.2.6 he6710b0_0 fastcache 1.0.2 py36h14c3975_2 ffmpeg 4.1.1 h167e202_0 conda-forge filelock 2.0.12 py36hacfa1f5_0 flask 1.0.2 py36_1 flask-cors 3.0.3 py36h2d857d3_0 fontconfig 2.13.1 he4413a7_1000 conda-forge freeglut 3.0.0 hf484d3e_1005 conda-forge freetype 2.9.1 h8a8886c_1 fribidi 1.0.5 h7b6447c_0 gast 0.2.2 py_0 conda-forge gdk-pixbuf 2.36.12 h49783d7_1002 conda-forge get_terminal_size 1.0.0 haa9412d_0 gettext 0.19.8.1 hc5be6a0_1002 conda-forge gevent 1.4.0 py36h7b6447c_0 giflib 5.1.9 h516909a_0 conda-forge glib 2.58.3 hf63aee3_1001 conda-forge glob2 0.5 py36h2c1b292_1 gmp 6.1.2 h6c8ec71_1 gmpy2 2.0.8 py36h10f8cd9_2 gnutls 3.6.5 hd3a4fd2_1002 conda-forge gobject-introspection 1.58.2 py36h2da5eee_1000 conda-forge graphite2 1.3.13 h23475e2_0 greenlet 0.4.15 py36h7b6447c_0 grpcio 1.16.0 py36h4f00d22_1000 conda-forge gstreamer 1.14.4 h66beb1c_1001 conda-forge gtk2 2.24.31 hb68c50a_1001 conda-forge h5py 2.9.0 nompi_py36hf008753_1102 conda-forge harfbuzz 2.4.0 h37c48d4_0 conda-forge hdf5 1.10.4 nompi_h3c11f04_1106 conda-forge heapdict 1.0.0 py36_2 html5lib 1.0.1 py36_0 icu 58.2 h9c2bf20_1 idna 2.8 py36_0 imageio 2.5.0 py36_0 imagesize 1.1.0 py36_0 importlib_metadata 0.8 py36_0 intel-openmp 2019.3 199 ipykernel 5.1.0 py36h39e3cac_0 ipython 7.4.0 py36h39e3cac_0 ipython_genutils 0.2.0 py36hb52b0d5_0 ipywidgets 7.4.2 py36_0 isort 4.3.16 py36_0 itsdangerous 1.1.0 py36_0 jasper 1.900.1 h07fcdf6_1006 conda-forge jbig 2.1 hdba287a_0 jdcal 1.4 py36_0 jedi 0.13.3 py36_0 jeepney 0.4 py36_0 jinja2 2.10 py36_0 jpeg 9c h14c3975_1001 conda-forge jsonschema 3.0.1 py36_0 jupyter 1.0.0 py36_7 jupyter_client 5.2.4 py36_0 jupyter_console 6.0.0 py36_0 jupyter_core 4.4.0 py36_0 jupyterlab 0.35.4 py36hf63ae98_0 jupyterlab_launcher 0.4.0 py36h4d8058d_0 jupyterlab_server 0.2.0 py36_0 jupytext 1.1.1 0 conda-forge keras 2.2.4 py36_0 conda-forge keras-applications 1.0.4 py_1 conda-forge keras-preprocessing 1.0.2 py_1 conda-forge keyring 18.0.0 py36_0 kiwisolver 1.0.1 py36hf484d3e_0 lame 3.100 h14c3975_1001 conda-forge lazy-object-proxy 1.3.1 py36h14c3975_2 libblas 3.8.0 5_mkl conda-forge libcblas 3.8.0 5_mkl conda-forge libedit 3.1.20181209 hc058e9b_0 libffi 3.2.1 hd88cf55_4 libgcc 7.2.0 h69d50b8_2 conda-forge libgcc-ng 8.2.0 hdf63c60_1 libgfortran 3.0.0 1 conda-forge libgfortran-ng 7.3.0 hdf63c60_0 libglu 9.0.0 hf484d3e_1000 conda-forge libgpuarray 0.7.6 h14c3975_1003 conda-forge libiconv 1.15 h516909a_1005 conda-forge liblapack 3.8.0 5_mkl conda-forge liblapacke 3.8.0 5_mkl conda-forge libpng 1.6.36 hbc83047_0 libprotobuf 3.7.1 h8b12597_0 conda-forge libsodium 1.0.16 h1bed415_0 libstdcxx-ng 8.2.0 hdf63c60_1 libtiff 4.0.10 h2733197_2 libtool 2.4.6 h7b6447c_5 libuuid 2.32.1 h14c3975_1000 conda-forge libwebp 1.0.2 h576950b_1 conda-forge libxcb 1.13 h1bed415_1 libxgboost 0.82 he1b5a44_0 conda-forge libxml2 2.9.9 he19cac6_0 libxslt 1.1.33 h7d1a2b0_0 llvmlite 0.28.0 py36hd408876_0 locket 0.2.0 py36h787c0ad_1 lxml 4.3.2 py36hefd8a0e_0 lzo 2.10 h49e0be7_2 mako 1.0.7 py_1 conda-forge markdown 2.6.11 py_0 conda-forge markupsafe 1.1.1 py36h7b6447c_0 matplotlib 2.2.2 py36hb69df0a_2 mccabe 0.6.1 py36_1 mistune 0.8.4 py36h7b6447c_0 mkl 2019.3 199 mkl-service 1.1.2 py36he904b0f_5 mkl_fft 1.0.10 py36ha843d7b_0 mkl_random 1.0.2 py36hd81dba3_0 mock 2.0.0 py36_1001 conda-forge more-itertools 6.0.0 py36_0 mpc 1.1.0 h10f8cd9_1 mpfr 4.0.1 hdf1c602_3 mpmath 1.1.0 py36_0 msgpack-python 0.6.1 py36hfd86e86_1 multipledispatch 0.6.0 py36_0 navigator-updater 0.1.0 py36h14770f7_0 nbconvert 5.4.1 py36_3 nbformat 4.4.0 py36h31c9010_0 ncurses 6.1 he6710b0_1 nettle 3.4.1 h1bed415_1002 conda-forge networkx 2.2 py36_1 nltk 3.4 py36_1 nose 1.3.7 py36_2 notebook 5.7.8 py36_0 numba 0.43.1 py36h962f231_0 numexpr 2.6.9 py36h9e4a6bb_0 numpy 1.16.2 py36h7e9f1db_0 numpy-base 1.16.2 py36hde5b4d6_0 numpydoc 0.8.0 py36_0 odo 0.5.1 py36h90ed295_0 olefile 0.46 py36_0 opencv 4.1.0 py36h79d2e43_0 conda-forge openh264 1.8.0 hdbcaa40_1000 conda-forge openpyxl 2.6.1 py36_1 openssl 1.0.2r h14c3975_0 conda-forge packaging 19.0 py36_0 pandas 0.24.2 py36he6710b0_0 pandoc 2.2.3.2 0 pandocfilters 1.4.2 py36_1 pango 1.40.14 h4ea9474_1004 conda-forge parso 0.3.4 py36_0 partd 0.3.10 py36_1 patchelf 0.9 hf79760b_2 path.py 11.5.0 py36_0 pathlib2 2.3.3 py36_0 patsy 0.5.1 py36_0 pbr 5.1.3 py_0 conda-forge pcre 8.43 he6710b0_0 pep8 1.7.1 py36_0 pexpect 4.6.0 py36_0 pickleshare 0.7.5 py36_0 pillow 5.4.1 py36h34e0f95_0 pip 19.0.3 py36_0 pixman 0.34.0 h14c3975_1003 conda-forge pkginfo 1.4.1 py36h215d178_1 pluggy 0.9.0 py36_0 ply 3.11 py36_0 prometheus_client 0.6.0 py36_0 prompt_toolkit 2.0.9 py36_0 protobuf 3.7.1 py36he1b5a44_0 conda-forge psutil 5.6.1 py36h7b6447c_0 ptyprocess 0.6.0 py36_0 py 1.8.0 py36_0 py-xgboost 0.82 py36he1b5a44_0 conda-forge pycodestyle 2.5.0 py36_0 pycosat 0.6.3 py36h14c3975_0 pycparser 2.19 py36_0 pycrypto 2.6.1 py36h14c3975_9 pyflakes 2.1.1 py36_0 pygments 2.3.1 py36_0 pygpu 0.7.6 py36h3010b51_1000 conda-forge pylint 2.3.1 py36_0 pyodbc 4.0.26 py36he6710b0_0 pyopenssl 19.0.0 py36_0 pyparsing 2.3.1 py36_0 pyqt 5.6.0 py36_2 pyrsistent 0.14.11 py36h7b6447c_0 pysocks 1.6.8 py36_0 pytables 3.4.4 py36h5d69a80_1004 conda-forge pytest 4.3.1 py36_0 pytest-arraydiff 0.3 py36h39e3cac_0 pytest-astropy 0.5.0 py36_0 pytest-doctestplus 0.3.0 py36_0 pytest-openfiles 0.3.2 py36_0 pytest-remotedata 0.3.1 py36_0 python 3.6.6 hd21baee_1003 conda-forge python-dateutil 2.8.0 py36_0 pytz 2018.9 py36_0 pywavelets 1.0.2 py36hdd07704_0 pyyaml 5.1 py36h7b6447c_0 pyzmq 18.0.0 py36he6710b0_0 qt 5.6.2 hce4f676_1013 conda-forge qtawesome 0.5.7 py36_1 qtconsole 4.4.3 py36_0 qtpy 1.7.0 py36_1 readline 7.0 h7b6447c_5 requests 2.21.0 py36_0 rope 0.12.0 py36_0 ruamel_yaml 0.15.46 py36h14c3975_0 scikit-image 0.14.2 py36he6710b0_0 scikit-learn 0.20.3 py36hd81dba3_0 scipy 1.2.1 py36h7c811a0_0 seaborn 0.9.0 py36_0 secretstorage 3.1.1 py36_0 send2trash 1.5.0 py36_0 setuptools 40.8.0 py36_0 simplegeneric 0.8.1 py36_2 singledispatch 3.4.0.3 py36h7a266c3_0 sip 4.19.8 py36hf484d3e_0 six 1.12.0 py36_0 snappy 1.1.7 hbae5bb6_3 snowballstemmer 1.2.1 py36h6febd40_0 sortedcollections 1.1.2 py36_0 sortedcontainers 2.1.0 py36_0 soupsieve 1.8 py36_0 sphinx 1.8.5 py36_0 sphinxcontrib 1.0 py36_1 sphinxcontrib-websupport 1.1.0 py36_1 spyder 3.3.3 py36_0 spyder-kernels 0.4.2 py36_0 sqlalchemy 1.3.1 py36h7b6447c_0 sqlite 3.27.2 h7b6447c_0 statsmodels 0.9.0 py36h035aef0_0 sympy 1.3 py36_0 tblib 1.3.2 py36h34cf8b6_0 tensorboard 1.10.0 py36_0 conda-forge tensorflow 1.10.0 py36_0 conda-forge termcolor 1.1.0 py_2 conda-forge terminado 0.8.1 py36_1 testfixtures 6.7.0 py_0 conda-forge testpath 0.4.2 py36_0 theano 1.0.3 py36_0 conda-forge tk 8.6.8 hbc83047_0 toolz 0.9.0 py36_0 tornado 6.0.2 py36h7b6447c_0 traitlets 4.3.2 py36h674d592_0 typed-ast 1.3.1 py36h7b6447c_0 typing 3.6.2 py36h7da032a_0 unicodecsv 0.14.1 py36ha668878_0 unixodbc 2.3.7 h14c3975_0 urllib3 1.24.1 py36_0 wcwidth 0.1.7 py36hdf4376a_0 webencodings 0.5.1 py36_1 werkzeug 0.14.1 py36_0 wheel 0.33.1 py36_0 widgetsnbextension 3.4.2 py36_0 wrapt 1.11.1 py36h7b6447c_0 wurlitzer 1.0.2 py36_0 x264 1!152.20180806 h14c3975_0 conda-forge xgboost 0.82 py36he1b5a44_0 conda-forge xlrd 1.2.0 py36_0 xlsxwriter 1.1.5 py36_0 xlwt 1.3.0 py36h7b00a1f_0 xorg-fixesproto 5.0 h14c3975_1002 conda-forge xorg-inputproto 2.3.2 h14c3975_1002 conda-forge xorg-kbproto 1.0.7 h14c3975_1002 conda-forge xorg-libice 1.0.9 h516909a_1004 conda-forge xorg-libsm 1.2.3 h84519dc_1000 conda-forge xorg-libx11 1.6.7 h14c3975_1000 conda-forge xorg-libxau 1.0.9 h14c3975_0 conda-forge xorg-libxext 1.3.4 h516909a_0 conda-forge xorg-libxfixes 5.0.3 h516909a_1004 conda-forge xorg-libxi 1.7.9 h516909a_1002 conda-forge xorg-libxrender 0.9.10 h516909a_1002 conda-forge xorg-libxt 1.1.5 h14c3975_1002 conda-forge xorg-renderproto 0.11.1 h14c3975_1002 conda-forge xorg-xextproto 7.3.0 h14c3975_1002 conda-forge xorg-xproto 7.0.31 h14c3975_1007 conda-forge xz 5.2.4 h14c3975_4 yaml 0.1.7 had09818_2 zeromq 4.3.1 he6710b0_3 zict 0.1.4 py36_0 zipp 0.3.3 py36_1 zlib 1.2.11 h7b6447c_3 zstd 1.3.7 h0b5b093_0 ```


Details about conda and system ( conda info ):

``` $ conda info active environment : myenv active env location : /home/me/anaconda3/envs/myenv shell level : 1 user config file : /home/me/.condarc populated config files : /home/me/.condarc conda version : 4.6.14 conda-build version : 3.0.27 python version : 3.6.8.final.0 base environment : /home/me/anaconda3 (writable) channel URLs : https://conda.anaconda.org/conda-forge/linux-64 https://conda.anaconda.org/conda-forge/noarch https://repo.anaconda.com/pkgs/main/linux-64 https://repo.anaconda.com/pkgs/main/noarch https://repo.anaconda.com/pkgs/free/linux-64 https://repo.anaconda.com/pkgs/free/noarch https://repo.anaconda.com/pkgs/r/linux-64 https://repo.anaconda.com/pkgs/r/noarch package cache : /home/me/anaconda3/pkgs /home/me/.conda/pkgs envs directories : /home/me/anaconda3/envs /home/me/.conda/envs platform : linux-64 user-agent : conda/4.6.14 requests/2.19.1 CPython/3.6.8 Linux/4.15.0-47-generic ubuntu/18.04.2 glibc/2.27 UID:GID : 1000:1000 netrc file : /home/me/.netrc offline mode : False ```
mshabunin commented 5 years ago

Try to set environment variables OPENCV_LOG_LEVEL=DEBUG and OPENCV_VIDEOIO_DEBUG=1

hajapy commented 5 years ago

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.

hmaarrfk commented 5 years ago

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.

hmaarrfk commented 5 years ago

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

mshabunin commented 5 years ago
>>> 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.

hmaarrfk commented 5 years ago

I think we can do -DVIDEOIO_PLUGIN_LIST=ffmpeg relatively easily. let me try to compile locally first.

hmaarrfk commented 5 years ago

tried to compile it with all your flags locally, didn't seem to have an effect. I might try again tomorrow.

isemaj commented 5 years ago

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.

hmaarrfk commented 5 years ago

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
>>> 
hmaarrfk commented 5 years ago

Maybe @sdvillal can chime in. It seems you fixed this issue in the past?

hmaarrfk commented 5 years ago

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()
mshabunin commented 5 years ago

@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.

hmaarrfk commented 5 years ago

what would happen if a user didnt have v4l2 installed?

would they be able to use conda-forge opencv?

mshabunin commented 5 years ago

V4L2 interface is part of Linux kernel. There are two mutually exclusive backends:

V4L
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.

hmaarrfk commented 5 years ago

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????

hmaarrfk commented 5 years ago

Than you @mshabunin I can confirm this works with a webcam on ubuntu 18.04