如何在 opencv 中合并两个垫子 android
How to merge two mat in opencv android
我用submat功能截取了部分图片,做了一些处理。我现在有两个垫子可以用。
Mat originalMat = new Mat();
Utils.bitmapToMat(originalBmp, originalMat);
Rect rect = new Rect(left, top, right - left, bottom - top);
Mat roi_img = originalMat.submat(rect);
Imgproc.cvtColor(roi_img, roi_img, Imgproc.COLOR_BGR2Lab);
#some processing to roi_img....
Imgproc.cvtColor(roi_img, roi_img, Imgproc.COLOR_Lab2BGR);
我发现 cvtColor 函数可能会更改 roi_img 的引用。 originalMat 的处理被禁用。 originalMat 和以前一样。
我想合并 originalMat 和 roi_img。
我尝试使用 copyto 和 clone 功能,但是没有用。
Mat mat = new Mat();
Utils.bitmapToMat(originalBmp, mat);
Rect rect = new Rect(40, 40, 100, 100);
Mat roi_img = mat.submat(rect);
double[] value = new double[]{255, 255, 255};
Imgproc.cvtColor(roi_img, roi_img, Imgproc.COLOR_BGR2Lab);
for (int i = 0; i < roi_img.rows(); i++) {
for (int j = 0; j < roi_img.cols(); j++) {
roi_img.put(i, j, value);
}
}
Imgproc.cvtColor(roi_img, roi_img, Imgproc.COLOR_Lab2BGR);
Mat roi_img2 = mat.submat(rect);
// roi_img2 = roi_img.clone();
roi_img.copyTo(roi_img2);
showMat(mat);
我犯了一个错误。我应该在 originalMat 上使用 cvtColor 函数。
我用submat功能截取了部分图片,做了一些处理。我现在有两个垫子可以用。
Mat originalMat = new Mat();
Utils.bitmapToMat(originalBmp, originalMat);
Rect rect = new Rect(left, top, right - left, bottom - top);
Mat roi_img = originalMat.submat(rect);
Imgproc.cvtColor(roi_img, roi_img, Imgproc.COLOR_BGR2Lab);
#some processing to roi_img....
Imgproc.cvtColor(roi_img, roi_img, Imgproc.COLOR_Lab2BGR);
我发现 cvtColor 函数可能会更改 roi_img 的引用。 originalMat 的处理被禁用。 originalMat 和以前一样。 我想合并 originalMat 和 roi_img。
我尝试使用 copyto 和 clone 功能,但是没有用。
Mat mat = new Mat();
Utils.bitmapToMat(originalBmp, mat);
Rect rect = new Rect(40, 40, 100, 100);
Mat roi_img = mat.submat(rect);
double[] value = new double[]{255, 255, 255};
Imgproc.cvtColor(roi_img, roi_img, Imgproc.COLOR_BGR2Lab);
for (int i = 0; i < roi_img.rows(); i++) {
for (int j = 0; j < roi_img.cols(); j++) {
roi_img.put(i, j, value);
}
}
Imgproc.cvtColor(roi_img, roi_img, Imgproc.COLOR_Lab2BGR);
Mat roi_img2 = mat.submat(rect);
// roi_img2 = roi_img.clone();
roi_img.copyTo(roi_img2);
showMat(mat);
我犯了一个错误。我应该在 originalMat 上使用 cvtColor 函数。