Opencv Java填充convexpoly和approxPolyDP函数

Opencv Java fillConvexPoly and approxPolyDP functions

本文关键字:approxPolyDP 函数 convexpoly Java 填充 Opencv      更新时间:2023-10-16

我的c++代码如下:

// ROI by creating mask for the trapezoid
Mat mask = Mat(frame.rows, frame.cols, CV_8UC1, Scalar(0));
// Create Polygon from vertices
approxPolyDP(pointsForTrapezoid, roiPolygonized, 1.0, true);
// Fill polygon white
fillConvexPoly(mask, &roiPolygonized[0], roiPolygonized.size(), 255, 8, 0);

,我想转换为Java,因为我将在Java中使用OpenCV从现在开始。

在Java中,我尝试了以下操作:

    // ROI by creating mask for the trapezoid
    Mat mask = new Mat(frame.rows(), frame.cols(), CvType.CV_8UC1, new Scalar(0));
    // Create Polygon from vertices
    MatOfPoint2f tmpTrapeziod = new MatOfPoint2f();
    MatOfPoint2f tmpROI = new MatOfPoint2f();
    tmpTrapeziod.fromList(pointsForTrapezoid);
    tmpROI.fromList(roiPolygonized);
    Imgproc.approxPolyDP(tmpTrapeziod, tmpROI, 1.0, true);
    // Fill polygon white
    Imgproc.fillConvexPoly(mask, tmpROI, new Scalar(255), 8, 0);

然而,最后一行给出的错误是:

The method fillConvexPoly(Mat, MatOfPoint, Scalar, int, int) in the type Imgproc is not applicable for the arguments (Mat, MatOfPoint2f, Scalar, int, int)

我现在对MatOfPointMatOfPoint2f的类型很困惑,似乎不像c++那么简单。

有人遇到过类似的问题吗?

Try

Imgproc.fillConvexPoly(mask, new MatOfPoint(tmpROI), new Scalar(255), 8, 0);

Doc -如此解释,我需要强调尝试