Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VideoCapture is not working in OpenCV 2.4.2

I recently installed OpenCV 2.4.2 in Ubuntu 12.04.

cap = VideoCapture(0)

is working. but I can't grab frames from some video source.

cap = VideoCapture("input.avi")
img = cap.read() 

gives me a numpy with all zero elements.

I have also installed ffmpeg 0.11, Latest snapshot of x264, v4l-0.8.8 (All are latest stable versions)

cmake -D WITH_QT=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D WITH_TBB=ON -D BUILD_EXAMPLES=OFF WITH_V4L=ON .. 
make
sudo make install

When I do cmake, I get this

-- Detected version of GNU GCC: 46 (406)
-- Found OpenEXR: /usr/lib/libIlmImf.so
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - found
-- Looking for libavformat/avformat.h
-- Looking for libavformat/avformat.h - found
-- Looking for ffmpeg/avformat.h
-- Looking for ffmpeg/avformat.h - not found
-- checking for module 'tbb'
-- package 'tbb' not found

And

--   Video I/O:  
--     DC1394 1.x:                  NO  
--     DC1394 2.x:                  YES (ver 2.2.0)  
--     FFMPEG:                      YES  
--       codec:                     YES (ver 54.23.100)  
--       format:                    YES (ver 54.6.100)  
--       util:                      YES (ver 51.54.100)  
--       swscale:                   YES (ver 2.1.100)  
--       gentoo-style:              YES  
--     GStreamer:                   
--       base:                      YES (ver 0.10.36)  
--       app:                       YES (ver 0.10.36)  
--       video:                     YES (ver 0.10.36)  
--     OpenNI:                      NO  
--     OpenNI PrimeSensor Modules:  NO  
--     PvAPI:                       NO  
--     UniCap:                      NO  
--     UniCap ucil:                 NO  
--     V4L/V4L2:                    Using libv4l (ver 0.8.8)  
--     XIMEA:                       NO  
--     Xine:                        NO

I looked for videodev.h, etc

  • /usr/include/linux/videodev2.h exists
  • /usr/include/libavformat/avformat.h exists
  • /usr/local/include/libavformat/avformat.h exists

But I couldn't find ffmpeg/avformat.h

What's the problem here?

like image 709
Froyo Avatar asked Jul 12 '12 04:07

Froyo


People also ask

How does OpenCV VideoCapture work?

Capture Video from Camera OpenCV allows a straightforward interface to capture live stream with the camera (webcam). It converts video into grayscale and display it. We need to create a VideoCapture object to capture a video. It accepts either the device index or the name of a video file.

What is cv2 VideoCapture in Python?

cv2. VideoCapture is a function of openCV library(used for computer vision, machine learning, and image processing) which allows working with video either by capturing via live webcam or by a video file.

Is VideoCapture read blocking?

VideoCapture(). read() is a blocking operation, the main program is stalled until the frame is read from the camera device and returned. A method to improve performance would be to spawn another thread to handle grabbing frames in parallel instead of relying on a single thread to grab frames in sequential order.

What does cv2 VideoCapture return?

Next, we cay cap = cv2. VideoCapture(0) . This will return video from the first webcam on your computer.


1 Answers

So, I realized there was some problem with ffmpeg. and I rebuilt and installed ffmpeg and then changed flags for cmake to make opencv.

For ffmpeg,

 ./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab 
make 
sudo make install

For OpenCV,

cmake -D CMAKE_BUILD_TYPE=RELEASE ..
make
sudo make install

Here's the complete script to install OpenCV 2.4.2 https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/2.4/opencv2_4_2.sh

and here's my blogpost about OpenCV 2.4.2 installation in detail http://jayrambhia.com/blog/install-opencv-2-4-in-ubuntu-12-04-precise-pangolin/

like image 155
Froyo Avatar answered Sep 18 '22 12:09

Froyo