4/03/2009

Merging 2 Image

Hi,
a simple solution is:
You could initialize a new picture with the required dimensions, andcopy the data line for line, one after one from both pictures into thenew one.

Examplecode:
//Let's assume img1 and img2 are your 1024x768 grayscale-images of
// type IplImage

IplImage *combined = new IplImage;
CvSize size;
size.width=2048;
size.height=768;
combined = cvCreateImage(size, IPL_DEPTH_8U, 1);
for (int i = 0; i < (size.height-1); i++) { memcpy(&img3->imageData[i*img3->widthStep],&img1->imageData[i*img1->widthStep], img1->widthStep);
memcpy(&img3->imageData[i*img3->widthStep+img1->widthStep],&img2->imageData[i*img2->widthStep], img2->widthStep);
}

No comments: