2016-11-14 105 views
1

我有以下我的C++代码:opencv实现的Java fillConvexPoly和approxPolyDP功能

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

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

+0

我不知道太多的Java做的,但方法签名表示它接受'MatOfPoint'不'MatOfPoint2f'所以它希望int coords不浮动coords – EdChum

+0

如果我这样做,那么其他函数会给出错误。 –

+0

在C++版本中,我所做的只是在矢量中收集点,然后将这个矢量传递给绘制和填充梯形的这些函数。我想在Java中做同样的事情,出于某种原因,我面临着很多问题。 –

回答

1

尝试

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

Doc - 这样解释,我需要强调尝试