历时一个多月,于今天上午终于将项目交上去了,这期间虽很辛苦,但是成长了不少,在此将项目中涉及到的知识点进行整理,本文主要介绍图像的角点检测:
一、代码部分:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// Detect_Corners.cpp : 定义控制台应用程序的入口点。 // #include "stdafx.h" #include "opencv2/opencv.hpp" #include <opencv2/imgproc/imgproc.hpp> #include <iostream> #include "opencv2/highgui/highgui.hpp" #include <stdio.h> #include <stdlib.h> using namespace std; using namespace cv; //全局变量 Mat src, src_gray; int thresh = 200; int max_thresh = 255; char * source_window = "Source image" ; //char* corners_window = "Corners detected"; //函数声明 void cornerHarris_demo( int , void *); int _tmain( int argc, _TCHAR* argv[]) { //Load source image and convert it to gray char *img_name= "..\\image\\71254.png" ; src=imread(img_name); imshow(source_window,src); cvtColor(src, src_gray, CV_BGR2GRAY); createTrackbar( "Threshold: " , source_window, &thresh, max_thresh, cornerHarris_demo); waitKey(0); //角点检测 cornerHarris_demo(0,0); return 0; } /** 函数 cornerHarris_demo */ void cornerHarris_demo( int , void *) { Mat dst, dst_norm,dst_norm_scaled; dst = Mat::zeros(src.size(), CV_32FC1 ); // Detector parameters int blockSize = 2; int apertureSize = 3; double k = 0.04; // Detecting corners cornerHarris( src_gray, dst, blockSize, apertureSize, k, BORDER_DEFAULT ); // Normalizing normalize( dst, dst_norm, 0, 255, NORM_MINMAX, CV_32FC1, Mat() ); convertScaleAbs( dst_norm, dst_norm_scaled ); // Drawing a circle around corners for ( int j = 0; j < dst_norm.rows ; j++ ) { for ( int i = 0; i < dst_norm.cols; i++ ) { if ( ( int ) dst_norm.at< float >(j,i) > thresh ) { circle( dst_norm_scaled, Point(i, j), 5, Scalar(0), 2, 8, 0 ); circle(src,Point( i, j ), 5, Scalar(255,0,0), -1, 8, 0 ); } } } // Showing the result imshow( source_window, src); } |
二、检测效果图:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/lindamtd/article/details/75201830