历时一个多月,于今天上午终于将项目交上去了,这期间虽很辛苦,但是成长了不少,在此将项目中涉及到的知识点进行整理,本文主要介绍图像的角点检测:
一、代码部分:
// 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);
}
二、检测效果图:
您可能感兴趣的文章:OpenCV实现图像轮廓检测以及外接矩形OpenCV实现图像的直线检测OpenCV实现图像边缘检测OpenCV利用霍夫变换进行直线检测opencv检测直线方法之形态学方法opencv检测直线方法之投影法利用Opencv中Houghline方法实现直线检测10个步骤Opencv轻松检测出图片中条形码使用OpenCV实现检测和追踪车辆opencv实现图片与视频中人脸检测功能