작업공간/OpenCV

char* -> IplImage 변환하기

Saul Kim 2014. 3. 18. 14:48

IplImage 구조체 데이터에 직접 char 버퍼의 데이터를 대입한다.


IplImage* _cvt_char_IplImage( unsigned char *pImage, int width, int height ) 

{

IplImage* img = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);

for(int i=0; i<img->height; i++) 

for(int j=0; j<img->width; j++) 

{

img->imageData[ i* img->widthStep + j*3 + 0 ] = pImage[i* img->widthStep + j*3 + 0]; // blue

img->imageData[ i* img->widthStep + j*3 + 1 ] = pImage[i* img->widthStep + j*3 + 1]; // green

img->imageData[ i* img->widthStep + j*3 + 2 ] = pImage[i* img->widthStep + j*3 + 2]; // red

 } 

}


return img;

}