goodFeaturesToTrack 算子
goodFeaturesToTrack(src,corners,maxCorners,quality_level,min_distance,Mat(),block_size,use_harris,k);
1.src:输入图像,输入的图像必须是8位或32位单通道图像
2.corners:输出的角点使用vector<Point2f>存储
3.maxCorners:最大角点数目,也就是corners集合中能存放的最大交点数,也就是最强的前corners个角点
4.quality_level:质量水平系数,是0.01~1之间的系数,其中系数越大检测到的角点就越少,反之亦然
5.min_distance:角点之间的最小距离,小于此距离的角点会被忽略,距离越大有可能检测到的角点就越少
6.Mat()掩码,mask=0忽略,基础用法忽略即可
7.block_size:Sobel算子,使用的邻域,四邻域,八邻域等 3,5,7
9.user_harris:是否使用harris检测,true是,false否
10.k:harris角点检测时使用一般为0.04,user_harris=false时此参数会被忽略
示例
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int num_corners = 25;
int max_corners = 200;
const char* output_title = "ShiTomasi Detector";
void ShiTomasi_Demo(int, void*);
Mat src, gray_src;
RNG rng(12345);
int main(int argc, char** argv) {
src = imread("D:/vcprojects/images/home.jpg");
if (src.empty()) {
printf("could not load image...\n");
return -1;
}
namedWindow("input image", CV_WINDOW_AUTOSIZE);
imshow("input image", src);
cvtColor(src, gray_src, COLOR_BGR2GRAY);
namedWindow(output_title, CV_WINDOW_AUTOSIZE);
createTrackbar("Num Corners:", output_title, &num_corners, max_corners, ShiTomasi_Demo);
ShiTomasi_Demo(0, 0);
waitKey(0);
return 0;
}
void ShiTomasi_Demo(int, void*) {
if (num_corners < 5) {
num_corners = 5;
}
vector<Point2f> corners;
double qualityLevel = 0.01;
double minDistance = 10;
int blockSize = 3;
bool useHarris = false;
double k = 0.04;
Mat resultImg = gray_src.clone();
cvtColor(resultImg, resultImg, COLOR_GRAY2BGR);
goodFeaturesToTrack(gray_src, corners, num_corners, qualityLevel, minDistance, Mat(), blockSize, useHarris, k);
printf("Number of Detected Corners: %d\n", corners.size());
for (size_t t = 0; t < corners.size(); t++) {
circle(resultImg, corners[t], 2, Scalar(rng.uniform(0, 255), rng.uniform(0, 255), rng.uniform(0, 255)), 2, 8, 0);
}
imshow(output_title, resultImg);
}