Ubuntu下编译安装OpenCV 2.4.7并读取摄像头
主要参考:
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
tar xvf x264-snapshot-20120528-2245-stable.tar.bz2
cd x264-snapshot-20120528-2245-stable
- Configure and build the x264 libraries.
./configure --enable-static
make
sudo make installIMPORTANT: If you are running a 64-bit version of Ubuntu, you must configure x264 as shown in the following command:
./configure --enable-shared --enable-pic
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:
[ 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 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.
- 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 installIMPORTANT: 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.
./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 ffmpeg version 0.11.1 from http://ffmpeg.org/download.html.
- 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
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
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
- Download OpenCV version 2.4.2 from http://sourceforge.net/projects/opencvlibrary/files/
- 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
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
/usr/local/lib
to 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!After editing the opencv.conf file, enter the following command:
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
- Tell linux where the shared libraries for OpenCV are located by entering the following shell command:
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();
cvNamedWindow("Video", ); while()
{
IplImage* pFrame=cvQueryFrame( pCapture );
if(!pFrame)break;
cvShowImage("Video",pFrame);
char c=cvWaitKey();
if(c==)break;
}
cvReleaseCapture(&pCapture);
cvDestroyWindow("Video");
return ;
}
读取摄像头结果如下图:
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
Ubuntu下编译安装OpenCV 2.4.7并读取摄像头的更多相关文章
- Ubuntu下编译安装OpenCV 2.4.7并读取摄像头[转]
主要参考: 1.http://www.ozbotz.org/opencv-installation/ 2.http://www.ozbotz.org/opencv-install-troublesho ...
- Ubuntu下编译安装postgreSQL 10.5
Ubuntu下编译安装postgreSQL 10.5 ubuntu 16.04 LTS系统postgreSQL 10.5 安装包准备 1.从PostgreSQL官网下载PostgreSQL的安装包 安 ...
- 在Ubuntu下编译安装GreatSQL
在Ubuntu下编译安装GreatSQL 本次介绍如何利用Docker构建Ubuntu环境,并将GreatSQL源码编译成二进制文件. 1.准备工作 先创建本次Docker的workdir为 /dat ...
- 在Ubuntu 16.04 LTS下编译安装OpenCV 4.1.1
目录 一 安装前的准备 二 编译并安装OpenCV 4.1.1 注:原创不易,转载请务必注明原作者和出处,感谢支持! OpenCV目前(2019-8-1)的最新版本为4.1.1.本文将介绍如何在Ubu ...
- ubuntu下编译安装poco
系统环境: ubuntu版本:Linux jfcai-VirtualBox 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 ...
- Linux 下编译安装OpenCV【转】
转自:http://www.cnblogs.com/emouse/archive/2013/02/22/2922940.html OpenCV 2.2以后版本需要使用Cmake生成makefile文件 ...
- Ubuntu下编译C++ OpenCV程序并运行
因为想试跑yolov3的缘故,所以装了ubuntu系统,直接通过U盘装的,并不像他们说的“折腾”,反而一切非常顺利,比装软件还简单.然后就是要用C++跑opencv的程序用于比赛,出于 ...
- Linux 下编译安装OpenCV(zhuanzai)
http://www.cnblogs.com/emouse/archive/2013/02/22/2922940.html Cmake的安装 OpenCV 2.2以后版本需要使用Cmake生成make ...
- ubuntu系统编译安装OpenCV 4.4
内容转载自我的博客 目录 前言 1. 下载源码 2. 安装各种依赖 3. 开始编译安装 4. 配置C++开发环境 5. 程序执行时加载动态库*.so 6. 测试cpp文件 7. 配置python3的o ...
随机推荐
- P3155 [CQOI2009]叶子的染色
P3155 [CQOI2009]叶子的染色 题目描述 给一棵m个结点的无根树,你可以选择一个度数大于1的结点作为根,然后给一些结点(根.内部结点和叶子均可)着以黑色或白色.你的着色方案应该保证根结点到 ...
- Android studio 使用flutter插件 运行第一个flutter项目 报错 Warning: License for package Android SDK Build-Tools 28.0.3 not accepted.
在Android studio中新建了flutter项目.运行报错licence not accepted. Warning: License for package Android SDK Buil ...
- Backbone基础笔记
之前做一个iPad的金融项目的时候有用到Backbone,不过当时去的时候项目已经进入UAT测试阶段了,就只是改了改Bug,对Backbone框架算不上深入了解,但要说我一点都不熟悉那倒也不是,我不太 ...
- 20155305乔磊2016-2017-2《Java程序设计》第八周学习总结
20155305乔磊2016-2017-2<Java程序设计>第八周学习总结 教材学习内容总结 通用API 日志API 1.java.util.logging包提供了日志功能相关类与接口, ...
- thinkphp 原数据更新
调用TP的save方法更新数据时,如果新数据与数据库中得数据一致, 那么执行M('table')->save(data)方法时,该方法会返回false.现在的需求是,哪怕用户要更新的数据与原数据 ...
- fonts.googleapis.com 字体报错问题解决。
更多内容推荐微信公众号,欢迎关注: 无法加载这些字体是因为,google的网站在国内无法访问造成的.在AdminLTE.css 和AdminLte.less中有如下内容: @import url(ht ...
- 数位DP入门(A - 不要62 HDU - 2089 &&B - Bomb HDU - 3555 )
题目链接:https://cn.vjudge.net/contest/278036#problem/A 具体思路:对于给定的数,我们按照位数进行运算,枚举每一位上可能的数,在枚举的时候需要注意几个条件 ...
- java 判断上传文件大小
/** * 判断文件大小 * * @param file * 文件 * @param size * 限制大小 * @param unit * 限制单位(B,K,M,G) * @return */ pu ...
- C 数据结构堆
引言 - 数据结构堆 堆结构都很耳熟, 从堆排序到优先级队列, 我们总会看见它的身影. 相关的资料太多了, 堆 - https://zh.wikipedia.org/wiki/%E5%A0%86%E7 ...
- Python的日志记录-logging模块的使用
一.日志 1.1什么是日志 日志是跟踪软件运行时所发生的事件的一种方法,软件开发者在代码中调用日志函数,表明发生了特定的事件,事件由描述性消息描述,同时还包含事件的重要性,重要性也称为级别或严重性. ...