首页 > 代码库 > 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
- #include <opencv2/core/core.hpp>
- #include <opencv2/highgui/highgui.hpp>
- using namespace cv;
- int main()
- {
- Mat src = imread("test.jpg",1);
- imshow("src",src);
- waitKey(0);
- return 0;
- }
注意: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效果测试
- #include <opencv2/photo.hpp>
- #include "opencv2/imgcodecs.hpp"
- #include <opencv2/highgui.hpp>
- #include <vector>
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace cv;
- using namespace std;
- void loadExposureSeq(string, vector<Mat>&, vector<float>&);
- int main(int, char**argv)
- {
- vector<Mat> images;
- vector<float> times;
- string strpath = "./SampleLighthouse";
- loadExposureSeq(strpath, images, times);
- for (int i = 0; i < times.size(); ++i)
- {
- cout << times[i] << " ";
- }
- cout << endl << "here" << endl;
- Mat response;
- Ptr<CalibrateDebevec> calibrate = createCalibrateDebevec();
- calibrate->process(images, response, times);
- Mat hdr;
- Ptr<MergeDebevec> merge_debevec = createMergeDebevec();
- merge_debevec->process(images, hdr, times, response);
- Mat ldr;
- Ptr<TonemapDurand> tonemap = createTonemapDurand(2.2f);
- tonemap->process(hdr, ldr);
- Mat fusion;
- Ptr<MergeMertens> merge_mertens = createMergeMertens();
- merge_mertens->process(images, fusion);
- imwrite("fusion.png", fusion * 255);
- imwrite("ldr.png", ldr * 255);
- imwrite("hdr.hdr", hdr);
- return 0;
- }
- void loadExposureSeq(string path, vector<Mat>& images, vector<float>& times)
- {
- path = path + std::string("/");
- ifstream list_file((path + "ST.txt").c_str());
- string name;
- float val;
- while(list_file >> name >> val) {
- Mat img = imread(path + name);
- images.push_back(img);
- times.push_back(1 / val);
- }
- list_file.close();
- }
曝光时间 ST.txt
s1.jpg 40.0
s2.jpg 10.0
s3.jpg 2.0
HDR图片
在普通的显示中无法正常显示,就不给出了
LDR图片
色调映射算法感觉不好,图像的很多细节丢失了。
Ubuntu 安装OpenCV3.0.0