Ubuntu下opencv3.3和opencv_contrib的编译安装
来源:互联网 发布:3.3v的单片机 编辑:程序博客网 时间:2024/06/05 04:48
文件准备
1.opencv-3.3.1.zip
2. opencv_contrib-3.3.1.zip
准备
先安装以下依赖包
sudo apt-get install build-essential sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev sudo apt-get install pkg-config
编译
1.解压下载好的包:
unzip opencv-3.3.1.zipunzip opencv_contrib-3.3.1.zip
2.解压完后需要将opencv_contrib.zip提取到opencv目录下,同时在该目录下新建一个文件夹build:
cp -r opencv_contrib-3.3.1 opencv-3.3.1 #复制opencv_contrib到opencv目录下cd opencv-3.3.1mkdir build #新建文件夹build
3.现在进入到opencv-3.3.1目录下,查看文件结构:
#ls3rdparty cmake data LICENSE platformsapps CMakeLists.txt doc modules README.mdbuild CONTRIBUTING.md include opencv_contrib-3.3.1 samples
4.进入build目录,并且执行cmake生成makefile文件:
cd build cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_EXTRA_MODULES_PATH=/home/files/opencv-3.3.1/opencv_contrib-3.3.1/modules/ ..
注意:OPENCV_EXTRA_MODULES_PATH就是你 opencv_contrib-3.3.1下面的modules目录,请按照自己的实际目录修改地址。还有后面的两点不可省略!!
接下来就是漫长的等待了…
生成完毕提示:
-- Install path: /usr/local-- -- cvconfig.h is in: /home/files/opencv-3.3.1/build-- ------------------------------------------------------------------- -- Configuring done-- Generating done-- Build files have been written to: /home/files/opencv-3.3.1/build
5.在cmake成功之后,就可以在build文件下make了:
make -j8 #8线程编译make install
接下来就是更漫长的等待了……具体时间因人而异,我的电脑跑了20分钟。如果看到下图,说明成功了,再make install
就ok了!
6.链接库共享
编译安装完毕之后,为了让你的链接库被系统共享,让编译器发现,需要执行管理命令ldconfig:
sudo ldconfig -v
问题
Ubuntu16.04会报错:
Scanning dependencies of target opencv_test_superres//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFReadDirectory@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFGetFieldDefaulted@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFNumberOfDirectories@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFIsTiled@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFOpen@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFDefaultStripSize@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFReadRGBAImage@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFReadTile@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFSetField@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFWriteScanline@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `_TIFFfree@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFGetField@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFScanlineSize@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFSetWarningHandler@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFTileSize@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `_TIFFmalloc@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFSetErrorHandler@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFSetDirectory@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFReadScanline@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFClose@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFNumberOfTiles@LIBTIFF_4.0'//usr/lib/x86_64-linux-gnu/libvtkIOImage-6.2.so.6.2: undefined reference to `TIFFClientOpen@LIBTIFF_4.0'[ 74%] Building CXX object modules/imgcodecs/CMakeFiles/opencv_perf_imgcodecs.dir/perf/perf_main.cpp.o[ 74%] Building CXX object modules/shape/CMakeFiles/opencv_test_shape.dir/test/test_main.cpp.o[ 74%] Building CXX object modules/highgui/CMakeFiles/opencv_test_highgui.dir/test/test_main.cpp.o[ 75%] Building CXX object modules/superres/CMakeFiles/opencv_test_superres.dir/test/test_main.cpp.o[ 75%] Building CXX object modules/videoio/CMakeFiles/opencv_perf_videoio.dir/perf/perf_main.cpp.o[ 75%] Building CXX object modules/videoio/CMakeFiles/opencv_test_videoio.dir/test/test_main.cpp.ocollect2: error: ld returned 1 exit statusmodules/viz/CMakeFiles/opencv_test_viz.dir/build.make:233: recipe for target 'bin/opencv_test_viz' failedmake[2]: *** [bin/opencv_test_viz] Error 1CMakeFiles/Makefile2:5627: recipe for target 'modules/viz/CMakeFiles/opencv_test_viz.dir/all' failedmake[1]: *** [modules/viz/CMakeFiles/opencv_test_viz.dir/all] Error 2make[1]: *** Waiting for unfinished jobs...
解决方法:
sudo apt-get autoremove libtiff5-devsudo apt-get install libtiff5-dev
例子
接下来你就可以在Clion开始写你的Opencv程序了,示例: Clion下第一个opencv3程序 ,记得在Cmakelists.txt上多花点功夫写对。
下面这个例子能跑,证明你上面环境配置完全正确!
/*** @概述:采用FAST算子检测特征点,采用SIFT算子对特征点进行特征提取,并使用BruteForce匹配法进行特征点的匹配* @类和函数:FastFeatureDetector + SiftDescriptorExtractor + BruteForceMatcher*/#include<opencv2/opencv.hpp>#include <opencv2/xfeatures2d.hpp>using namespace std;using namespace cv;using namespace cv::xfeatures2d;int main(int argc, char** argv){ Mat objImage = imread("1.jpg", IMREAD_COLOR); Mat sceneImage = imread("2.jpg", IMREAD_COLOR); //-- Step 1: Detect the keypoints using SURF Detector int minHessian = 400; Ptr<SURF> detector = SURF::create(minHessian); std::vector<KeyPoint> obj_keypoint, scene_keypoint; detector->detect(objImage, obj_keypoint); detector->detect(sceneImage, scene_keypoint); //computer the descriptors Mat obj_descriptors, scene_descriptors; detector->compute(objImage, obj_keypoint, obj_descriptors); detector->compute(sceneImage, scene_keypoint, scene_descriptors); //use BruteForce to match,and get good_matches BFMatcher matcher; vector<DMatch> matches; matcher.match(obj_descriptors, scene_descriptors, matches); sort(matches.begin(), matches.end()); //筛选匹配点 vector<DMatch> good_matches; for (int i = 0; i < min(50, (int)(matches.size()*0.15)); i++) { good_matches.push_back(matches[i]); } //draw matches Mat imgMatches; drawMatches(objImage, obj_keypoint, sceneImage, scene_keypoint,good_matches, imgMatches); //get obj bounding vector<Point2f> obj_good_keypoint; vector<Point2f> scene_good_keypoint; for (int i = 0; i < good_matches.size(); i++) { obj_good_keypoint.push_back(obj_keypoint[good_matches[i].queryIdx].pt); scene_good_keypoint.push_back(scene_keypoint[good_matches[i].trainIdx].pt); } vector<Point2f> obj_box(4); vector<Point2f> scene_box(4); obj_box[0] = Point(0, 0); obj_box[1] = Point(objImage.cols, 0); obj_box[2] = Point(objImage.cols, objImage.rows); obj_box[3] = Point(0, objImage.rows); Mat H = findHomography(obj_good_keypoint, scene_good_keypoint, RANSAC); //find the perspective transformation between the source and the destination perspectiveTransform(obj_box, scene_box, H); line(imgMatches, scene_box[0]+Point2f((float)objImage.cols, 0), scene_box[1] + Point2f((float)objImage.cols, 0), Scalar(0, 255, 0), 2); line(imgMatches, scene_box[1] + Point2f((float)objImage.cols, 0), scene_box[2] + Point2f((float)objImage.cols, 0), Scalar(0, 255, 0), 2); line(imgMatches, scene_box[2] + Point2f((float)objImage.cols, 0), scene_box[3] + Point2f((float)objImage.cols, 0), Scalar(0, 255, 0), 2); line(imgMatches, scene_box[3] + Point2f((float)objImage.cols, 0), scene_box[0] + Point2f((float)objImage.cols, 0), Scalar(0, 255, 0), 2); //show the result imshow("匹配图", imgMatches); //save picture file imwrite("final.jpg",imgMatches); waitKey(0); return 0;}
上传1.jpg
和2.jpg
:
再传一张最后跑出的效果图:
阅读全文
0 0
- Ubuntu下opencv3.3和opencv_contrib的编译安装
- ubuntu16.04下opencv3.2和opencv_contrib编译安装
- window下编译Opencv3.1.0和opencv_contrib
- opencv3.3 opencv_contrib安装
- Windows环境下编译OpenCV3.1和OpenCV_contrib
- Windows环境下编译OpenCV3.1和OpenCV_contrib for vs2008
- Windows环境下编译OpenCV3.1和OpenCV_contrib
- Windows环境下使用CMake编译OpenCV3.0和OpenCV_contrib
- opencv3.3+opencv_contrib+vs2013编译
- 添加OpenCV_contrib库至OpenCV3.1.0中(Windows 64位 环境下编译OpenCV3.1.0和OpenCV_contrib)
- Opencv3+Opencv_contrib编译
- opencv3.2 在Ubuntu下的编译安装
- opencv3.x+opencv_contrib安装
- opencv3.2安装opencv_contrib
- opencv3.0+opencv_contrib安装
- OpenCV3及opencv_contrib安装
- opencv3.3+opencv_contrib-3.3编译及在eclipse下使用opencv
- windows下cmake编译opencv3.2+opencv_contrib完整过程
- android长连接心跳机制
- windows下创建/删除文件夹(C/C++ python Matlab)
- iOS 数组~把创建的字典添加到数组中
- assert定义和用法
- shell命令-dd
- Ubuntu下opencv3.3和opencv_contrib的编译安装
- 大数据和云计算技术周报(第3期)
- ORACLE追踪应用执行sql语句——10046事件
- Toast执行完makeText之后的代码不执行(子线程中调用Toast显示异常分析)
- OSI七层模型详解(物理层、数据链路层、网络层、传输层.....应用层协议与硬件)
- 大数据人才发展报告:招聘猛增6倍,均薪达38万
- sentos7 zookeeper 单机,集群搭建
- NoSQL 还是 SQL ?这一篇讲清楚
- VS2013设置行号