Opencv Java fillConvexPoly和approxPolyDP函数

时间:2016-11-14 13:33:33

标签: java c++ opencv

我的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 ++那样简单。

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

1 个答案:

答案 0 :(得分:1)

尝试

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

Doc - 说明我需要强调尝试