cvGoodFeaturesToTrack()与goodFeaturesToTrack()进行harris角点检测

1、角点检测函数和参数说明

cvGoodFeaturesToTrack()函数主要是处理IplImage数据格式的图像,而goodFeaturesToTrack()函数主要是处理Mat数据格式的图像。参数quality_level :特征值最大值最小值乘法因子;参数minDistance:角点之间最小距离;均对图像中harris角点检测的个数有影响。

2、具体代码如下

(1)harris角点检测

#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"

#include 
#include 
using namespace std;
using namespace cv;

int main()
{
	//FILE* fp=fopen("E:\\实验室项目\\ImagePro\\GoodFeatures\\result.txt","w+");
	//char* filename="E:\\实验室项目\\ImagePro\\GoodFeatures\\j10.jpg";
	IplImage* img=cvLoadImage("F22.jpg",CV_LOAD_IMAGE_COLOR);
	if (!img)
	{
		cout<<"读取图像失败!"<


(2)shi-Tomas角点检测

#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include 
#include 
#include 
//#include 

using namespace std;
using namespace cv;

Mat src,src_gray;

int maxCorners=1000;
int maxTrackbar=100;

RNG rng(12345);

char* source_window="Image";

void goodFeaturesToTrack_demo(int,void*);

int main()
{
	src=imread("F22.jpg",1);

	cvtColor(src,src_gray,CV_BGR2GRAY);
	namedWindow(source_window,CV_WINDOW_AUTOSIZE);
	createTrackbar("角点个数:",source_window,&maxCorners,maxTrackbar,goodFeaturesToTrack_demo);
	imshow(source_window,src);
	goodFeaturesToTrack_demo(0,0);

	waitKey(0);
	return 0;
}

void goodFeaturesToTrack_demo(int,void*)
{
	if (maxCorners<1)
	{
		maxCorners=1;
	}

	//Shi-Tomasi 角点算法参数定义
	vector corners;
	double qualityLevel=0.01;//最大最小特征值乘法因子
	double minDistance=10;//角点之间最小距离
	int blockSize=3;
	bool useHarrisDetector=false;
	double k=0.04;


	Mat copy;
	copy=src.clone();

	goodFeaturesToTrack(src_gray,corners,maxCorners,qualityLevel,minDistance,Mat(),blockSize,useHarrisDetector,k);
	
	cout<<"检测到角点数:"<
测试结果:
cvGoodFeaturesToTrack()与goodFeaturesToTrack()进行harris角点检测_第1张图片


题目: Shi-Tomasi角点检测子


你可能感兴趣的:(Opencv学习笔记)