//http://blog.youkuaiyun.com/moc062066
//chinamochen@gmail.com
//2014年5月24日
//
#include<cv.h>
#include<highgui.h>
#include<iostream>
#include<cxcore.h>
using namespace std ;
int main(int argc, char *argv[])
{
// Load a color image, and convert it into grayscale
IplImage* img = cvLoadImage("F:\\lena.jpg");
IplImage* img_gray = cvCreateImage(cvGetSize(img), 8, 1);
cvCvtColor(img, img_gray, CV_BGR2GRAY);
// Create temporary images required by cvGoodFeaturesToTrack
IplImage* img_temp = cvCreateImage(cvGetSize(img), 32, 1);
IplImage* img_eigen = cvCreateImage(cvGetSize(img), 32, 1);
// Create the array to store the points detected( <= 1000 )
int count = 1000;
CvPoint2D32f* corners = new CvPoint2D32f[count];
// Find corners
cvGoodFeaturesToTrack(img_gray, img_eigen, img_temp, corners, &count, 0.1, 10);
// Mark these corners on the original image
for(int i=0;i<count;i++)
{
cvLine(img, cvPoint(corners[i].x, corners[i].y), cvPoint(corners[i].x, corners[i].y), CV_RGB(255,0,0), 5);
}
// Display it
cvNamedWindow("img");
cvShowImage("img", img);
// Print the number of corners
printf("Detected Points : %d\n", count);
cvWaitKey(0);
return 0 ;
}