我在图像中检测到轮廓。检测轮廓后,我根据面积过滤了轮廓。然后,我围绕牌照板(仅围绕一个轮廓)绘制了一个边界矩形。
如何裁剪剩余的图像并仅获得绘制矩形的区域,也就是说,我只想获得在其周围绘制矩形的牌照。我没有矩形坐标。我只是在opencv中使用Core.rectangle()函数绘制一个矩形。
谁能帮我这个。请提供android + opencv中的代码,使用它们我可以产生所需的结果。我还附有图片。 Here I have drawn rectangle using Core.rectangle(). I want to get the rectangle part and crop other part.
最佳答案
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);
}
}
关于android - 如何使用opencv在android中设置边界矩形周围的感兴趣区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43176886/