我编写了一些代码,它将从实际图像返回轮廓。我想访问每个轮廓,在像素级别进行一些图像处理并写回图像。
有没有办法单独访问轮廓区域并迭代该区域中的单个像素并写回图像。
Rect rect = Imgproc.boundingRect(matOfPoint);
Mat roiBox = rgbaMatrix.submat(rect)
这将返回一个子矩阵,其中也包含不属于轮廓的像素。
Please follow this link to see the screenshot of contour detections
最佳答案
我找到了一种始终保留主矩阵上下文的方法,正如 @AlexanderReynolds 建议的那样,掩蔽是提取精确区域的唯一方法。
Rect rect = Imgproc.boundingRect(matOfPoint);
Mat subMat = new Mat(mRgba,rect);
Mat zeroMat = Mat.zeros(subMat.size(),subMat.type());
zeroMat.copyTo(subMat);
这会将零矩阵复制到原始矩阵
关于java - 如何在android中使用opencv访问轮廓区域内的像素并写回原始图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44887811/