我有RGB大图像和RGB小图像。 用较小的图像替换较大图像中的区域的最快方法是什么? 我可以定义多渠道ROI然后使用copyTo吗?或者我必须将每个图像分割成通道,替换ROI然后再将它们重新组合成一个?
答案 0 :(得分: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();
}