主要参考:

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.

  1. Remove any installed versions of ffmpeg and x264.

    sudo apt-get remove ffmpeg x264 libx264-dev

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

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

  4. Download and install gtk.

    sudo apt-get install libgtk2.0-0 libgtk2.0-dev

  5. Download and install libjpeg.

    sudo apt-get install libjpeg8 libjpeg8-dev

  6. Create a directory to hold source code.

    cd ~
    mkdir src

  7. Download and install install x264.
    1. 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

    2. Configure and build the x264 libraries.

      ./configure --enable-static
      make
      sudo make install

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

  8. Download and install install ffmpeg.
    1. 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

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

      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.

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

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

  10. Download and install install OpenCV 2.4.2.
    1. 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

    2. Create a new build directory and run cmake:

      cd OpenCV-2.4.2/
      mkdir build
      cd build
      cmake -D CMAKE_BUILD_TYPE=RELEASE ..

    3. 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
    4. Build and install OpenCV.

      make
      sudo make install

  11. Configure Linux.
    1. 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

      .

    2. 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();
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

Ubuntu下编译安装OpenCV 2.4.7并读取摄像头的更多相关文章

  1. Ubuntu下编译安装OpenCV 2.4.7并读取摄像头[转]

    主要参考: 1.http://www.ozbotz.org/opencv-installation/ 2.http://www.ozbotz.org/opencv-install-troublesho ...

  2. Ubuntu下编译安装postgreSQL 10.5

    Ubuntu下编译安装postgreSQL 10.5 ubuntu 16.04 LTS系统postgreSQL 10.5 安装包准备 1.从PostgreSQL官网下载PostgreSQL的安装包 安 ...

  3. 在Ubuntu下编译安装GreatSQL

    在Ubuntu下编译安装GreatSQL 本次介绍如何利用Docker构建Ubuntu环境,并将GreatSQL源码编译成二进制文件. 1.准备工作 先创建本次Docker的workdir为 /dat ...

  4. 在Ubuntu 16.04 LTS下编译安装OpenCV 4.1.1

    目录 一 安装前的准备 二 编译并安装OpenCV 4.1.1 注:原创不易,转载请务必注明原作者和出处,感谢支持! OpenCV目前(2019-8-1)的最新版本为4.1.1.本文将介绍如何在Ubu ...

  5. ubuntu下编译安装poco

    系统环境: ubuntu版本:Linux jfcai-VirtualBox 4.15.0-29-generic #31-Ubuntu SMP Tue Jul 17 15:39:52 UTC 2018 ...

  6. Linux 下编译安装OpenCV【转】

    转自:http://www.cnblogs.com/emouse/archive/2013/02/22/2922940.html OpenCV 2.2以后版本需要使用Cmake生成makefile文件 ...

  7. Ubuntu下编译C++ OpenCV程序并运行

            因为想试跑yolov3的缘故,所以装了ubuntu系统,直接通过U盘装的,并不像他们说的“折腾”,反而一切非常顺利,比装软件还简单.然后就是要用C++跑opencv的程序用于比赛,出于 ...

  8. Linux 下编译安装OpenCV(zhuanzai)

    http://www.cnblogs.com/emouse/archive/2013/02/22/2922940.html Cmake的安装 OpenCV 2.2以后版本需要使用Cmake生成make ...

  9. ubuntu系统编译安装OpenCV 4.4

    内容转载自我的博客 目录 前言 1. 下载源码 2. 安装各种依赖 3. 开始编译安装 4. 配置C++开发环境 5. 程序执行时加载动态库*.so 6. 测试cpp文件 7. 配置python3的o ...

随机推荐

  1. arcgis求邻接矩阵

    求邻接矩阵 教程链接   http://m.blog.csdn.net/wan_yanyan528/article/details/49175673 (1) 将目标shp文件导出一份副本备用(以省级为 ...

  2. string 中的一些优化事项

    1.1 fmt  vs  "+" (无转义) import ( "testing" "fmt" ) var ( str = "he ...

  3. uboot常用命令详解

    dnw:在进入系统之前进入指令行,输入该指令可下载烧录文件. re:重新启动嵌入式系统. printenv:打印当前系统环境变量. setenv:设置环境变量,格式:setenv name value ...

  4. 关于Python运行代码报错:SyntaxError: Non-ASCII character '\xe5' in file的解决方法

    运行python文件报错如上 解决办法: # -*- coding: UTF- -*- 或者 #coding=utf- (注:此语句一定要添加在源代码的第一行) 原因:Python默认是以ASCII作 ...

  5. [洛谷P2444] [POI2000]病毒

    洛谷题目链接:[POI2000]病毒 题目描述 二进制病毒审查委员会最近发现了如下的规律:某些确定的二进制串是病毒的代码.如果某段代码中不存在任何一段病毒代码,那么我们就称这段代码是安全的.现在委员会 ...

  6. 【leetcode 简单】 第五十六题 快乐数

    编写一个算法来判断一个数是不是“快乐数”. 一个“快乐数”定义为:对于一个正整数,每一次将该数替换为它每个位置上的数字的平方和,然后重复这个过程直到这个数变为 1,也可能是无限循环但始终变不到 1.如 ...

  7. Xor Sum(HDU4825 + 字典树)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4825 题目: 题意: 先给你n个数,再进行q次查询,每次查询数s与原来给的n个数异或和最大的数. 思 ...

  8. 【转】WireShark 过滤规则

    原链:[渗透神器系列]WireShark wireshark是一款网络流量抓取分析神器,也是安全工具使用排行中排名第一的工具.使用wireshark必须要牢记一些常用的数据包过滤规则,对于寻找一些特定 ...

  9. 33、Map简介

    Map接口概述 除了Collection之外,常用的集合还有Map接口,里面常用的实现类图如下: map中的元素是以键-值的方式存在的,通过键可以获取到值,键是不可以重复的,跟地图比较像,通过一个坐标 ...

  10. 面试:----Nginx的一理解

    1.静态HTTP服务器 首先,Nginx是一个HTTP服务器,可以将服务器上的静态文件(如HTML.图片)通过HTTP协议展现给客户端. 配置: 2.反向代理服务器 什么是反向代理? 客户端本来可以直 ...