OpenCV合并图像

*****************/
#include 
#include 
int main()
{
    char* filePath ="D:/图片库/Lena.jpg";
    IplImage* srcImg = cvLoadImage(filePath);
    IplImage* greyImg = cvCreateImage(cvGetSize(srcImg), srcImg->depth, 1);
    IplImage* cannyImg = cvCreateImage(cvGetSize(greyImg), srcImg->depth, 1);
    CvSize dstSize;
    dstSize.width = srcImg->width *3.0;
    dstSize.height = srcImg->height;
    IplImage* dstImg = cvCreateImage(dstSize, srcImg->depth, srcImg->nChannels);
    cvZero(dstImg);
    cvConvertImage(srcImg, greyImg);    
    cvCanny(greyImg, cannyImg, 150, 100);
    //----------------------------------
    //载入原图像到目标图像
    cvSetImageROI(dstImg, cvRect(0, 0, srcImg->width, srcImg->height));
    cvCopy(srcImg, dstImg);
     cvResetImageROI(dstImg);
    //载入灰度图像到目标图像
    cvSetImageROI(dstImg, cvRect(srcImg->width, 0, srcImg->width, srcImg->height));
    dstImg->nChannels =1;
    cvCopy(greyImg, dstImg);
    cvResetImageROI(dstImg);
    //载入边缘检测图像到目标图像
    cvSetImageROI(dstImg, cvRect((srcImg->width) *2.0, 0, srcImg->width, srcImg->height));
    dstImg->nChannels =1;
    cvCopy(cannyImg, dstImg);
    cvResetImageROI(dstImg);
    //---------------------------------------
    cvNamedWindow("dstImg");
    cvShowImage("dstImg", dstImg);
    cvWaitKey(0);
    cvReleaseImage(&srcImg);
    cvReleaseImage(&greyImg);
    cvReleaseImage(&cannyImg);
    cvReleaseImage(&dstImg);
    cvDestroyWindow("dstImg");
    return0;

你可能感兴趣的:(OpenCV合并图像)