opencv学习之Shi-Tomasi角点检测

// opencv2413_test.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include 
#include 
#include 

using namespace cv;
using namespace std;

Mat g_srcImage, g_grayImage;
int g_maxCornerNumber = 33;
int g_maxTrackbarNumber = 500;
RNG g_rng(12345);

void on_GoodFeatureToTrack(int, void*);

int main()
{
	g_srcImage = imread("E:\\pictures\\For_Project\\Opencv_Test\\te.jpg");
	cvtColor(g_srcImage, g_grayImage, COLOR_BGR2GRAY);

	namedWindow("Shi_Tomasi角点检测", WINDOW_AUTOSIZE);

	createTrackbar("最大角点数量", "Shi_Tomasi角点检测", 
		&g_maxCornerNumber, g_maxTrackbarNumber, on_GoodFeatureToTrack);
	imshow("Shi_Tomasi角点检测", g_srcImage);
	on_GoodFeatureToTrack(0, 0);

	waitKey();
	return 0;
}

void on_GoodFeatureToTrack(int, void*) {
	//对变量小于等于1进行处理
	if (g_maxCornerNumber <= 1) {
		g_maxCornerNumber = 1;
	}

	vector corners;
	//角点检测可接受的最小特征值
	double qualityLevel = 0.01;
	//角点之间的最小距离
	double minDistance = 10;
	//计算导数自相关矩阵时指定的领域范围
	int blockSize = 3;
	double k = 0.04;
	Mat copy = g_srcImage.clone();

	goodFeaturesToTrack(g_grayImage, corners, g_maxCornerNumber, qualityLevel, 
		minDistance, Mat(), blockSize, false, k);

	cout << "此次检测到的角点数量为:" << corners.size() << endl;

	int r = 4;
	for (unsigned int i = 0; i < corners.size(); i++) {
		circle(copy, corners[i], r, Scalar(g_rng.uniform(0, 255), 
			g_rng.uniform(0, 255), g_rng.uniform(0, 255)), -1, 8, 0);
	}
	imshow("Shi_Tomasi角点检测", copy);
}

你可能感兴趣的:(opencv学习之Shi-Tomasi角点检测)