2015-05-09 70 views
1

我正在爲android的opencv項目工作。我需要將變量從MatOfPoint2f轉換爲MatOfPoint。以下是我的代碼的相關部分:approxMatOfPoint2f類型,我需要轉換它,因爲drawContours使用類型ArrayList<MatOfPoint>將MatOfPoint2f轉換爲MatOfPoint

Imgproc.approxPolyDP(newMtx, approx, 0.02*peri, true); 
approxMatOfPoint = (MatOfPoint) approx; // to convert 
ArrayList<MatOfPoint> p = new ArrayList<>(); 
p.add(approxMatOfPoint); 
Imgproc.drawContours(img, p, 0, new Scalar(0,255,0), 2); 

回答

0

我解決了執行以下操作:

MatOfPoint approxf1 = new MatOfPoint(); 
... 

Imgproc.approxPolyDP(newMtx, approx, 0.02*peri, true); 
approx.convertTo(approxf1, CvType.CV_32S); 
List<MatOfPoint> contourTemp = new ArrayList<>(); 
contourTemp.add(approxf1); 
Imgproc.drawContours(img, contourTemp, 0, new Scalar(0, 255, 0), 2); 

乾杯。