参考资料:
#pragma comment(lib,"cxcore.lib")
#pragma comment(lib,"cv.lib")
#pragma comment(lib,"highgui.lib")
#pragma comment(lib,"ml.lib")
#pragma comment(lib,"cvcam.lib")
#pragma comment(lib,"cvaux.lib")
#include
#include
#include
#include
#include
using namespace std;
int getMoravec(IplImage* src,CvPoint* corners , float threshold)
{
int winsize=5;//窗口的大小 即 5*5 win[5,5]
int halfwinsize=winsize/2;
IplImage* diffDst=cvCreateImage(cvGetSize(src),32,1);
cvZero(diffDst);
//float threshold=9500;
int conersCount=0;
float maxCornersValue=0;//最大角点值
int x,y;
/*
//滑动窗口
* * * * *
* * * * *
* * 0 * *
* * * * *
* * * * *
//遍历方式如图
**************
**************
**1111111111**
**1111111111**
**1111111111**
**************
**************
*/
for (y=halfwinsize;yheight-halfwinsize;y++)
{
for (x=halfwinsize;xwidth-halfwinsize;x++)
{
float reaction[4],minVal;
reaction[0]=0;
reaction[1]=0;
reaction[2]=0;
reaction[3]=0;
int i;
//0
for (i=-halfwinsize;iheight-halfwinsize;y+=halfwinsize)
{
for (x=halfwinsize;xwidth-halfwinsize;x+=halfwinsize)
{
float max=0;
int flag=0;
CvPoint maxLoc;
maxLoc.x=-1;
maxLoc.y=-1;
//int halfwinsize=halfwinsize;
for (int winy=-halfwinsize;winy0)printf("xxxxxx");
if (value>max)
{
max=value;
flag=1;
maxLoc.x=x+winx;
maxLoc.y=y+winy;
if(max>maxCornersValue)maxCornersValue=value;
}
}
}//------------
if (flag==1 && max>threshold)
{
corners[conersCount].x=maxLoc.x;
corners[conersCount].y=maxLoc.y;
conersCount++;
}
}
}//end for
printf("图像中最大角点值=%f",maxCornersValue);
return conersCount;
}
int main()
{
IplImage* src=cvLoadImage("img//Moravec.jpg",CV_LOAD_IMAGE_GRAYSCALE);
CvPoint* corners;
int cornersCount;
corners=(CvPoint*)malloc(sizeof(CvPoint)*9000);
int count=getMoravec(src,corners,6500);
IplImage* show=cvCreateImage(cvGetSize(src),8,3);
cvCvtColor(src,show,CV_GRAY2BGR);
for (int i=0;i