【问题标题】:How to set Region of Interest around bounding rectangle in android using opecv如何使用opencv在android中的边界矩形周围设置感兴趣区域
【发布时间】:2017-08-27 20:42:06
【问题描述】:

我在图像中检测到轮廓。检测轮廓后,我根据区域过滤轮廓。然后我在车牌周围画了一个边界矩形,只围绕一个轮廓。

如何裁剪剩余的图像并仅获取绘制的矩形区域,即我只想获取已绘制矩形的车牌。我没有矩形坐标。我只是在opencv中使用Core.rectangle()函数来绘制一个矩形。

谁能帮我解决这个问题。请在 android + opencv 中提供代码,我可以使用它来获得所需的结果。我还附上一张图片。Here I have drawn rectangle using Core.rectangle(). I want to get the rectangle part and crop other part.

【问题讨论】:

标签: android opencv image-processing opencv4android opencv-contour


【解决方案1】:
  List<MatOfPoint> contour = new ArrayList<MatOfPoint>();
                Mat hierarch = new Mat();
                //find contours
                Imgproc.findContours(gray1, contour, hierarch, Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);
                //itrerate through each contour
                for (int Idx = 0; Idx < contours.size(); Idx++) {
                    double area = Imgproc.contourArea(contours.get(contourIdx));
                    if (area > largest_area) {
                        largest_area = (int) area1;
                        largest_contour_index = Idx;
                        Rect bounding_rect = Imgproc.boundingRect(contour.get(Idx));
                        Mat img = ROI.submat(bounding_rect1);

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

                    }

                }

【讨论】:

  • 虽然这段代码 sn-p 可以解决问题,但including an explanation 确实有助于提高您的帖子质量。请记住,您正在为将来的读者回答问题,而这些人可能不知道您的代码建议的原因。也请尽量不要用解释性的 cmets 挤满你的代码,这会降低代码和解释的可读性!
猜你喜欢
  • 2013-02-28
  • 1970-01-01
  • 2014-07-06
  • 2018-12-02
  • 1970-01-01
  • 2012-04-25
  • 1970-01-01
  • 2013-03-03
  • 1970-01-01
相关资源
最近更新 更多