opencv:将图像copy到指定位置

#include "cv.h"
#include "highgui.h"

int main()
{

    IplImage* img = cvLoadImage("E:/opencv/src/sf.jpg",0);
    CvRect roi =cvRect(6, 6, 48, 48);

    cvNamedWindow("img");
    cvShowImage("img", img);

    IplImage* img1 = cvLoadImage("E:/opencv/src/lena.png",0);
    CvRect roi1 = cvRect(6, 6, 48, 48);

    cvNamedWindow("img1");
    cvShowImage("img1", img1);

    cvSetImageROI(img, roi);
    cvSetImageROI(img1, roi1);
    cvCopy(img1, img);

    CvSize size= cvSize(100,100);//区域大小
    cvSetImageROI(img,cvRect(60,70,size.width, size.height));//设置源图像ROI
    IplImage* pDest = cvCreateImage(size,img->depth,img->nChannels);//创建目标图像
    cvCopy(img,pDest); //复制图像
    cvResetImageROI(pDest);//源图像用完后,清空ROI
    cvSaveImage("E:/opencv/src/Roi.jpg",pDest);//保存目标图像

    cvResetImageROI(img);
    cvResetImageROI(img1);

    cvNamedWindow("result");

    cvShowImage("result", img);


    cvWaitKey(-1);
    cvReleaseImage(&img);
    cvReleaseImage(&img1);
    cvDestroyAllWindows();
    return 0;
}

你可能感兴趣的:(opencv入门)