1

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

我可以在 的文档上Mat看到三种有趣的方法,

Mat submat(int rowStart, int rowEnd, int colStart, int colEnd) 提取一个矩形子矩阵。

Mat submat(Range rowRange, Range colRange) 提取一个矩形子矩阵。

Mat submat(Rect roi) 提取一个矩形子矩阵。

  1. 有没有办法从轮廓中 找出rowStart,rowEnd和?colStartcolEnd

或者

  1. 有没有办法从轮廓中获取rowRange和获取?colRange

或者

  1. 我可以Rect从轮廓上做一个吗?
4

1 回答 1

2

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

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

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

于 2016-04-20T00:31:32.157 回答