首页 > 代码库 > Ubuntu 安装OpenCV3.0.0

Ubuntu 安装OpenCV3.0.0

 Ubuntu  安装OpenCV3.0.0

为了看看opencv3.0的HDR效果,尝试安装opencv3.0到ubuntu12.04上面,安装了好几次终于成功了。

参考博客:
http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/

http://blog.163.com/huai_jing@126/blog/static/171861983201311103411229

http://www.cnblogs.com/steven-blog/archive/2013/04/27/3046357.html

http://www.cnblogs.com/emouse/archive/2013/02/22/2922940.html

http://blog.sina.com.cn/s/blog_8835a8480100x23h.html


安装过程出现问题解决方法
http://blog.sina.com.cn/s/blog_675e6b570101gpsj.html

卸载方法 OpenCv卸载

http://stackoverflow.com/questions/13134151/how-to-uninstall-opencv-in-ubuntu

You can also uninstall by going to the "build" folder directory of opencv from terminal, and execute the following
make uninstall
cd ..
sudo rm -r build


sudo rm -r /usr/local/include/opencv2
/usr/local/include/opencv
/usr/include/opencv
/usr/include/opencv2
/usr/local/share/opencv
/usr/local/share/OpenCV
/usr/share/opencv
/usr/share/OpenCV
/usr/local/bin/opencv*
/usr/local/lib/libopencv*

install reference
http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/


OpenCV安装
1 系统更新
利用ubuntu自带的更新管理器或者
sudo apt-get update
sudo apt-get upgrade


2 安装必要的组件
sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake 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.0

http://opencv.org/downloads.html

解压到某个文件下,这里选择
/home/yourname/opencv3.0

4  编译opecv3.0
进入解压后的opencv3.0目录

mkdir build

进入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 ..

5 安装opencv3.0

在build目录
make
sudo make install

6 配置opencv.conf file ,加入环境变量
sudo gedit /etc/ld.so.conf.d/opencv.conf

在opencv.conf里面加入命令
/usr/local/lib

更新库目录
sudo ldconfig

打开文件bash.bashrc
sudo gedit /etc/bash.bashrc
加入下面两行
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH



7 测试你的opencv3.0是否安装成功

编译不通过请注销或者重启电脑试试

测试代码:opencvtest.cpp

[cpp] view plaincopy技术分享技术分享
  1. #include <opencv2/core/core.hpp>  
  2. #include <opencv2/highgui/highgui.hpp>  
  3. using namespace cv;  
  4.   
  5. int main()  
  6. {  
  7.     Mat src = imread("test.jpg",1);  
  8.     imshow("src",src);  
  9.     waitKey(0);  
  10.     return 0;  
  11. }  




注意:linux下面的目录形式为/.../....

所以“#include <opencv2\core\core.hpp>” 会找不到头文件

编译方式:
1 命令行
g++  opencvtest.cpp -o opencvtest  `pkg-config  --cflags --libs opencv`

2 借助cmake,写CMakeLists.txt

cmake_minimum_required(VERSION 2.8)

project(opencvtest)

find_package( OpenCV REQUIRED )

add_executable( opencvtest opencvtest.cpp )

target_link_libraries( opencvtest ${OpenCV_LIBS} )

之后 执行

cmake .
Make
 运行
./ opencvtest


8 opnecv3.0的HDR效果测试

[cpp] view plaincopy技术分享技术分享
  1. #include <opencv2/photo.hpp>  
  2. #include "opencv2/imgcodecs.hpp"  
  3. #include <opencv2/highgui.hpp>  
  4. #include <vector>  
  5. #include <iostream>  
  6. #include <fstream>  
  7. #include <string>  
  8.   
  9. using namespace cv;  
  10. using namespace std;  
  11.   
  12. void loadExposureSeq(string, vector<Mat>&, vector<float>&);  
  13.   
  14. int main(int, char**argv)  
  15.   
  16. {  
  17.   
  18.     vector<Mat> images;  
  19.     vector<float> times;  
  20.     string strpath = "./SampleLighthouse";  
  21.     loadExposureSeq(strpath, images, times);  
  22.   
  23.     for (int i = 0; i < times.size(); ++i)  
  24.     {  
  25.         cout << times[i] << " ";  
  26.     }  
  27.     cout << endl << "here" << endl;  
  28.   
  29.     Mat response;  
  30.     Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();  
  31.     calibrate->process(images, response, times);  
  32.     Mat hdr;  
  33.     Ptr<MergeDebevec> merge_debevec = createMergeDebevec();  
  34.     merge_debevec->process(images, hdr, times, response);  
  35.     Mat ldr;  
  36.     Ptr<TonemapDurand> tonemap = createTonemapDurand(2.2f);  
  37.     tonemap->process(hdr, ldr);  
  38.   
  39.     Mat fusion;  
  40.     Ptr<MergeMertens> merge_mertens = createMergeMertens();  
  41.     merge_mertens->process(images, fusion);  
  42.   
  43.     imwrite("fusion.png", fusion * 255);  
  44.     imwrite("ldr.png", ldr * 255);  
  45.     imwrite("hdr.hdr", hdr);  
  46.     return 0;  
  47. }  
  48.   
  49.   
  50.   
  51. void loadExposureSeq(string path, vector<Mat>& images, vector<float>& times)  
  52. {  
  53.   
  54.     path = path + std::string("/");  
  55.     ifstream list_file((path + "ST.txt").c_str());  
  56.     string name;  
  57.     float val;  
  58.     while(list_file >> name >> val) {  
  59.         Mat img = imread(path + name);  
  60.         images.push_back(img);  
  61.         times.push_back(1 / val);  
  62.     }  
  63.     list_file.close();  
  64. }  


曝光时间 ST.txt
s1.jpg 40.0
s2.jpg 10.0
s3.jpg 2.0

技术分享


技术分享


技术分享

HDR图片

在普通的显示中无法正常显示,就不给出了

LDR图片
技术分享

色调映射算法感觉不好,图像的很多细节丢失了。

Ubuntu 安装OpenCV3.0.0