Shi-Tomasi原理几乎和Harris一样的,只不过最后计算角点响应的公式发生了变化
变为 min(λ1,λ2)
这样计算会变得更简单
API
cv::goodFeaturesToTrack(
InputArray src, //默认灰度图像
OutputArray corners,
int maxCorners,
double qualityLevel,
double minDistance,
InputArray mask=noArray(),
int blocksize=3,
bool useHarriDector=false,
double k=0.04
)
Demo
#include"pch.h" #include<iostream> #include<opencv2/opencv.hpp> #include<math.h> using namespace std; using namespace cv; const char* output_title = "Shi-Tomasi-CornerDetection Reslut"; int thresh = 130; int max_count = 255; Mat src, gray_src; int num_corners = 25; int max_corners = 200; RNG rng(12345); void ShiTomasi_Demo(int, void*); int main(int argc, char** argv) { src = imread("1.jpg"); imshow("input img", src); namedWindow(output_title, CV_WINDOW_AUTOSIZE); cvtColor(src, gray_src, COLOR_BGR2GRAY); createTrackbar("Num Corners:", output_title, &num_corners, max_corners, ShiTomasi_Demo); ShiTomasi_Demo(0, 0); waitKey(); 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 = src.clone(); goodFeaturesToTrack(gray_src, corners, num_corners, qualityLevel, minDistance, Mat(), blockSize, useHarris, k); cout << "Number of corner :" << corners.size()<<endl; 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); }