0

I have an RGB large-image, and an RGB small-image. What is the fastest way to replace a region in the larger image with the smaller one? Can I define a multi-channel ROI and then use copyTo? Or must I split each image to channels, replace the ROI and then recombine them again to one?

4

1 回答 1

1

是的。多通道 ROI 和 copyTo 将起作用。就像是:

int main(int argc,char** argv[])
{
    cv::Mat src = cv::imread("c:/src.jpg");

    //create a canvas with 10 pixels extra in each dim. Set all pixels to yellow.
    cv::Mat canvas(src.rows + 20, src.cols + 20, CV_8UC3, cv::Scalar(0, 255, 255));

    //create an ROI that will map to the location we want to copy the image into
    cv::Rect roi(10, 10, src.cols, src.rows);
    //initialize the ROI in the canvas. canvasROI now points to the location we want to copy to.
    cv::Mat canvasROI(canvas(roi));

    //perform the copy.
    src.copyTo(canvasROI);

    cv::namedWindow("original", 256);
    cv::namedWindow("canvas", 256);

    cv::imshow("original", src);
    cv::imshow("canvas", canvas);

    cv::waitKey();  

}
于 2012-08-06T04:20:38.610 回答