#include<iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// OpenCV
#include <cxcore.h>
#include <cv.h>
#include <highgui.h>
#include <cvaux.h>
using namespace std;
using namespace cv;
void main(int argc, char* argv[])
{
IplImage *imgGrey;
double minVal = 0.0, maxVal = 0.0;
double min = 0, max = 255;
double scale, shift;
IplImage *image = cvLoadImage("停车位4.jpg");
IplImage *pHarrisImg = cvCreateImage(cvGetSize(image), IPL_DEPTH_32F, 1);
IplImage* imgRGB2 = cvLoadImage("停车位4.jpg");
imgGrey = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
IplImage *dst8 = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
imgGrey->origin = image->origin;
cvCvtColor(image, imgGrey, CV_BGR2GRAY);
CvRect roi;
roi.x = 0;
roi.y = 10;
roi.width = imgGrey->width;
roi.height = imgGrey->height;
cvSetImageROI(imgGrey, roi);
IplImage *dst;
dst = cvCloneImage(imgGrey);
int w=dst->width;
int h=dst->height;
IplImage* eig_image = cvCreateImage(cvSize(w, h),IPL_DEPTH_32F, 1);
IplImage* temp_image = cvCreateImage(cvSize(w, h),IPL_DEPTH_32F, 1);
const int MAX_CORNERS = 1000;//estimate a corner number
CvPoint2D32f corners[MAX_CORNERS] = {0};// coordinates of corners
//CvPoint2D32f* corners = new CvPoint2D32f[ MAX_CORNERS ]; //another method of declaring an array
int corner_count = MAX_CORNERS;
double quality_level = 0.01;//threshold for the eigenvalues
double min_distance = 0;//minimum distance between two corners
int eig_block_size = 3;//window size
int use_harris = true;//use 'harris method' or not
unsigned char * src = (unsigned char*)malloc(100 * sizeof(unsigned char));
int a = sizeof(*src);
int half_win_size=3;//the window size will be 3+1+3=7
int iteration=20;
double epislon=0.1;
cvGoodFeaturesToTrack(dst,
eig_image, // output
temp_image,
corners,
&corner_count,
quality_level,
min_distance,
NULL,
eig_block_size,
use_harris);
int r=2; //rectangle size
int lineWidth=1; // rectangle line width
//-----draw good feature corners on the original RGB image---------
for (int i=0;i<corner_count;i++){
corners[i].x += roi.x;
corners[i].y += roi.y;
cvRectangle(imgRGB2, cvPoint(corners[i].x-r,corners[i].y-r),
cvPoint(corners[i].x+r,corners[i].y+r), cvScalar(0,255,0),lineWidth);
}
cvNamedWindow("cvGoodFeaturesToTrack", CV_WINDOW_AUTOSIZE );
cvShowImage( "cvGoodFeaturesToTrack", imgRGB2 );
cvWaitKey(0);
}