【发布时间】:2017-07-31 08:57:07
【问题描述】:
如何仅在黑色对象上绘制轮廓,并将背景中的其他所有内容填充为白色? 我的代码目前能够在图像上绘制轮廓:
Bitmap b = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);
srcMat= new Mat();
Utils.bitmapToMat(b,srcMat);
Mat gray = new Mat();
Imgproc.cvtColor(srcMat, gray, Imgproc.COLOR_RGBA2GRAY);
Imgproc.Canny(gray, gray, 20, 20*3, 3, true);
List<MatOfPoint> contours = new ArrayList<>();
Mat hierarchy = new Mat();
Imgproc.findContours(gray,contours,hierarchy,Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);
for (int contourIdx = 0; contourIdx < contours.size(); contourIdx++) {
Imgproc.drawContours(srcMat, contours, contourIdx, new Scalar(0, 0, 255), -1);
}
Utils.matToBitmap(gray, b);
imgR.setImageBitmap(b);
【问题讨论】:
-
您想通过创建轮廓或您在这里谈论的其他类型的轮廓来创建图像的蒙版。请提供您尝试实现的输出。
标签: android opencv image-processing mask opencv-contour