这是在 Ruadhan 提供的源代码基础上做了一些修改,可以检测图像中的角点。应用环境是:OPENCV BETA 4,VC6 编译运行通过。
==========
#include <stdio.h>
#include "cv.h"
#include "highgui.h"
#define max_corners 100
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);
cvNamedWindow( "image", 1 ); // create HighGUI window with name "image"
//Load the image to be processed
srcImage = cvLoadImage("..//..//c//pic3.png", 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++)
{
cvCircle(srcImage, cvPoint((int)(corners[i].x), (int)(corners[i].y)), 6,
color, 2, CV_AA, 0);
}
}
cvShowImage( "image", srcImage );
cvReleaseImage(&srcImage);
cvReleaseImage(&grayImage);
cvReleaseImage(&corners1);
cvReleaseImage(&corners2);
cvWaitKey(0); // wait for key. The function has
return 0;
}
-----------------
敕勒川,阴山下
天似穹庐,笼罩四野
天苍苍,野茫茫,风吹草低见牛羊