opencv之图像膨胀

#include <cv.h>

#include <highgui.h>



void main()

{

    IplImage* src;

    IplImage*dst;

    src=cvLoadImage("../../lena.jpg");

    dst=cvCreateImage(cvGetSize(src),8,3);

    

    cvNamedWindow("dst");

    cvShowImage("dst",src);



    printf("SRC:\n");



    int x,y;

    for (y=0;y<10;y++)

    {

        for (x=0;x<10;x++)

        {

            CvScalar values=cvGet2D(src,y,x);

            printf("%3d ",(int)values.val[1] );

        }

        printf("\n");

    }

    printf("---------------------------------------------\n");

    



    int values[16]={0,0,0,0,

        0,0,1,0,

        0,1,1,0,

        0,0,0,0

    } ;

    IplConvKernel*element=0;

    int cols=4,rows=4,ancher_x=2,ancher_y=2;

    element=cvCreateStructuringElementEx(cols,rows,ancher_x,ancher_y,CV_SHAPE_CUSTOM,values);

    cvDilate(src,dst,element,1);

    printf("DST:\n");

    printf("-------------------膨胀后的结果---------------------\n");

    for (y=0;y<10;y++)

    {

        for (x=0;x<10;x++)

        {

            CvScalar values=cvGet2D(dst,y,x);

            printf("%3d ",(int)values.val[1] );

        }

        printf("\n");

    }

    cvWaitKey(0);

    //system("pause");



}
View Code

 

你可能感兴趣的:(opencv)