2

在 Android 上,通过使用 OpenCV,我尝试绘制从 ROI 获得的轮廓,但我无法在图像的正确位置绘制它们。

Mat resultImage= ...; // source

Rect roi = new Rect(x, y, widht, height);
Mat mat = new Mat(resultImage, roi);

Imgproc.adaptiveThreshold(mat, mat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY_INV, 15, 4);

mat.convertTo(mat, CvType.CV_32SC1);

List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
Mat hierarchy = new Mat();
Imgproc.findContours(mat, contours, hierarchy, Imgproc.RETR_FLOODFILL, Imgproc.CHAIN_APPROX_SIMPLE);

mat.release();

Imgproc.drawContours(resultImage, contours, -1, new Scalar(255,0,0), 1);

它在左上角绘制轮廓。但我需要它在 ROI 来自的“x”、“y”。

有没有办法为任何轮廓添加偏移量?

4

1 回答 1

1

我得到了它:

Imgproc.drawContours(resultImage, contours, -1, new Scalar(255,0,0), 1, 8, hierarchy, 1, new Point(x,y));

它可以通过使用“Point-Class”来添加偏移量

于 2013-04-03T14:15:14.917 回答