2017-07-03 39 views
0

我写过一些代码,它将从实际图像中返回轮廓。我想访问每个轮廓,在像素级进行一些图像处理并写回图像。如何访问轮廓区域内的像素,并使用Android中的opencv回写原始图像

有没有办法单独访问轮廓区域,并遍历区域中的单个像素并写回图像。

 Rect rect = Imgproc.boundingRect(matOfPoint); 
     Mat roiBox = rgbaMatrix.submat(rect) 

这将返回一个子矩阵,其中也包含不属于轮廓的像素。

Please follow this link to see the screenshot of contour detections

+0

我认为最简单的方式是通过绘制你的轮廓为白色填充多边形新的黑色图像上创建蒙版。 –

回答

0

我发现的一种方法,它总存放在主基体的背景下,作为@AlexanderReynolds建议掩蔽是提取确切区域的唯一方式。

Rect rect = Imgproc.boundingRect(matOfPoint); 
Mat subMat = new Mat(mRgba,rect); 
Mat zeroMat = Mat.zeros(subMat.size(),subMat.type()); 
zeroMat.copyTo(subMat); 

这会将零矩阵的原矩阵

相关问题