#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
Mat img1, img2, img3, img4, img5, img6, img_result, img_gray1, img_gray2, img_gray3, img_canny1, img_binary1, img_dist1, img_dist2, kernel_1, kernel_2, img_laplance, img_sharp;
char win1[] = "window1";
char win2[] = "window2";
char win3[] = "window3";
char win4[] = "window4";
char win5[] = "window5";
char win6[] = "window6";
char win7[] = "window7";
int thread_value = 60;
int max_value = 255;
RNG rng1(12345);
RNG rng2(1235);
int Demo_Shi_Tomasi();
void Demo_1(int, void*);
//Shi-Tomasi角点检测
int Demo_Shi_Tomasi()
{
namedWindow(win1, CV_WINDOW_AUTOSIZE);
//namedWindow(win2, CV_WINDOW_AUTOSIZE);
//namedWindow(win3, CV_WINDOW_AUTOSIZE);
img1 = imread("D://images//4//3.jpg");
//img2 = imread("D://images//1//p5_1.jpg");
if (img1.empty())
{
cout << "could not load image..." << endl;
return 0;
}
imshow(win1, img1);
cvtColor(img1, img2, CV_BGR2GRAY);
imshow(win2, img2);
createTrackbar("Track", win1, &thread_value, max_value, Demo_1);
Demo_1(0, 0);
return 0;
}
void Demo_1(int, void*)
{
if (thread_value<10)
{
thread_value = 10;
}
//img3 = Mat::zeros(img2.size(), CV_32FC1);
vector<Point2f> vec_points;
double qualityLevel = 0.01;
double minDistance = 10;
int blockSize = 2;
int kSize = 3;
double k = 0.04;
img4 = img1.clone();
goodFeaturesToTrack(img2, vec_points, thread_value, qualityLevel, minDistance, Mat(), blockSize, false,k);
for (size_t t=0;t<vec_points.size();t++)
{
Scalar color_1 = Scalar(rng1.uniform(0,255), rng1.uniform(0, 255), rng1.uniform(0, 255));
circle(img4, vec_points[t], 2, color_1, 2, 8, 0);
}
imshow(win4, img4);
}
int main()
{
Demo_Shi_Tomasi();
waitKey(0);
return 0;
}