OpenCv之角点检测PreCornerDetect算法

PreCornerDetect

计算用于角点检测的特征图,

void cvPreCornerDetect( const CvArr* image, CvArr* corners, int aperture_size=3 );
image
输入图像.
corners
保存候选角点的特征图
aperture_size
Sobel 算子的核大小(见cvSobel).

函数 cvPreCornerDetect 计算函数D_x^2D_{yy}+D_y^2D_{xx} - 2D_xD_yD_{xy} 其中 D_{\cdot} 表示一阶图像差分,D_{\cdot \cdot} 表示二阶图像差分。 角点被认为是函数的局部最大值:

// 假设图像格式为浮点数
IplImage* corners = cvCloneImage(image);
IplImage* dilated_corners = cvCloneImage(image);
IplImage* corner_mask = cvCreateImage( cvGetSize(image), 8, 1 );
cvPreCornerDetect( image, corners, 3 );
cvDilate( corners, dilated_corners, 0, 1 );
cvSub( corners, dilated_corners, corners );
cvCmpS( corners, 0, corner_mask, CV_CMP_GE );
cvReleaseImage( &corners );
cvReleaseImage( &dilated_corners );
上面选自opencv中文网站

下面直接上图上代码

效果图:

OpenCv之角点检测PreCornerDetect算法_第1张图片

代码:

void preCorner() {                                                                                                                                 IplImage  *gray, *sobel,*binary, *frame;
	frame = cvLoadImage("girl.png");//加载图像
	IplImage* temp = cvCreateImage(cvGetSize(frame), IPL_DEPTH_32F, 3);
	cvConvertScale(frame, temp);
	IplImage* out = cvCreateImage(cvGetSize(temp), IPL_DEPTH_32F, 1);
	cvCvtColor(temp, out, CV_RGB2GRAY);
	IplImage* corners = cvCloneImage(out);
	cvPreCornerDetect(out, corners, 3);
	cvNamedWindow("PreCornerDetect");
	cvShowImage("frame", frame);
	cvShowImage("PreCornerDetect", corners);
	cvWaitKey(0);

	cvReleaseImage(&out);
	cvReleaseImage(&corners);
	cvReleaseImage(&temp);
}


你可能感兴趣的:(opencv)