Ubuntu下编译安装OpenCV 2.4.7并读取摄像头[转]
2016-07-08 17:48
417 查看
主要参考:
1、http://www.ozbotz.org/opencv-installation/
2、http://www.ozbotz.org/opencv-install-troubleshooting/
开发环境:VMware下Ubuntu+OpenCV2.4.7
安装过程:
Remove any installed versions of ffmpeg and x264.
Get all the dependencies for x264 and ffmpeg.
Download and install gstreamer.
Download and install gtk.
Download and install libjpeg.
Create a directory to hold source code.
Download and install install x264.Download a recent stable snapshot of x264 from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/. The exact version does not seem to matter. To write this guide, I used version x264-snapshot-20120528-2245-stable.tar.bz2, but I have used previous versions too.
Configure and build the x264 libraries.
IMPORTANT: If you are running a 64-bit version of Ubuntu, you must configure x264 as shown in the following command:
The -shared and -pic options might also be required when you compile for some other architectures, such as ARM. You know you need these options if you get the following error when compiling OpenCV:
Download and install install ffmpeg.Download ffmpeg version 0.11.1 from http://ffmpeg.org/download.html.
Configure and build ffmpeg.
IMPORTANT: Just like with x264 in the previous step, you must configure ffmpeg with the -shared and -pic options if you are running a 64-bit version of Ubuntu or some other architectures, such as ARM.
Download and install install a recent version of v4l (video for linux) from http://www.linuxtv.org/downloads/v4l-utils/. For this guide I used version 0.8.8.
Download and install install OpenCV 2.4.2.Download OpenCV version 2.4.2 from http://sourceforge.net/projects/opencvlibrary/files/
Create a new build directory and run cmake:
Verify that the output of cmake includes the following text:found gstreamer-base-0.10
GTK+ 2.x: YES
FFMPEG: YES
GStreamer: YES
V4L/V4L2: Using libv4l
Build and install OpenCV.
Configure Linux.Tell linux where the shared libraries for OpenCV are located by entering the following shell command:
Add the command to your .bashrc file so that you don’t have to enter every time your start a new terminal. (注:我主要采用将export LD_LIBRARY_PATH=/usr/local/lib加入.bashrc file的方法,.bashrc file为隐藏文件,在主用户目录下,可用shell命令:ls -al查看)
Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text
After editing the opencv.conf file, enter the following command:
.
Using your favorite editor, add the following two lines to the end of /etc/bash.bashrc:
After completing the previous steps, your system should be ready to compile code that uses the OpenCV libraries. The following example shows one way to compile code for OpenCV(这里最好先进行重启):
以上按照过程中,可能会遇到其他问题,许多都可参考《OpenCV Installation Troubleshooting Guide》,里面有详细的问题描述及解答,非常清楚。
最后g++编译的代码main.cpp如下:
读取摄像头结果如下图:
Utkarsh Sinha runs AiShack, a site that has easy-to-understand tutorials using OpenCV to solve real-world problems: http://www.aishack.in/topics/tutorials/
Sebastian Montabone has several articles on installing OpenCV and image processing. His web site is http://www.samontab.com/
FakeOutdoorsman’s posted an excellent dependency install guide, which is located on the Ubuntu forums: http://ubuntuforums.org/showthread.php?t=786095
1、http://www.ozbotz.org/opencv-installation/
2、http://www.ozbotz.org/opencv-install-troubleshooting/
开发环境:VMware下Ubuntu+OpenCV2.4.7
安装过程:
The Installation Procedure
To install and configure OpenCV 2.4.1, complete the following steps. The commands shown in each step can be copy and pasted directly into a Linux command line.Remove any installed versions of ffmpeg and x264.
sudo apt-get remove ffmpeg x264 libx264-dev
Get all the dependencies for x264 and ffmpeg.
sudo apt-get update sudo apt-get install build-essential checkinstall git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev
Download and install gstreamer.
sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg
Download and install gtk.
sudo apt-get install libgtk2.0-0 libgtk2.0-dev
Download and install libjpeg.
sudo apt-get install libjpeg8 libjpeg8-dev
Create a directory to hold source code.
cd ~ mkdir src
Download and install install x264.Download a recent stable snapshot of x264 from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/. The exact version does not seem to matter. To write this guide, I used version x264-snapshot-20120528-2245-stable.tar.bz2, but I have used previous versions too.
cd ~/src
wget ftp://ftp.videolan.org/pub/videolan/x264/snapshots/x264-snapshot-20120528-2245-stable.tar.bz2[/code]tar xvf x264-snapshot-20120528-2245-stable.tar.bz2cd x264-snapshot-20120528-2245-stable
Configure and build the x264 libraries.
./configure --enable-static make sudo make install
./configure --enable-shared --enable-pic
[ 25%] Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/bitstrm.cpp.o Linking CXX shared library ../../lib/libopencv_highgui.so /usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32S against `av_destruct_packet' can not be used when making a shared object; recompile with -fPIC /usr/local/lib/libavcodec.a: could not read symbols: Bad value
Download and install install ffmpeg.Download ffmpeg version 0.11.1 from http://ffmpeg.org/download.html.
cd ~/src wget http://ffmpeg.org/releases/ffmpeg-0.11.1.tar.bz2 tar xvf ffmpeg-0.11.1.tar.bz2 cd ffmpeg-0.11.1
Configure and build 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
./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 --enable-shared --enable-pic
Download and install install a recent version of v4l (video for linux) from http://www.linuxtv.org/downloads/v4l-utils/. For this guide I used version 0.8.8.
cd ~/src
wget http://www.linuxtv.org/downloads/v4l-utils/v4l-utils-0.8.8.tar.bz2[/code]tar xvf v4l-utils-0.8.8.tar.bz2
cd v4l-utils-0.8.8
make sudo make install
Download and install install OpenCV 2.4.2.Download OpenCV version 2.4.2 from http://sourceforge.net/projects/opencvlibrary/files/
cd ~/src
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.2/OpenCV-2.4.2.tar.bz2[/code]tar xvf OpenCV-2.4.2.tar.bz2
Create a new build directory and run cmake:
cd OpenCV-2.4.2/ mkdir build cd build cmake -D CMAKE_BUILD_TYPE=RELEASE ..
Verify that the output of cmake includes the following text:found gstreamer-base-0.10
GTK+ 2.x: YES
FFMPEG: YES
GStreamer: YES
V4L/V4L2: Using libv4l
Build and install OpenCV.
make sudo make install
Configure Linux.Tell linux where the shared libraries for OpenCV are located by entering the following shell command:
export LD_LIBRARY_PATH=/usr/local/lib
Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text
/usr/local/libto the end of a file named
/etc/ld.so.conf.d/opencv.conf. In the standard Ubuntu install, the opencv.conf file does not exist; you need to create it. Using vi, for example, enter the following commands:
sudo vi /etc/ld.so.conf.d/opencv.conf G o /usr/local/lib <Esc> :wq!
sudo ldconfig /etc/ld.so.conf
Using your favorite editor, add the following two lines to the end of /etc/bash.bashrc:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH
After completing the previous steps, your system should be ready to compile code that uses the OpenCV libraries. The following example shows one way to compile code for OpenCV(这里最好先进行重启):
g++ `pkg-config opencv --cflags` main.cpp -o main `pkg-config opencv --libs`
以上按照过程中,可能会遇到其他问题,许多都可参考《OpenCV Installation Troubleshooting Guide》,里面有详细的问题描述及解答,非常清楚。
最后g++编译的代码main.cpp如下:
#include <cv.h> #include <opencv/highgui.h> #include<stdio.h> #include<opencv2/opencv.hpp> using namespace cv; int main(int argc, char *argv[]) { CvCapture* pCapture = cvCreateCameraCapture(0); cvNamedWindow("Video", 1); while(1) { IplImage* pFrame=cvQueryFrame( pCapture ); if(!pFrame)break; cvShowImage("Video",pFrame); char c=cvWaitKey(33); if(c==27)break; } cvReleaseCapture(&pCapture); cvDestroyWindow("Video"); return 0; }
读取摄像头结果如下图:
More Information
If you encounter problems installing OpenCV, see the companion guide, “A Comprehensive OpenCV Installation Troubleshooting Guide.”Utkarsh Sinha runs AiShack, a site that has easy-to-understand tutorials using OpenCV to solve real-world problems: http://www.aishack.in/topics/tutorials/
Sebastian Montabone has several articles on installing OpenCV and image processing. His web site is http://www.samontab.com/
FakeOutdoorsman’s posted an excellent dependency install guide, which is located on the Ubuntu forums: http://ubuntuforums.org/showthread.php?t=786095
相关文章推荐
- hadoop
- openwrt更换原有Linux内核版本
- 使用Cropbox解决图片上传
- Ubuntu 12.04嵌入式交叉编译环境arm-linux-gcc搭建过程图解
- Runloop的使用
- 提升进程权限-OpenProcessToken等函数的用法
- 分布式架构中一致性解决方案——Zookeeper集群搭建
- 服务器推送之WebSocket 入门学习路程(三)
- linux中bin和sbin目录的主要区别
- 自定义popwindow的spinner下拉列表
- opencv-视频处理-实时的前景检测-Vibe算法
- Mac直播服务器Nginx配置对HLS的支持
- 用到了以下linux命令,不断更新
- 2016.6.21 -Dmaven.multiModuleProjectDirectory system propery is not set,Check $M2_HOME environment variable and mvn script match.
- 安卓开发中Linux常用命令大全
- Snoopy
- erlang+rabbitmq在linux系统启动中遇到了erlexec:HOME must be set的问题
- 学点SELinux--(1)SELinux的工作方式、启动和停止
- 实现WEB压缩的三种途径:Web服务器(Nginx/Apache)、Php扩展、Php代码
- 2种方式解决nginx负载下的Web API站点里swagger无法使用