opencv之圖像的腐蝕


#include<highgui.h>

#include<cxcore.h>
#include<cv.h>
#include<iostream>
int main()
{
IplImage* src = cvCreateImage ( cvSize ( 11 , 10) ,8 , 1 );//create a array include 11 rows and 10 cols;
IplImage* dst = cvCreateImage ( cvGetSize (src) , 8 , 1 );//save the result;
cvZero ( src);
cvZero ( dst);
int x , y ;


//(1,6)-(1,9)
    // (2,6)-(2,9)
    // (3,6)-(3,9)
//set 255

for( y = 1 ;y<4 ; y++)
{
for( x=6 ; x<10;x++)
{
cvSetReal2D( src ,y , x ,255);
}
}


for( y = 4 ;y<6 ; y++)
{
for( x=4 ; x<8;x++)
{
cvSetReal2D( src ,y , x ,255);
}
}

for( x=1 ; x<8;x++)
{
cvSetReal2D( src ,6 , x ,255);
}
for( y = 7 ;y<9 ; y++)
{
for( x=1 ; x<5 ; x++)
{
cvSetReal2D( src ,y , x ,255);
}
}
printf( " src is \n");
for( y = 0 ;y<src->height ; y++)
{
for( x=0 ; x<src->width ;x++)
{
float value = cvGetReal2D( src , y , x);
printf( " %3d" , (int)(value));
}
printf ("\n");
}// it is over that set the mat;


IplConvKernel* element = 0 ;
// set the Erode model
int values[16]={0,0,0,0,
           0,0,1,0,
0,1,1,0,
0,0,0,0
               };
int cols = 4 ,rows=4,anchor_x=2,anchor_y=2;
element = cvCreateStructuringElementEx( cols , rows , anchor_x ,anchor_y ,CV_SHAPE_CUSTOM , values );
cvErode ( src , dst , element , 1);// erode one ci
printf( "dst is \n");
for( y = 0 ;y<src->height ; y++)
{
for( x=0 ; x<src->width ;x++)
{
float value = cvGetReal2D( dst , y , x);
printf( " %3d" , (int)(value));
}
printf ("\n");
}

}



發佈了8 篇原創文章 · 獲贊 3 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章