使用 OpenCV4Android,如何从轮廓创建 ROI(感兴趣区域或子垫)?

Using OpenCV4Android, how to create an ROI (Region-Of-Interest or a submat) from a contour?

给定图像 Mat 和其中的轮廓(即 MatOfPoint),如何创建 ROI(感兴趣区域)/submat?

我可以在 docs of Mat,

上看到三个有趣的方法

Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) Extracts a rectangular submatrix.

Mat submat(Range rowRange, Range colRange) Extracts a rectangular submatrix.

Mat submat(Rect roi) Extracts a rectangular submatrix.

  1. 有没有办法找出 rowStartrowEndcolStartcolEnd 从等高线?

  1. 有没有办法从轮廓中得到 rowRangecolRange

  1. 我可以根据等高线做一个Rect吗?

使用Imgproc.boundingRect(MatOfPoint contour)方法。这样您就可以使用您列出的 submat() 方法中的第三种:

Rect roiRect = Imgproc.boundingRect(contour);
Mat roiSubmat = originalMat.submat(roiRect);

roiSubmat 是您感兴趣的区域(存储在 Mat 中)。