角点检测(3)SUSAN算子



#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <math.h>

int main( int argc, char** argv )
{
    int height ,width ,step ,channels ;
         int i,j,k,same ,max,min,thresh,sum;
         uchar*data0,*data1 ;
         //char *filename="result.bmp";
        // IplImage* Img,*nimg; //声明IplImage指针
    //载入图像
       IplImage*  nimg = cvLoadImage("1.jpg");
       IplImage*  Img = cvCreateImage(cvGetSize(nimg),8,1);
		cvCvtColor( nimg, Img, CV_BGR2GRAY );
height    = Img->height;
width     = Img->width;
step      = Img->widthStep/sizeof(uchar);
channels = Img->nChannels;
        data0   = (uchar*)Img->imageData;
        data1 =    (uchar*)nimg->imageData;
printf("Processing a %d X %d image with %d channels\n",width,height,channels);
int OffSetX[37] = { -1, 0, 1,
-2,-1, 0, 1, 2,
-3,-2,-1, 0, 1, 2, 3,
-3,-2,-1, 0, 1, 2, 3,
-3,-2,-1, 0, 1, 2, 3,
-2,-1, 0, 1, 2,
-1, 0, 1 };
int OffSetY[37] = { -3,-3,-3,
-2,-2,-2,-2,-2,
-1,-1,-1,-1,-1,-1,-1,
0, 0, 0, 0, 0, 0, 0,
1, 1, 1, 1, 1, 1, 1,
2, 2, 2, 2, 2,
3, 3, 3 };
    max = min = data0[0];
    //for(i=0;i<height;i++)
// for(j=0;j<width;j++)
    //{
   // if(data0[i*step+j]>max) max = data0[i*step+j];
    //if(data0[i*step+j]<min)   min = data0[i*step+j];
//   }
    for(i=3;i<height-3;i++)
    for(j=3;j<width-3;j++)
   {
        same =0;sum = 0;
        for(k=0;k<37;k++)
     {
        sum+=data0[(i+OffSetY[k])*step+(j+OffSetX[k])];
        thresh = sum/37;
        if(fabs( (float)(data0[(i+OffSetY[k])*step+(j+OffSetX[k])]-data0[i*step+j]))<=thresh)
        same++;
        if(same<18)
        data1[i*step+j] = 255;
        else
        data1[i*step+j] = 0;
     }
   }
   cvNamedWindow( "Image", 1 ); //创建窗口
        cvShowImage( "Image", nimg ); //显示图像
        cvWaitKey(0); //等待按键
        cvDestroyWindow( "Image" );//销毁窗口
        cvReleaseImage( &Img ); //释放图像
        cvReleaseImage( &nimg );
        return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值