参考文献:
http://bbs.elecfans.com/jishu_503398_1_1.html
帖子的主要内容就是在Ubuntu16.04上安装图像处理软件OpenCV,并用简单的程序实现UVC摄像头的图像采集
硬件平台:Windows7 64 bit + USB摄像头C270
软件平台:VMware® Workstation 12 Pro+ Ubuntu16.04 + arm-linux-gcc4.3.2 + OpenCV3.1
一、知识补充
1.什么是OpenCV
OpenCV是一款开源的图像处理库,于1999年由Intel公司发起和建立。OpenCV为Python、Matlab等多种计算机语言提供了接口,它的库函数采用了C和C++编写,可以在Windows、Linux、Mac OS和Android等多种操作系统上面运行。采用OpenCV做图像处理,可以使显著提高编程效率。可以到http://opencv.org/downloads.html下载需要的版本。
sudo apt-get install cmake
待完成安装后,在终端输入以下指令,可以查看安装cmake的版本信息。
cmake --version
cmake version 3.5.1
可以看到:
sudo apt-get update
sudo apt-get upgrade
(2)安装依赖项
sudo apt-get install pkg-config libgtk2.0-dev build-essential libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev python-dev python-numpy python-tk libtbb-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev default-jdk ant libvtk5-qt4-dev
(3)下载并解压OpenCV3.1.0至Ubuntu16.04的用户目录下
cd ~
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/3.1.0/opencv-3.1.0.zip
unzip opencv-3.1.0.zip
cd opencv-3.1.0
下载很慢,你可以到我网盘试试:
(4)OpenCV 2.0之后的版本,必须使用CMake创建Makefile。我使用的CMake版本是3.5.1。最后的两个点“..”的意思是:当前目录在build文件夹里,所以在编译的时候需要回到OpenCV的主菜单。
mkdir build
cd build
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON ..
1.运行上的指令时出现如下错误:
js@ubuntu:~/opencv/opencv-3.1.0/build/build$ cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON ..
CMake Error: The source directory "/home/js/opencv/opencv-3.1.0/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
查各种原因,出现这个错误提示的原因是CMakeLists.txt 不在/home/js/opencv/opencv-3.1.0/build路径中,咨询一看,我晕菜,居然在build下面还建了一个build文件夹,rm -r build后,在上一层的build中再次输入上面的命令,又在build的下一层新建了一个build文件夹,出现同样的错误,看来不是我的笔误造成的两层文件夹,而是它自动新建了一个build文件夹,怎么回事,之前我在另外一个虚拟机都没有自动新建一个文件夹的啊。。。搞不懂,先不管他,既然他要自动新建build文件夹,那么我事先就不建build文件夹了。。直接在/home/js/opencv/opencv-3.1.0/运行上面同样的命令。哈哈,开始配置了。。。
但是又出错了:
重新把上面的 sudo apt-get update 和sudo apt-get upgrade,执行一遍,第一个没问题,第二个居然出错了。问题如下:
libtiff5-dev:i386 libtiff5-dev
E: Package ‘libtiff4-dev’ has no installation candidate
http://installion.co.uk/ubuntu/vivid/main/l/libtiff5-dev/install/index.html
输入:
sudo apt-get install libtiff5-dev
还是不管用,仔细阅读提示,发现是libtiff4-dev无效了,没有了,用libtiff5-dev 代替了。好了,重新执行依赖,并将其中的libtiff4-dev 该为libtiff5-dev。好了,开始下载了。。。
– Checking for module ‘tbb’
– Found tbb, version 4.4~20151115
– ICV: Downloading ippicv_linux_20151201.tgz… 这个地方等待下载了,据之前的经验,这里下载的东西的校验值会出问题,导致配置不成功。。。
没关系,从网上先下载ippicv_linux_20151201.tgz 在放到它应该的目录下就行了。。。写完这段话,还在下载,不知道会不会成功呢。。OK,该来还是会来:
CMake Error at 3rdparty/ippicv/downloader.cmake:77 (message):
ICV: Failed to download ICV package: ippicv_linux_20151201.tgz.
Status=28;”Timeout was reached”
Call Stack (most recent call first):
3rdparty/ippicv/downloader.cmake:110 (_icv_downloader)
cmake/OpenCVFindIPP.cmake:237 (include)
cmake/OpenCVFindLibsPerf.cmake:12 (include)
CMakeLists.txt:537 (include)
– Configuring incomplete, errors occurred!
See also “/home/js/opencv/opencv-3.1.0/build/CMakeFiles/CMakeOutput.log”.
See also “/home/js/opencv/opencv-3.1.0/build/CMakeFiles/CMakeError.log”.js@ubuntu:~/opencv/opencv-3.1.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e$ ls
ippicv_linux_20151201.tgz
进入上面的目录,并且删除“ippicv_linux_20151201.tgz”,将下载的文件cp到这个这个地方。重新在build目录下输入配置命令:。
(实在百度不到这个文件,可以去我的网盘下载:
1.ippicv_linux_20141027.tgz”:
https://yunpan.cn/Oc6gRzCihpQGXc 访问密码 a25d
2.ippicv_linux_20151201.tgz”
https://yunpan.cn/Oc6sYbdKLc7uRX 访问密码 a6b0)
运行cmake的时候,会在终端出现依赖项的配置列表如下:
--
-- OpenCV modules:
-- To be built: core flann imgproc ml photo video viz imgcodecs shape videoio highgui objdetect superres ts features2d calib3d java stitching videostab python2
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev python3
--
-- GUI:
-- QT 4.x: YES (ver 4.8.7 EDITION = OpenSource)
-- QT OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libQtOpenGL.so)
-- OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGL.so)
-- VTK support: YES (ver 5.10.1)
--
-- Media I/O:
-- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
-- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
-- WEBP: build (ver 0.3.1)
-- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
-- TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.6)
-- JPEG 2000: /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
-- OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
-- GDAL: NO
--
-- Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: YES (ver 2.2.4)
-- FFMPEG: YES
-- codec: YES (ver 56.60.100)
-- format: YES (ver 56.40.101)
-- util: YES (ver 54.31.100)
-- swscale: YES (ver 3.1.101)
-- resample: NO
-- gentoo-style: YES
-- GStreamer: NO
-- OpenNI: NO
-- OpenNI PrimeSensor Modules: NO
-- OpenNI2: NO
-- PvAPI: NO
-- GigEVisionSDK: NO
-- UniCap: NO
-- UniCap ucil: NO
-- V4L/V4L2: Using libv4l1 (ver 1.10.0) / libv4l2 (ver 1.10.0)
-- XIMEA: NO
-- Xine: NO
-- gPhoto2: NO
--
-- Parallel framework: TBB (ver 4.4 interface 9002)
--
-- Other third-party libraries:
-- Use IPP: 9.0.1 [9.0.1]
-- at: /home/js/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx
-- Use IPP Async: NO
-- Use VA: NO
-- Use Intel VA-API/OpenCL: NO
-- Use Eigen: YES (ver 3.2.92)
-- Use Cuda: NO
-- Use OpenCL: YES
-- Use custom HAL: NO
--
-- OpenCL:
-- Version: dynamic
-- Include path: /home/js/opencv/opencv-3.1.0/3rdparty/include/opencl/1.2
-- Use AMDFFT: NO
-- Use AMDBLAS: NO
--
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.12)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.5.2)
--
-- Python (for build): /usr/bin/python2.7
--
-- Java:
-- ant: /usr/bin/ant (ver 1.9.6)
-- JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
-- Java wrappers: YES
-- Java tests: YES
--
-- Matlab: Matlab not found or implicitly disabled
--
-- Documentation:
-- Doxygen: NO
-- PlantUML: NO
--
-- Tests and samples:
-- Tests: YES
-- Performance tests: YES
-- C/C++ Examples: YES
--
-- Install path: /usr/local
--
-- cvconfig.h is in: /home/js/opencv/opencv-3.1.0/build
-- -----------------------------------------------------------------
我发现,其实在opencv-3.1.0目录中输入:
cmake .
也就是说不用输入后面的那一长串宏定义开关。也可以编译,由于这里使用的是cmake . 所以最终配置的文件会在opencv-3.1.0目录下,如果在build目录下,是否会成功呢??你可以试一下,请留言告诉我结果吧。感谢!!!
区别在于:
– cvconfig.h is in: /home/js/opencv/opencv-3.1.0/build
在以上的配置列表中,观察主要的依赖软件都已配置到位,如FFMPEG、QT、OPENGL和V4L2等,显示须为YES。一下,核对了一下,这些确实已经配置到位。可以进行下一步了。编译和安装openCV3.1.0
配置总结:其实可以这样在open目录下,在解压opencv3.1.0之前,可以新建一个目录如下:
js@ubuntu:~/opencv/opencv-3.1.0/3rdparty/ippicv/downloads/linux-808b791a6eac9ed78d32a7666804320e$
然后把从我网盘或者网上下载的文件ippicv_linux_20151201.tgz拷贝到当前目录下。在opencv3.1.0目录下新建build目录。执行:cmake .. 就行啦。。。一下内容是copy的我实际操作的log。有点长,有耐心的的可以快速浏览一下:
js@ubuntu:~/opencv/opencv-3.1.0$ mkdir build
js@ubuntu:~/opencv/opencv-3.1.0$
js@ubuntu:~/opencv/opencv-3.1.0$ cd build/
js@ubuntu:~/opencv/opencv-3.1.0/build$ cmake ..
-- The CXX compiler identification is GNU 5.4.0
-- The C compiler identification is GNU 5.4.0
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
中间略去~~~~~~~
-- Performing Test HAVE_C_WERROR_ADDRESS
-- Performing Test HAVE_C_WERROR_ADDRESS - Success
--
-- GUI:
-- QT: NO
-- GTK+ 2.x: YES (ver 2.24.30)
-- GThread : YES (ver 2.48.1)
-- GtkGlExt: NO
-- OpenGL support: NO
-- VTK support: YES (ver 5.10.1)
--
-- Media I/O:
-- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
-- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
-- WEBP: build (ver 0.3.1)
-- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
-- TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.6)
-- JPEG 2000: /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
-- OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
-- GDAL: NO
--
-- Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: YES (ver 2.2.4)
-- FFMPEG: YES
-- codec: YES (ver 56.60.100)
-- format: YES (ver 56.40.101)
-- util: YES (ver 54.31.100)
-- swscale: YES (ver 3.1.101)
-- resample: NO
-- gentoo-style: YES
-- GStreamer: NO
-- OpenNI: NO
-- OpenNI PrimeSensor Modules: NO
-- OpenNI2: NO
-- PvAPI: NO
-- GigEVisionSDK: NO
-- UniCap: NO
-- UniCap ucil: NO
-- V4L/V4L2: Using libv4l1 (ver 1.10.0) / libv4l2 (ver 1.10.0)
-- XIMEA: NO
-- Xine: NO
-- gPhoto2: NO
--
-- Parallel framework: pthreads
--
-- Other third-party libraries:
-- Use IPP: 9.0.1 [9.0.1]
-- at: /home/js/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx
-- Use IPP Async: NO
-- Use VA: NO
-- Use Intel VA-API/OpenCL: NO
-- Use Eigen: YES (ver 3.2.92)
-- Use Cuda: NO
-- Use OpenCL: YES
-- Use custom HAL: NO
--
-- OpenCL:
-- Version: dynamic
-- Include path: /home/js/opencv/opencv-3.1.0/3rdparty/include/opencl/1.2
-- Use AMDFFT: NO
-- Use AMDBLAS: NO
--
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.12)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.5.2)
--
-- Python (for build): /usr/bin/python2.7
--
-- Java:
-- ant: /usr/bin/ant (ver 1.9.6)
-- JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
-- Java wrappers: YES
-- Java tests: YES
--
-- Matlab: Matlab not found or implicitly disabled
--
-- Documentation:
-- Doxygen: NO
-- PlantUML: NO
--
-- Tests and samples:
-- Tests: YES
-- Performance tests: YES
-- C/C++ Examples: NO
--
-- Install path: /usr/local
--
-- cvconfig.h is in: /home/js/opencv/opencv-3.1.0/build
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /home/js/opencv/opencv-3.1.0/build
弄完之后在确认一下是否成功???呀,好像不行呢??
好那我们重新
mkdir build
cd build
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON ..
如下情况:
js@ubuntu:~/opencv/opencv-3.1.0/build$ cd ..
js@ubuntu:~/opencv/opencv-3.1.0$ mkdir build
mkdir: cannot create directory ‘build’: File exists
js@ubuntu:~/opencv/opencv-3.1.0$ cd build
js@ubuntu:~/opencv/opencv-3.1.0/build$ cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON ..
-- Detected version of GNU GCC: 54 (504)
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found suitable version "1.2.8", minimum required is "1.2.3")
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.8")
-- Found OpenEXR: /usr/lib/x86_64-linux-gnu/libIlmImf.so
//中间略去~~~
-- OpenCV modules:
-- To be built: core flann imgproc ml photo video viz imgcodecs shape videoio highgui objdetect superres ts features2d calib3d java stitching videostab python2
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev python3
--
-- GUI:
-- QT 4.x: YES (ver 4.8.7 EDITION = OpenSource)
-- QT OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libQtOpenGL.so)
-- OpenGL support: YES (/usr/lib/x86_64-linux-gnu/libGLU.so /usr/lib/x86_64-linux-gnu/libGL.so)
-- VTK support: YES (ver 5.10.1)
--
-- Media I/O:
-- ZLib: /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.8)
-- JPEG: /usr/lib/x86_64-linux-gnu/libjpeg.so (ver )
-- WEBP: build (ver 0.3.1)
-- PNG: /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.2.54)
-- TIFF: /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 - 4.0.6)
-- JPEG 2000: /usr/lib/x86_64-linux-gnu/libjasper.so (ver 1.900.1)
-- OpenEXR: /usr/lib/x86_64-linux-gnu/libImath.so /usr/lib/x86_64-linux-gnu/libIlmImf.so /usr/lib/x86_64-linux-gnu/libIex.so /usr/lib/x86_64-linux-gnu/libHalf.so /usr/lib/x86_64-linux-gnu/libIlmThread.so (ver 2.2.0)
-- GDAL: NO
--
-- Video I/O:
-- DC1394 1.x: NO
-- DC1394 2.x: YES (ver 2.2.4)
-- FFMPEG: YES
-- codec: YES (ver 56.60.100)
-- format: YES (ver 56.40.101)
-- util: YES (ver 54.31.100)
-- swscale: YES (ver 3.1.101)
-- resample: NO
-- gentoo-style: YES
-- GStreamer: NO
-- OpenNI: NO
-- OpenNI PrimeSensor Modules: NO
-- OpenNI2: NO
-- PvAPI: NO
-- GigEVisionSDK: NO
-- UniCap: NO
-- UniCap ucil: NO
-- V4L/V4L2: Using libv4l1 (ver 1.10.0) / libv4l2 (ver 1.10.0)
-- XIMEA: NO
-- Xine: NO
-- gPhoto2: NO
--
-- Parallel framework: TBB (ver 4.4 interface 9002)
--
-- Other third-party libraries:
-- Use IPP: 9.0.1 [9.0.1]
-- at: /home/js/opencv/opencv-3.1.0/3rdparty/ippicv/unpack/ippicv_lnx
-- Use IPP Async: NO
-- Use VA: NO
-- Use Intel VA-API/OpenCL: NO
-- Use Eigen: YES (ver 3.2.92)
-- Use Cuda: NO
-- Use OpenCL: YES
-- Use custom HAL: NO
--
-- OpenCL:
-- Version: dynamic
-- Include path: /home/js/opencv/opencv-3.1.0/3rdparty/include/opencl/1.2
-- Use AMDFFT: NO
-- Use AMDBLAS: NO
--
-- Python 2:
-- Interpreter: /usr/bin/python2.7 (ver 2.7.12)
-- Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.12)
-- numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.11.0)
-- packages path: lib/python2.7/dist-packages
--
-- Python 3:
-- Interpreter: /usr/bin/python3 (ver 3.5.2)
--
-- Python (for build): /usr/bin/python2.7
--
-- Java:
-- ant: /usr/bin/ant (ver 1.9.6)
-- JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include
-- Java wrappers: YES
-- Java tests: YES
--
-- Matlab: Matlab not found or implicitly disabled
--
-- Documentation:
-- Doxygen: NO
-- PlantUML: NO
--
-- Tests and samples:
-- Tests: YES
-- Performance tests: YES
-- C/C++ Examples: YES
--
-- Install path: /usr/local
--
-- cvconfig.h is in: /home/js/opencv/opencv-3.1.0/build
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
CMake Warning:
Manually-specified variables were not used by the project:
BUILD_NEW_PYTHON_SUPPORT
-- Build files have been written to: /home/js/opencv/opencv-3.1.0/build
js@ubuntu:~/opencv/opencv-3.1.0/build$
(5)编译和安装OpenCV3.1.0。make编译是一个漫长的过程,建议去小憩一会儿或者喝喝茶活动活动筋骨,待编译进度到100%之后,进行安装。安装需在root权限下进行。
make
开始编译:
sudo make install
(6)配置OpenCV。
sudo gedit /etc/ld.so.conf.d/opencv.conf
/usr/local/lib
输入库文件路径,保存并退出。
(7)使库文件生效,在终端输入
sudo ldconfig
(8)设置环境变量
sudo gedit /etc/bash.bashrc
保存,关闭环境变量设置文档。关闭终端,重启Ubuntu。至此,Ubuntu16.04下OpenCV3.1.0的安装结束。
三、验证OpenCV的安装:用USB摄像头实现图像采集。
实现步骤:
1. 打开终端,进入用户目录,创建webcam_capture.cpp
cd ~
gedit webcam_capture.cpp
#include "cxcore.h"
#include "highgui.h"
#include "cv.h"
using namespace std;
int main()
{
IplImage* pFrame = NULL;
cvNamedWindow("result", 1);
CvCapture* pCapture = cvCreateCameraCapture(-1);
cvSetCaptureProperty(pCapture,CV_CAP_PROP_FRAME_WIDTH,320);
cvSetCaptureProperty(pCapture,CV_CAP_PROP_FRAME_HEIGHT,240);
while(true)
{
pFrame = cvQueryFrame( pCapture );
if(!pFrame) break;
char c = cvWaitKey(33);
if(c == 32) break;
cvShowImage("result", pFrame);
}
return 0;
}
g++ webcam_capture.cpp -o webcam_capture `pkg-config --cflags --libs opencv`
出错了
opencv会默认安装在/usr/local/目录文件下,若要改变安装位置有选项“-D CMAKE_INSTALL_PREFIX=/usr/local”,修改后面的参数即可。
其中命令”cmake -DINSTALL_CREATE_DISTRIB=ON”是必须要加上的,否则编译以后目标文件链接库的时候会出现以下错误