The Bearded Templar
The Bearded Templar

Reputation: 701

OpenCV VideoCapture Not Opening

I'm trying to use OpenCV's cv2 python bindings on an Amazon server running Ubuntu 14.04 and I can't seem to get VideoCapture to work properly.

I tried opening the default capture as follows:

import cv2
cap = cv2.VideoCapture(0)
cap.isOpened() #Returns false

I tested this on my local machine and it was true as expected, so there is something wrong with my open CV configuration. I've tried a variety of things:

I'm kind of out of ideas at this point. Any ideas of what could be going wrong?

Edit: OpenCV version is 2.4.9.

Upvotes: 15

Views: 30761

Answers (2)

Ravish Kumar Sharma
Ravish Kumar Sharma

Reputation: 238

I also faced a similar problem. Possible solutions:

  1. Check if you have given the correct path.

  2. If you have installed OpenCV using pip, it will not work. You can remove OpenCV and reinstall it looking at the official documentation.

  3. Ways to install via pip,
    pip install opencv-python Only installs main module
    pip install opencv-contrib-python Install main and contrib module, so use this command.

Upvotes: 9

Orlov Const
Orlov Const

Reputation: 371

I had the same problem and was solved successfully. You should to build OpenCV with WITH_FFMPEG flag:

cmake .. -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_GTK=ON -DWITH_FFMPEG=1 

And you should view "YES" everywhere in section FFMPEG:

Video I/O:
--     DC1394 1.x:                  NO
--     DC1394 2.x:                  YES (ver 2.2.5)
--     FFMPEG:                      YES
--       avcodec:                   YES (ver 57.107.100)
--       avformat:                  YES (ver 57.83.100)
--       avutil:                    YES (ver 55.78.100)
--       swscale:                   YES (ver 4.8.100)
--       avresample:                YES (ver 3.7.0)
--     GStreamer:                   NO
--     OpenNI:                      NO
--     OpenNI PrimeSensor Modules:  NO
--     PvAPI:                       NO
--     GigEVisionSDK:               NO
--     UniCap:                      NO
--     UniCap ucil:                 NO
--     V4L/V4L2:                    NO/YES
--     XIMEA:                       NO
--     Xine:                        NO

If you will not see it then need to install next packages via apt (if you are using Debian or Ubuntu Linux):

sudo apt-get install libav-tools libavcodec-dev libavformat-dev libavutil-dev libswscale-dev libx264-dev

Upvotes: 1

Related Questions