2012-08-05 26 views
0

我有一个RGB大图像和一个RGB小图像。 用较小的图像替换较大图像中的区域的最快方法是什么? 我可以定义多渠道投资回报率,然后使用copyTo?或者我必须将每个图像分割为通道,替换ROI,然后再将它们重新组合为一个?在openCV中,如何替换图像中的RGB ROI

回答

0

是的。多渠道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(); 

} 
相关问题