在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);
它在左上角绘制轮廓但我需要它在“x”,“y”的投资回报率是从哪里来的。
有没有办法给任何轮廓添加偏移?
最佳答案:
我得到了它:
Imgproc.drawContours(resultImage, contours, -1, new Scalar(255,0,0), 1, 8, hierarchy, 1, new Point(x,y));
它可以使用“点类”添加偏移量