【问题标题】:how to draw contours and create a bounding rectangle on an image, using android and openCV如何使用android和openCV在图像上绘制轮廓并创建边界矩形
【发布时间】:2017-08-26 17:31:35
【问题描述】:

如何在android中绘制轮廓并在图像上创建边界矩形?

到目前为止我有什么,

    Mat imageMat = new Mat();

    Utils.bitmapToMat(photo, imageMat);
    Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_BGR2GRAY);
       Imgproc.adaptiveThreshold(imageMat, imageMat, 255,
           Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 7, 7);
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Mat hierarchy = new Mat();
    Imgproc.findContours(imageMat, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);


    Bitmap resultBitmap = Bitmap.createBitmap(imageMat.cols(), imageMat.rows(), Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(imageMat, resultBitmap);
    ((ImageView) findViewById(R.id.imageView)).setImageBitmap(resultBitmap);

【问题讨论】:

  • 我的意思是说……我们怎么画……
  • 看看drawContoursboundingRect方法

标签: android opencv


【解决方案1】:

查看here 的文档DrawContours 方法,您可以关注this example

至于边界矩形,请查看上面链接的相同文档,并且(遵循this example)有

List<Rect> boundingRects = new List<Rect>();
for (MatOfPoint points : contours){
    boundingRects.append(Imgproc.boundingRect(points));
}

虽然我还没有测试过代码(目前还不能),但这应该可以解决您的问题(示例在我看来是合理的,并且它们是针对类似问题的确认解决方案)。

告诉我!

【讨论】:

  • 让我试一试。
  • 轮廓颜色改变后还是黑白的,不知道为什么?!
  • 你在哪里画的?请用新代码更新问题
  • 如果你告诉我如何实现 thisList boundingRects = new List(); for (MatOfPoint points : contours){ boundingRects.append(Imgproc.boundingRect(points)); }
  • 我在图像中的矩形周围绘制轮廓,然后裁剪出最大的矩形,这是项目的目标。
猜你喜欢
  • 2015-08-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-27
  • 2013-05-08
  • 2018-03-13
  • 1970-01-01
  • 2014-05-21
相关资源
最近更新 更多