cvCornerHarris角点检测


#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)。格式. 当输入图像是浮点数格式时,该参数表示用来计算差分固定的浮点滤波器的个数。
k
Harris 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);

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值