VideoCapture 在 OpenCV 2.4.2 中不起作用 [英] VideoCapture is not working in OpenCV 2.4.2

查看:37
本文介绍了VideoCapture 在 OpenCV 2.4.2 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在 Ubuntu 12.04 中安装了 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() 

给我一​​个全零元素的numpy.

gives me a numpy with all zero elements.

我也安装了ffmpeg 0.11,x264的最新快照,v4l-0.8.8(都是最新的稳定版本)

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

当我做 cmake 时,我得到了这个

When I do cmake, I get this

-- 检测到的 GNU GCC 版本:46 (406)
-- 找到 OpenEXR:/usr/lib/libIlmImf.so
-- 寻找 linux/videodev.h
-- 正在寻找 linux/videodev.h - 未找到
-- 寻找 linux/videodev2.h
-- 寻找 linux/videodev2.h - 找到
-- 寻找 libavformat/avformat.h
-- 寻找 libavformat/avformat.h - 找到
-- 寻找 ffmpeg/avformat.h
-- 正在寻找 ffmpeg/avformat.h - 未找到
-- 检查模块'tbb'
-- 未找到包 'tbb'

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

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

我寻找 videodev.h 等

I looked for videodev.h, etc

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

但是我找不到ffmpeg/avformat.h

这里有什么问题?

推荐答案

所以,我意识到 ffmpeg 存在一些问题.我重建并安装了 ffmpeg,然后更改了 cmake 的标志以制作 opencv.

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

对于 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

对于 OpenCV,

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

这是安装 OpenCV 2.4.2 的完整脚本 https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/2.4/opencv2_4_2.sh

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 安装的详细博客文章 http://jayrambhia.com/blog/install-opencv-2-4-in-ubuntu-12-04-precise-pangolin/

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/

这篇关于VideoCapture 在 OpenCV 2.4.2 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆