Harris algorithm based on openCV

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

Harris <wbr>algorithm <wbr>based <wbr>on <wbr>openCV

Harris <wbr>algorithm <wbr>based <wbr>on <wbr>openCV

The result Image:

Harris <wbr>algorithm <wbr>based <wbr>on <wbr>openCV

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;

}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值