Opencv Java fillConvexPoly 和 approxPolyDP 函数
Opencv Java fillConvexPoly and approxPolyDP functions
我的 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)
目前我对 MatOfPoint
和 MatOfPoint2f
类型感到很困惑,似乎它不像 C++ 中那么简单。
有人遇到过类似的问题吗?
尝试
Imgproc.fillConvexPoly(mask, new MatOfPoint(tmpROI), new Scalar(255), 8, 0);
Doc - 如此解释以至于我需要强调 Try
我的 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)
目前我对 MatOfPoint
和 MatOfPoint2f
类型感到很困惑,似乎它不像 C++ 中那么简单。
有人遇到过类似的问题吗?
尝试
Imgproc.fillConvexPoly(mask, new MatOfPoint(tmpROI), new Scalar(255), 8, 0);
Doc - 如此解释以至于我需要强调 Try