cvSetData

关于cvSetData的一个小练习

//刚开始我一直以为imageData里面会有负数,后来发现自己错了,但是会有0存在

void main() {

int i , j;

long k;

char *BGRData;

IplImage * image = cvLoadImage( "lena.jpg" , 1 );

IplImage *iplImage = cvCreateImage(cvGetSize(image),image->depth,image->nChannels);

/*//方法一:

for( j = 0 ; j < image -> height ; j ++ ) {

for( i = 0 ; i < image -> width ; i ++ ) {

(  ( iplImage -> imageData + j * image -> widthStep ) ) [ i * iplImage -> nChannels ]

= ( ( image -> imageData + j * image -> widthStep ) ) [ i * image -> nChannels ];

(  ( iplImage -> imageData + j * image -> widthStep ) ) [ i * iplImage -> nChannels  + 1]

=((image -> imageData+j*image->widthStep))[i*image->nChannels+1];

(  ( iplImage -> imageData + j * image -> widthStep ) ) [ i * iplImage -> nChannels +2 ]

=((image -> imageData+j*image->widthStep))[i*image->nChannels+2];


}

}

*/

/*//方法二:

for( k = 0 ; k < image -> height * image -> widthStep ; k ++ ) {

iplImage -> imageData[ k ] = image -> imageData[ k ];

}

*/

/*//方法三:

cvSetData( iplImage , image -> imageData , iplImage -> widthStep );

*/

////方法四:

BGRData = ( char * ) malloc ( image -> height * image -> widthStep * sizeof( char ) );

for( k = 0 ; k < image -> height * image -> widthStep ; k ++ ) {

BGRData[ k ] = image -> imageData[ k ];

}

cvSetData( iplImage , BGRData , iplImage -> widthStep );


cvShowImage( "image" , image );

cvShowImage( "iplImage" , iplImage );

cvWaitKey( 100000 );

}

你可能感兴趣的:(image)