filter.c

来自「于仕琪的OpenCV基础+教程的程序实例」· C语言 代码 · 共 120 行

C
120
字号
//  Filtering for Image with variaty filtering kernel//// CV_PREWITT_3x3_V A gradient filter (vertical Prewitt operator).//         -1  0  1//         -1  0  1//         -1  0  1// CV_PREWITT_3x3_H A gradient filter (horizontal Prewitt operator).//          1  1  1//          0  0  0//         -1 -1 -1// CV_SOBEL_3x3_V A gradient filter (vertical Sobel operator).//         -1  0  1//         -2  0  2//         -1  0  1// CV_SOBEL_3x3_H A gradient filter (horizontal Sobel operator).//          1  2  1//          0  0  0//         -1 -2 -1// CV_LAPLACIAN_3x3 A 3x3 Laplacian highpass filter.//         -1 -1 -1//         -1  8 -1//         -1 -1 -1// CV_LAPLACIAN_3x3 A 3x3 Laplacian highpass filter (another kernel)// This kernel is similar with function: cvLaplace with aperture_size=1//          0  1  0//          1  -4  1//          0  1  0      注:直接用cvFilter2D得到的结果与用cvLaplace得到的结果//                           略有不同// CV_LAPLACIAN_5x5 A 5x5 Laplacian highpass filter.//         -1 -3 -4 -3 -1//         -3  0  6  0 -3//         -4  6 20  6 -4//         -3  0  6  0 -3//         -1 -3 -4 -3 -1// CV_GAUSSIAN_3x3 A 3x3 Gaussian lowpass filter.// This filter uses the kernel A/16,where//         1 2 1//     A =  2 4 2//         1 2 1// These filter coefficients correspond to a 2-dimensional Gaussian// distribution with standard deviation 0.85.//// CV_GAUSSIAN_5x5 A 5x5 Gaussian lowpass filter.// This filter uses the kernel A/571,where//         2  7  12  7  2//         7 31  52 31  7//    A =  12 52 127 52 12//         7 31  52 31  7//         2  7  12  7  2#include <cv.h>#include <highgui.h>#include <stdio.h>int main( int argc, char** argv ){ 	IplImage *src = 0;
    IplImage *dst = 0;
    IplImage *dstdown = 0;
    IplImage *dstup = 0;

	src = cvLoadImage("lena.jpg", 0);   //导入图象

/*	CvPoint  offset;
    CvScalar value;

	offset.x=0;
	offset.y=0;
	value.val[0]=255;
    value.val[1]=255;
    value.val[2]=255;
     
//	cvCopyMakeBorder(src,dst,offset,IPL_BORDER_REPLICATE,cvScalarAll(0));
	cvCopyMakeBorder(src,dst,offset,IPL_BORDER_CONSTANT,value); */

    
/*	IplImage *dst1 = 0;
    IplImage *src1 = 0;

    src1=  cvCreateImage(cvSize(src->width,src->height+1),IPL_DEPTH_32S,1); 
	dst = cvCreateImage(cvSize((src->width+1),(src->height+1)),IPL_DEPTH_64F,1);
    dst1 = cvCreateImage(cvSize((src->width+1),(src->height+1)),IPL_DEPTH_32S,1);
 
    cvIntegral(src,dst,0,0);
	cvIntegral(src,dst1,0,0); 

    cvNamedWindow("dst1", 0);
    cvShowImage("dst1",0);	
	cvReleaseImage( &dst1 );*/


/*   dstdown = cvCreateImage(cvSize(((src->width)/2),((src->height)/2)),IPL_DEPTH_8U,1);
     cvPyrDown(src,dstdown,CV_GAUSSIAN_5x5);
     cvNamedWindow("dstdown", 1);
     cvShowImage("dstdown",dstdown);


	 dstup = cvCreateImage(cvSize(((src->width)*2),((src->height)*2)),IPL_DEPTH_8U,1);
     cvPyrUp(src,dstup,CV_GAUSSIAN_5x5);
     cvNamedWindow("dstup", 1);
     cvShowImage("dstup",dstup);*/
   

   

   


    cvNamedWindow("src", 1);
    cvShowImage("src",src);    cvWaitKey(0);

	cvDestroyAllWindows();    cvReleaseImage( &src );
    cvReleaseImage( &dst );
  
   return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?