程序参见:
code:
#include "stdafx.h" #include "cv.h" #include "highgui.h" #define max_corners 100 int main( int argc, char** argv ) { int cornerCount=max_corners; CvPoint2D32f corners[max_corners]; double qualityLevel = 0.05; double minDistance = 5; IplImage *srcImage = 0, *grayImage = 0, *corners1 = 0, *corners2 = 0; int i; CvScalar color = CV_RGB(255,0,0); cvNamedWindow( "image", 2); //创建显示窗口 //加载一副图片 srcImage = cvLoadImage("33.jpg", 1); grayImage = cvCreateImage(cvGetSize(srcImage), IPL_DEPTH_8U, 1); //将原图灰度化 cvCvtColor(srcImage, grayImage, CV_BGR2GRAY); corners1= cvCreateImage(cvGetSize(srcImage), IPL_DEPTH_32F, 1); corners2= cvCreateImage(cvGetSize(srcImage),IPL_DEPTH_32F, 1); cvGoodFeaturesToTrack (grayImage, corners1, corners2, corners,&cornerCount, qualityLevel, minDistance, 0); printf("num corners found: %d\n", cornerCount); if(cornerCount>0) { for (i=0; i <cornerCount;++i) { cvCircle(srcImage, cvPoint((int)(corners[i].x), (int)(corners[i].y)), 6,color, 2, CV_AA, 0); } } cvShowImage("image", srcImage); cvWaitKey(0); cvReleaseImage(&srcImage); cvReleaseImage(&grayImage); cvReleaseImage(&corners1); cvReleaseImage(&corners2); return 0; }
另外一个:
忘记在哪里下的了。。感谢原作者:
// eyes_susan.cpp : 定义控制台应用程序的入口点。 //可以检测眼睛动态匹配轮廓的susan角点检测算法,准确率98 #include "stdafx.h" #include<math.h> #include<stdlib.h> #include<stdio.h> #include "cv.h" #include "highgui.h" int main( int argc, char** argv ) { int height ,width ,step ,channels ; int i,j,k,same ,max,min,sum; float thresh; uchar *data0,*data1 ; //char *filename="result.bmp"; IplImage* Img, *nimg; //声明IplImage指针 //载入图像 Img = cvLoadImage( "yy.jpg",0); cvNamedWindow( "Image0", 2); //创建窗口 cvShowImage( "Image0", Img ); //显示图像 nimg = cvCreateImage(cvGetSize(Img),8,1); 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=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 = (float)sum/37; float data_fabs; data_fabs= (float)(data0[(i+OffSetY[k])*step+(j+OffSetX[k])]-data0[i*step+j]); if(fabs( data_fabs)<=thresh) same++; } if(same<18) nimg->imageData[i*step+j] = 255; else nimg->imageData[i*step+j] = 0; printf("same = %d\n", same); } cvNamedWindow( "Image", 2); //创建窗口 cvShowImage( "Image", nimg ); //显示图像 cvWaitKey(0); //等待按键 cvDestroyWindow( "Image" );//销毁窗口 cvReleaseImage( &Img ); //释放图像 cvReleaseImage( &nimg ); return 0; }