2016-11-14 100 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 - 這樣解釋,我需要強調嘗試