Android OpenCV 将 ROI 复制到更大图像的一部分
Android OpenCV copy ROI to part of bigger image
我从 phone 的相机中得到一张垫子 (320x480)。然后我需要处理该帧的一部分。我为此使用投资回报率:
mat2 = new Mat(width, 175, CvType.CV_8SC3);
Rect roi = new Rect(75, 0, 175, 320);
mat2 = new Mat(mat1, roi);
现在我想创建一个尺寸为 320x480 的黑色背景的新垫子。我该怎么做?
然后我想将处理后的 ROI 复制到新垫子上与第一个垫子相同的位置。我该怎么做?
我正在使用 OpenCV 3.4.6 和 android studio。
提前致谢
您只需要从原始 Mat
(您的相机框架)submat()
一个 ROI
,然后将 submat
作为正常处理 Mat
,但要注意不要克隆 sumbmat
如果你想得到原来的效果。
根据评论更新:
Mat originalMat = someMat;
Mat blackMat = Mat.zeros(size, CvType.CV_8UC1); // it is your black mat
// create a submat from the original mat, and clone it
Mat roiMat = originalMat.submat(rect).clone();
..... // do what you want with roiMat
// now copy the result to the original mat
Mat dst = originalMat.submat(rect); // do not clone this submat
roiMat.copyTo(dst);
// done!
我从 phone 的相机中得到一张垫子 (320x480)。然后我需要处理该帧的一部分。我为此使用投资回报率:
mat2 = new Mat(width, 175, CvType.CV_8SC3);
Rect roi = new Rect(75, 0, 175, 320);
mat2 = new Mat(mat1, roi);
现在我想创建一个尺寸为 320x480 的黑色背景的新垫子。我该怎么做?
然后我想将处理后的 ROI 复制到新垫子上与第一个垫子相同的位置。我该怎么做?
我正在使用 OpenCV 3.4.6 和 android studio。
提前致谢
您只需要从原始 Mat
(您的相机框架)submat()
一个 ROI
,然后将 submat
作为正常处理 Mat
,但要注意不要克隆 sumbmat
如果你想得到原来的效果。
根据评论更新:
Mat originalMat = someMat;
Mat blackMat = Mat.zeros(size, CvType.CV_8UC1); // it is your black mat
// create a submat from the original mat, and clone it
Mat roiMat = originalMat.submat(rect).clone();
..... // do what you want with roiMat
// now copy the result to the original mat
Mat dst = originalMat.submat(rect); // do not clone this submat
roiMat.copyTo(dst);
// done!