harris角点检测
#include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <imgproc/imgproc.hpp> using namespace std; using namespace cv; #define WINDOW_NAME1 "【程序窗口1】" #define WINDOW_NAME2 "【程序窗口2】" Mat g_srcImage, g_srcImage1, g_grayImage; int thresh = 30; int max_thresh = 175; void on_CornerHarris(int, void*) { Mat dstImage; Mat normImage; Mat scaledImage; dstImage = Mat::zeros(g_srcImage.size(), CV_32FC1); g_srcImage1 = g_srcImage.clone(); //进行角点检测 cornerHarris(g_grayImage, dstImage, 2, 3, 0.04, BORDER_DEFAULT); //归一化与转换 normalize(dstImage, normImage, 0, 255, NORM_MINMAX, CV_32FC1); convertScaleAbs(normImage, scaledImage); for (int j = 0; j < normImage.rows; j++) { for (int i = 0; i<normImage.cols; i++) { if ((int)normImage.at<float>(j, i)>thresh + 80) { circle(g_srcImage1, Point(i, j), 5, Scalar(10, 10, 255), 2, 8, 0); circle(scaledImage, Point(i, j), 5, Scalar(0, 10, 255), 2, 8, 0); } } } imshow(WINDOW_NAME1, g_srcImage1); imshow(WINDOW_NAME2, scaledImage); } int main() { g_srcImage = imread("../../sources/goal_3.png"); if (!g_srcImage.data) return -1; imshow("g_srcImage", g_srcImage); g_srcImage1 = g_srcImage.clone(); cvtColor(g_srcImage1, g_grayImage, COLOR_BGR2GRAY); namedWindow(WINDOW_NAME1, WINDOW_AUTOSIZE); createTrackbar("阈值:", WINDOW_NAME1, &thresh, max_thresh, on_CornerHarris); on_CornerHarris(0, 0); waitKey(0); return 0; }
效果如下:
相关推荐
BeanJoy 2020-07-28
Codeeror 2020-04-27
me 2019-06-28
ouyangandy 2019-06-28
opencvfw 2019-06-28
csdmeb 2018-05-08
cangyue000 2015-03-07
qizongshuai 2015-03-07
太空小孩 2017-12-25