【OpenCV】OpenCV 3.1.0 + opencv_contrib编译(Windows)


OpenCV学习笔记(八)—— OpenCV 3.1.0 + opencv_contrib编译(Windows)

OpenCV3编程入门——学习笔记番外篇之目标跟踪object tracking

Opencv3.1.0+opencv_contrib配置及使用SIFT测试


由于在学习图像识别中的特征点检测中,需要用到Surf和Sift算法,但是这两个算法在OpenCV 3.1.0的Release版本中并不存在,因为他们是存放在opencv_contrib目录下面的未稳定功能模块,所以如果我们想要使用这个目录的功能,就需要自己重新进行OpenCV的编译。


一、准备工作:

1.下载OpenCV安装包:https://sourceforge.net/projects/opencvlibrary/files/opencv-win/3.0.0/

        安装过程实际上就是解压过程,安装完成后得到:

        

2.下载opencv_contrib源码:https://github.com/Itseez/opencv_contrib

        下载之后直接解压,得到源码目录:

        

3.下载cmake-gui工具:http://www.cmake.org/cmake/resources/software.html

 

        下载完成后,直接解压即可使用,不必安装。


二、使用cmake生成OpenCV.sln:

1.打开cmake-gui\bin目录下的cmake-gui.exe工具:

   

2.填写相应参数,包括:OpenCV源码目录OpenCV.sln工程的导出目录,开始导出OpenCV.sln工程:

    

    第一次导出时需要设置后面用来编译此OpenCV.sln工程的VS的版本,这里我用的是VS 2015:

    

    设置完成之后点击“Generate”开始生成工程:

    

3.第一次编译完成之后,我们需要将额外的opencv_contrib加到工程中进行第二次编译,在配置表中找到“OPENCV_EXTRA_MODULES_PATH”,设置其参数值为open_contrib源码包中的modles目录,我的目录是“E:\OpenCV\tools\opencv_contrib-master\modules”:

    

    设置完成之后点击Configure进行配置,不报错的话就进行第二次编译:

    

    第二次编译一般很快就能完成:

    

    编译完成后,我们在资源管理器下查看上面设置的文件输出目录,发现目录下多出了很多文件,其实就是OpenCV.sln工程文件:

    


三、用VS打开OpenCV.sln工程,编译生成Debug和Release库:

1.用VS 2015打开OpenCV.sln工程,在解决方案中可以查看工程目录:

    

2.编译生成debug版本的库,记得在此之前要选择编译的平台信息,这就是编译生成debug版本和release版本的区别:

    

    在解决方案中选中工程,右键选择重新生成解决方案:

    

    

3.找到CMakeTargets中的INSTALL,然后右键选择“仅限于项目”-->“仅生成INSTALL”:

    

    然后,在工程目录下的install目录中,可以看到生成了一堆文件:

    


四、把新的库文件配置到到项目中:

  1. VC++目录-->包含目录,添加:
    D:\opencv3\opencv\mybuild\install\include

  2. VC++目录-->库目录,添加:
    D:\opencv3\opencv\mybuild\install\x86\vc12\lib
    D:\opencv3\opencv\mybuild\install\x86\vc12\staticlib

  3. 链接器-->输入-->附加依赖项,添加: (下面添加的release的版本,注意添加的库与编译选项要一致)

opencv_aruco310.lib
opencv_bgsegm310.lib
opencv_bioinspired310.lib
opencv_calib3d310.lib
opencv_ccalib310.lib
opencv_core310.lib
opencv_datasets310.lib
opencv_dnn310.lib
opencv_dpm310.lib
opencv_face310.lib
opencv_features2d310.lib
opencv_flann310.lib
opencv_fuzzy310.lib
opencv_highgui310.lib
opencv_imgcodecs310.lib
opencv_imgproc310.lib
opencv_line_descriptor310.lib
opencv_ml310.lib
opencv_objdetect310.lib
opencv_optflow310.lib
opencv_photo310.lib
opencv_plot310.lib
opencv_reg310.lib
opencv_rgbd310.lib
opencv_saliency310.lib
opencv_shape310.lib
opencv_stereo310.lib
opencv_stitching310.lib
opencv_structured_light310.lib
opencv_superres310.lib
opencv_surface_matching310.lib
opencv_text310.lib
opencv_tracking310.lib
opencv_ts310.lib
opencv_video310.lib
opencv_videoio310.lib
opencv_videostab310.lib
opencv_xfeatures2d310.lib
opencv_ximgproc310.lib
opencv_xobjdetect310.lib
opencv_xphoto310.lib
ippicvmt.lib


=========Debug=============

opencv_aruco310d.dll
opencv_bgsegm310d.dll
opencv_bioinspired310d.dll
opencv_calib3d310d.dll
opencv_ccalib310d.dll
opencv_core310d.dll
opencv_datasets310d.dll
opencv_dnn310d.dll
opencv_dpm310d.dll
opencv_face310d.dll
opencv_features2d310d.dll
opencv_flann310d.dll
opencv_fuzzy310d.dll
opencv_highgui310d.dll
opencv_imgcodecs310d.dll
opencv_imgproc310d.dll
opencv_line_descriptor310d.dll
opencv_ml310d.dll
opencv_objdetect310d.dll
opencv_optflow310d.dll
opencv_phase_unwrapping310d.dll
opencv_photo310d.dll
opencv_plot310d.dll
opencv_reg310d.dll
opencv_rgbd310d.dll
opencv_saliency310d.dll
opencv_shape310d.dll
opencv_stereo310d.dll
opencv_stitching310d.dll
opencv_structured_light310d.dll
opencv_superres310d.dll
opencv_surface_matching310d.dll
opencv_text310d.dll
opencv_tracking310d.dll
opencv_video310d.dll
opencv_videoio310d.dll
opencv_videostab310d.dll
opencv_xfeatures2d310d.dll
opencv_ximgproc310d.dll
opencv_xobjdetect310d.dll
opencv_xphoto310d.dll

4、关于imread的问题。如果图片名称是存在txt文档中,用readImageLists方法提取到list列表时,要特别注意txt文档的换行符必须是“UNIX 终束符 -LF"。否则读取到的文件名会多出"\r"字符,导致读取图像文件失败。


======================目标跟踪=======================================

// OpenCV3Contrib.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <opencv2/opencv.hpp>  //头文件
#include <opencv2/xfeatures2d.hpp>
#include <opencv2/core/utility.hpp>
#include <opencv2/tracking.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
#include <cstring>

using namespace cv;  //包含cv命名空间
using namespace std;


int _tmain(int argc, _TCHAR* argv[])
{
	Create SIFT class pointer
	//Ptr<Feature2D> f2d = xfeatures2d::SIFT::create();
	读入图片
	//Mat img_1 = imread("1.jpg");
	//Mat img_2 = imread("2.jpg");
	Detect the keypoints
	//vector<KeyPoint> keypoints_1, keypoints_2;
	//f2d->detect(img_1, keypoints_1);
	//f2d->detect(img_2, keypoints_2);
	Calculate descriptors (feature vectors)
	//Mat descriptors_1, descriptors_2;
	//f2d->compute(img_1, keypoints_1, descriptors_1);
	//f2d->compute(img_2, keypoints_2, descriptors_2);
	Matching descriptor vector using BFMatcher
	//BFMatcher matcher;
	//vector<DMatch> matches;
	//matcher.match(descriptors_1, descriptors_2, matches);
	绘制匹配出的关键点
	//Mat img_matches;
	//drawMatches(img_1, keypoints_1, img_2, keypoints_2, matches, img_matches);
	//imshow("【match图】", img_matches);
	等待任意按键按下
	//waitKey(0);

	// declares all required variables
	Rect2d roi;
	Mat frame;
	// create a tracker object
	Ptr<Tracker> tracker = Tracker::create("KCF");
	// set input video
	//  std::string video = argv[1];
	//VideoCapture cap("dount.avi");
	VideoCapture cap("Move.mpg");
	// get bounding box
	cap >> frame;
	roi = selectROI("tracker", frame);
	//quit if ROI was not selected
	if (roi.width == 0 || roi.height == 0)
		return 0;
	// initialize the tracker
	tracker->init(frame, roi);
	// perform the tracking process
	printf("Start the tracking process, press ESC to quit.\n");
	for (;;) {
		// get frame from the video
		cap >> frame;
		// stop the program if no more images
		if (frame.rows == 0 || frame.cols == 0)
			break;
		// update the tracking result
		tracker->update(frame, roi);
		// draw the tracked object
		rectangle(frame, roi, Scalar(255, 0, 0), 2, 1);
		// show image with the tracked object
		imshow("tracker", frame);
		//quit on ESC button
		if (waitKey(1) == 27)break;
	}
	return 0;
}



评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值