您的位置:首页 > 其它

cvCornerHarris角点检测

2015-06-16 21:43 190 查看


#include "cv.h"
#include "highgui.h"
#include "iostream"
using namespace std;
using namespace cv;
int flag=1;
int main(int argc,char** argv)
{

IplImage *src=cvLoadImage("line.jpg");
cvShowImage("src1",src);
IplImage *Ipl_Gray=cvCreateImage(cvGetSize(src),8,1);
IplImage *Ipl_32F=cvCreateImage(cvGetSize(src),IPL_DEPTH_32F,1);
cvCvtColor(src,Ipl_Gray,CV_RGB2GRAY);
cvCornerHarris(Ipl_Gray,Ipl_32F,7,3);
cvShowImage("32",Ipl_32F);
/**************显示图片的实际像素值 **********************
while(flag)
{
for(int i=0;i<src->height ;i++)
{
for(int j=0;j<src->width;j++)
{
double value= cvGetReal2D(Ipl_32F,i,j);

printf("%f ",value);
}
printf("\n ");
}
flag=0;
}
******************************************************/
double minVal,maxVal;
double minVal1,maxVal1;

cvMinMaxLoc(Ipl_32F,&minVal,&maxVal,NULL,NULL,0);
IplImage *Ipl_out=cvCreateImage(cvGetSize(src),8,1);
double Scale;
double Shift;
Scale =255/(maxVal-minVal);
Shift =-minVal*Scale;
cvConvertScale(Ipl_32F,Ipl_out,Scale,Shift);
cvShowImage("out",Ipl_out);
while(flag)
{
for(int i=0;i<src->height ;i++)
{
for(int j=0;j<src->width;j++)
{
double value= cvGetReal2D(Ipl_out,i,j);

if(value>120)
{
cvCircle(src,cvPoint(j,i),1,CV_RGB(55,55,125),1,8);
}
// printf("%f ",value);
}
// printf("\n ");
}
flag=0;
}
cvShowImage("src",src);
// cvMinMaxLoc(Ipl_out,&minVal1,&maxVal1,NULL,NULL,0);

//cout<<minVal1<<endl;
// cout<<maxVal1<<endl;
cout<<minVal<<endl;
cout<<maxVal<<endl;
cvWaitKey();

return 0;

}

重点介绍cvCornerHarris函数的用法细节

CornerHarris

哈里斯(Harris)边缘检测
void cvCornerHarris( const CvArr* image, CvArr* harris_responce, int block_size, int aperture_size=3, double k=0.04 );

image输入图像。harris_responce存储哈里斯(Harris)检测responces的图像。与输入图像等大。block_size邻域大小(见关于cvCornerEigenValsAndVecs的讨论)。aperture_size扩展 Sobel 核的大小(见 cvSobel)。格式. 当输入图像是浮点数格式时,该参数表示用来计算差分固定的浮点滤波器的个数。kHarris detector free parameter. See the formula below.
The function cvCornerHarris runs the Harris edge detector on image. Similarly to cvCornerMinEigenVal and cvCornerEigenValsAndVecs, for each pixel it calculates 2x2 gradient covariation matrix
M over block_size×block_size neighborhood. Then, it stores
det(M) - k*trace(M)2 to the destination image. Corners in the image can be found as local maxima of the destination image

第一个参数是输入的图像;
第二的参数是 harris_responce(要是是32 位的浮点dan通道图像)
(看看以上的第一个图:是读回这个参数的值,这个表面了,经过cvCornerHarris处理过后的值变成很小的浮点值)

这也是表命了,cvCornerharris处理去处理图像的时候,必须采用32位的浮点型)

另外,读回来的值这么小,怎么转换为图像呢,这就需要cvconvertScale转换为适合一定范围的图像值

double Shift;
Scale =255/(maxVal-minVal);
Shift =-minVal*Scale;
cvConvertScale(Ipl_32F,Ipl_out,Scale,Shift);

下面是处理过后的彩色图像

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: