刚才要做对视频每一帧的提取,按照网上的一种方法安装了Opencv 3.2,然而一切安装完毕后执行以下代码:
import cv2catcher = cv2.VideoCapture('3.avi')
报错,提示:
Unable to stop the stream: Inappropriate ioctl for device
各种调整都没能解决问题,无奈重新安装了3.0.0版本的Opencv,总结步骤如下。
已有环境:CUDA 8.0 cudnn 7.5 Python 2.7 scipy numpy theano 等深度学习套件
参考:http://rodrigoberriel.com/2014/10/installing-opencv-3-0-0-on-ubuntu-14-04/
(一) 安装依赖项
sudo apt-get -y install libopencv-dev build-essential cmake git libgtk2.0-dev pkg-config python-dev python-numpy libdc1394-22 libdc1394-22-dev libjpeg-dev libpng12-dev libtiff4-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev libtbb-dev libqt4-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils unzip(二) 下载Opencv源码
http://opencv.org/releases.html
下载后解压到Home文件夹,在解压出来的文件夹中新建一个名为build的文件夹,并在build内打开终端。
(三)编译,安装
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON .. make -j $(nproc) sudo make install在执行 make -j $(nproc) 时,编译到92%报错:
modules/cudalegacy/CMakeFiles/opencv_cudalegacy.dir/build.make:290: recipe for target 'modules/cudalegacy/CMakeFiles/opencv_cudalegacy.dir/src/graphcuts.cpp.o' Failed make[2]: *** [modules/cudalegacy/CMakeFiles/opencv_cudalegacy.dir/src/graphcuts.cpp.o] Error 1
经过谷歌找到了解决方法,原来官方的3.0.0版本发布时尚不支持CUDA 8.0,现在已经修复:
参考https://github.com/opencv/opencv/pull/6510/commits/10896129b39655e19e4e7c529153cb5c2191a1db
即进入到~/opencv-3.0.0/modules/cudalegacy/src文件夹中,打开graphcuts.cpp文件,删除第45行的预处理语句,改为
#if !defined (HAVE_CUDA) || defined (CUDA_DISABLER) || (CUDART_VERSION >= 8000)
重新编译即可。
原文链接:https://www.f2er.com/ubuntu/353395.html