OpenCV 关于两张图片的整合问题

第一,将两张图片上下排列,合成一张图片

extern IplImage* stack_imgs( IplImage* img1, IplImage* img2 )
{
	IplImage* stacked = cvCreateImage( cvSize( MAX(img1->width, img2->width),
										img1->height + img2->height ),
										IPL_DEPTH_8U, 3 );

	cvZero( stacked );
	cvSetImageROI( stacked, cvRect( 0, 0, img1->width, img1->height ) );
	cvAdd( img1, stacked, stacked, NULL );
	cvSetImageROI( stacked, cvRect(0, img1->height, img2->width, img2->height) );
	cvAdd( img2, stacked, stacked, NULL );
	cvResetImageROI( stacked );

	return stacked;
}


第二,将两张图片左右排列,合成一张图片

extern IplImage* expand_imgs( IplImage* img1, IplImage* img2 )
{
	IplImage* expanded = cvCreateImage( cvSize( 
		img1->width + img2->width,MAX(img1->height, img2->height)), 
		IPL_DEPTH_8U, 3 );

	cvZero( expanded );
	cvSetImageROI( expanded, cvRect( 0, 0, img1->width, img1->height ) );
	cvAdd( img1, expanded, expanded, NULL );
	cvSetImageROI( expanded, cvRect(img1->width, 0, img2->width, img2->height) );
	cvAdd( img2, expanded, expanded, NULL );
	cvResetImageROI( expanded );

	return expanded;
}


你可能感兴趣的:(OpenCV 关于两张图片的整合问题)