简体   繁体   English

VideoCapture在OpenCV 2.4.2中不起作用

[英]VideoCapture is not working in OpenCV 2.4.2

I recently installed OpenCV 2.4.2 in Ubuntu 12.04. 我最近在Ubuntu 12.04中安装了OpenCV 2.4.2。

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. 给了我一个零元素的numpy。

I have also installed ffmpeg 0.11, Latest snapshot of x264, v4l-0.8.8 (All are latest stable versions) 我还安装了ffmpeg 0.11,x264的最新快照,v4l-0.8.8(所有都是最新的稳定版本)

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 当我做cmake时,我明白了

-- Detected version of GNU GCC: 46 (406) - 检测到的GNU GCC版本:46(406)
-- Found OpenEXR: /usr/lib/libIlmImf.so - 找到OpenEXR:/usr/lib/libIlmImf.so
-- Looking for linux/videodev.h - 寻找linux / videodev.h
-- Looking for linux/videodev.h - not found - 寻找linux / videodev.h - 找不到
-- Looking for linux/videodev2.h - 寻找linux / videodev2.h
-- Looking for linux/videodev2.h - found - 寻找linux / videodev2.h - 找到了
-- Looking for libavformat/avformat.h - 寻找libavformat / avformat.h
-- Looking for libavformat/avformat.h - found - 寻找libavformat / avformat.h - 找到了
-- Looking for ffmpeg/avformat.h - 寻找ffmpeg / avformat.h
-- Looking for ffmpeg/avformat.h - not found - 寻找ffmpeg / avformat.h - 未找到
-- checking for module 'tbb' - 检查模块'tbb'
-- package 'tbb' not found - 找不到包'tbb'

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 我找了videodev.h等

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

But I couldn't find ffmpeg/avformat.h 但我找不到ffmpeg/avformat.h

What's the problem here? 这有什么问题?

So, I realized there was some problem with ffmpeg. 所以,我意识到ffmpeg存在一些问题。 and I rebuilt and installed ffmpeg and then changed flags for cmake to make opencv. 然后我重建并安装了ffmpeg,然后为cmake更改了标志以生成opencv。

For ffmpeg, 对于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, 对于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 这是安装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/ 这是我关于OpenCV 2.4.2安装的博文详情http://jayrambhia.com/blog/install-opencv-2-4-in-ubuntu-12-04-precise-pangolin/

To run a full installation of OpenCV try the following: 要运行OpenCV的完整安装,请尝试以下操作:

sudo apt-get install libopencv-dev python-opencv

For more details check out the following link http://milq.github.io/install-opencv-ubuntu-debian/ 有关更多详细信息,请查看以下链接http://milq.github.io/install-opencv-ubuntu-debian/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM