使用 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.
- 有没有办法找出
rowStart
、rowEnd
、colStart
和
colEnd
从等高线?
或
- 有没有办法从轮廓中得到
rowRange
和 colRange
?
或
- 我可以根据等高线做一个
Rect
吗?
使用Imgproc.boundingRect(MatOfPoint contour)
方法。这样您就可以使用您列出的 submat()
方法中的第三种:
Rect roiRect = Imgproc.boundingRect(contour);
Mat roiSubmat = originalMat.submat(roiRect);
roiSubmat
是您感兴趣的区域(存储在 Mat 中)。
给定图像 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.
- 有没有办法找出
rowStart
、rowEnd
、colStart
和colEnd
从等高线?
或
- 有没有办法从轮廓中得到
rowRange
和colRange
?
或
- 我可以根据等高线做一个
Rect
吗?
使用Imgproc.boundingRect(MatOfPoint contour)
方法。这样您就可以使用您列出的 submat()
方法中的第三种:
Rect roiRect = Imgproc.boundingRect(contour);
Mat roiSubmat = originalMat.submat(roiRect);
roiSubmat
是您感兴趣的区域(存储在 Mat 中)。