http://blog.sina.com.cn/s/blog_661159d50100iql0.html,有图像不显示的请查看我的sina博客
Harris algorithm based on openCV
Those time, I plan to do with those corner detect algorithms, such as Harris, SIFT, ASIFT.
So today I finish the Harris detect and others will be finished in some days.
Harris algorithm:
Step 1:对每一像素点计算相关矩阵M。
The result Image:
And the code for openCV:
/
//harris detect
//author:crazy_007
//at 2010.5.11
#include "cv.h"
#include "highgui.h"
int main(int argc,char** argv)
{
IplImage* pImg;
IplImage* pHarrisImg;
IplImage* grayImage;
IplImage* dst8;
double minVal=0.0, maxVal=0.0;
double scale, shift;
double min=0, max=255;
if(argc==2 && (pImg=cvLoadImage(argv[1],1))!=NULL)
{
cvNamedWindow("source",1);
cvShowImage("source",pImg);
pHarrisImg=cvCreateImage(cvGetSize(pImg),IPL_DEPTH_ 32F,1);//there we should define IPL_DEPTH_32F rather than IPL_DEPTH_8U
grayImage=cvCreateImage(cvGetSize(pImg),IPL_DEPTH_8U,1);
dst8=cvCreateImage(cvGetSize(pImg),IPL_DEPTH_8U,1);//this is for the result image
grayImage->origin=pImg->origin; //there make sure the same origin between grayImage and pImg
cvCvtColor(pImg,grayImage,CV_BGR2GRAY);//cause harris need gray scale image,we should convert RGB 2 gray.
int block_size=7;
//do harris algorithm
cvCornerHarris(grayImage,pHarrisImg,block_size,3,0.04);
//convert scale so that we see the clear image
cvMinMaxLoc(pHarrisImg,&minVal,&maxVal,NULL,NULL,0);
scale=(max-min)/(maxVal-minVal);
shift=-minVal*scale+min;
cvConvertScale(pHarrisImg,dst8,scale,shift);
cvNamedWindow("Harris",1);
cvShowImage("Harris",dst8);
cvWaitKey(0);
cvDestroyWindow("source");
cvDestroyWindow("Harris");
cvReleaseImage(&dst8);
cvReleaseImage(&pHarrisImg);
return 0;
}
return 1;
}