角点检测(corner detection)的源代码(需要OPENCV库的支持)

这是在 Ruadhan 提供的源代码基础上做了一些修改,可以检测图像中的角点。应用环境是:OPENCV BETA 4,VC6 编译运行通过。

运行文件下载地址:

http://www.assuredigit.com/program/corner.exe

==========
#include <stdio.h><br>#include "cv.h"<br>#include "highgui.h"<br>#define max_corners 100</stdio.h>

int main( int argc, char** argv )
{
int cornerCount=max_corners;
CvPoint2D32f corners[max_corners];
double qualityLevel;
double minDistance;
IplImage *srcImage = 0, *grayImage = 0, *corners1 = 0, *corners2 = 0;
int i;
CvScalar color = CV_RGB(255,0,0);
char* filename = argc == 2 ? argv[1] : (char*)"..//..//c//pic3.png";

cvNamedWindow( "image", 1 ); // create HighGUI window with name "image"

//Load the image to be processed
srcImage = cvLoadImage(filename,1);

grayImage = cvCreateImage(cvGetSize(srcImage), IPL_DEPTH_8U, 1);

//copy the source image to copy image after converting the format
cvCvtColor(srcImage, grayImage, CV_BGR2GRAY);

//create empty images of same size as the copied images
corners1= cvCreateImage(cvGetSize(srcImage), IPL_DEPTH_32F, 1);
corners2= cvCreateImage(cvGetSize(srcImage),IPL_DEPTH_32F, 1);

cvGoodFeaturesToTrack (grayImage, corners1, corners2, corners,
&cornerCount, 0.05, 5, 0);

printf("num corners found: %d\n", cornerCount);

// draw circles at each corner location in the gray image and
// print out a list the corners
if(cornerCount>0)
{
for (i=0; i<cornercount i> {<br> cvCircle(srcImage, cvPoint((int)(corners[i].x), (int)(corners[i].y)), 6,<br> color, 2, CV_AA, 0);<br> }<br> }<br><br> cvShowImage( "image", srcImage ); <br><br> cvReleaseImage(&amp;srcImage);<br> cvReleaseImage(&amp;grayImage);<br> cvReleaseImage(&amp;corners1);<br> cvReleaseImage(&amp;corners2);<br><br> cvWaitKey(0); // wait for key. The function has<br> return 0;<br>}<br></cornercount>

<!-- Signature -->

-----------------
敕勒川,阴山下
天似穹庐,笼罩四野
天苍苍,野茫茫,风吹草低见牛羊<!-- Signature --><!-- Message body ''"" -->

你可能感兴趣的:(opencv)