2016-08-24 114 views
0

我試圖將一個圖像複製到另一個圖像,我使用CopyTo實現它,除了將源圖像放入目標的ROI之外,我的目標圖像被完全替換。將圖像複製到ROI

這裏是我的代碼如下所示:

var output = new Mat(size, size, MatType.CV_8UC3, background); 
var temp1 = image.Resize(new OpenCvSharp.Size(targetWidth, targetHeight), 0, 0, interpolation); 
xOffset = Convert.ToInt32((size - targetWidth)/2); 
yOffset = Convert.ToInt32((size - targetHeight)/2); 
output.AdjustROI(yOffset, (size - 1) - yOffset, xOffset, (size - 1) - xOffset); 
temp1.CopyTo(output); 
output.AdjustROI(0, size - 1, 0, size - 1); 

我發現,在OpenCV的這種使用()運營商的投資回報率,但是我無法找到該運營商在OpenCVSharp現已實現,我不知道那是什麼相當於可能被命名爲。

回答

0

我意識到,這可能會使用Mat的在OpenCVSharp構造函數來實現和下面的代碼似乎這樣的伎倆:

var output = new Mat(size, size, MatType.CV_8UC3, background); 
var temp1 = image.Resize(new OpenCvSharp.Size(targetWidth, targetHeight), 0, 0, interpolation); 
xOffset = Convert.ToInt32((size - targetWidth)/2); 
yOffset = Convert.ToInt32((size - targetHeight)/2); 
var roi = new Mat(output, new Rect(xOffset, yOffset, targetWidth, targetHeight)); 
temp1.CopyTo(roi);