热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在Ubuntu中安装并测试OpenCV

参照www.Micro_Studios.com的视频,在Ubuntu中成功安装了opencv,并且测试成功。现把具体的安装及测试过程整理出来࿰

参照www.Micro_Studios.com的视频,在Ubuntu中成功安装了opencv,并且测试成功。现把具体的安装及测试过程整理出来,适合刚刚在Linux中使用opencv的同学参考参考。


1. Install OpenCV in Ubuntu:

 

(1) Update the list of packagerepositories:

sudo apt-get update
sudo apt-get upgrade


(2) Remove previously installedFFMPEG and x264 libraries:

sudo apt-get remove ffmpeg x264-dev

(3)
Installthe necessary packages for compiling the OpenCV sources:

sudo apt-get install ocl-icd-libopencl1 build-essential checkinstall cmake pkg-config yasm libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils

(4) Make a directory to downloadand build OpenCV:

mkdir opencv
cd opencv


(5) Download the OpenCV sources forLinux, then unzip it:

wget -O opencv-2.4.10.zip http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.10/opencv-2.4.10.zip/download
unzip opencv-2.4.10.zip
cd opencv-2.4.10


(6) Create a directory to compileOpenCV sources:

mkdir build
cd build


(7) Building OpenCV sources withCMake and install:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON ..


(8) Make and install:

make
sudo make install
sudo sh -c 'echo"/usr/local/lib">/etc/ld.so.conf.d/opencv.conf'
sudo ldconfig
                     

(9) Restart the system for everythingto take effect:

sudo shutdown -r now


2. Test OpenCV in Ubuntu:

 

(1) Create a directory DisplayImagefor test project:

mkdir DisplayImage
cd DisplayImage


(2) Create DisplayImage.cpp and edit it:

gedit DisplayImage.cpp

Then edit the DisplayImage.cpp:

#include
#include
using namespace cv;int main(int argc, char** argv)
{if(argc!= 2){printf("usage:DisplayImage.out \n");return -1;}Mat image;image= imread(argv[1], 1); if(!image.data)
{printf("Noimage data\n");return -1;}namedWindow("DisplayImage",CV_WINDOW_AUTOSIZE);imshow("DisplayImage",image);waitKey(0);return 0;
}


(3) Create a CMake file:

gedit CMakeLists.txt

Then edit the CMakeLists.txt:

cmake_minimum_required(VERSION 2.8)
project(DisplayImage)
find_package(OpenCV REQUIRED)
add_executable(DisplayImage DisplayImage.cpp)
target_link_libraries(DisplayImage ${OpenCV_LIBS})



(4) Generate the executable file:

cmake .
make


(5) Execute it:

./DisplayImage lena.jpglena.jpg is the test image












推荐阅读
author-avatar
zulaka_208
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有