我正在使用以下代码克隆我的数组:
aproximatedContours = cloneList(contours);
方法体:
public static ArrayList<MatOfPoint> cloneList(ArrayList<MatOfPoint> contours) {
ArrayList<MatOfPoint> clone = new ArrayList<MatOfPoint>(contours.size());
for(MatOfPoint item: contours)
clone.add((MatOfPoint) item.clone()); // Line 479
return clone;
}
但是,即使轮廓和克隆都是 ArrayList 的类型,并且显然它们的元素是 MatOfPoint 的类型,我也会收到以下错误:
08-16 16:34:16.015: W/System.err(21747): java.lang.ClassCastException: org.opencv.core.Mat cannot be cast to org.opencv.core.MatOfPoint
08-16 16:34:16.020: W/System.err(21747): at com.example.objecttracker.ObjectTracker.cloneList(ObjectTracker.java:469)
08-16 16:34:16.020: W/System.err(21747): at com.example.objecttracker.ObjectTracker.onCameraFrame(ObjectTracker.java:446)
08-16 16:34:16.020: W/System.err(21747): at org.opencv.android.CameraBridgeViewBase.deliverAndDrawFrame(CameraBridgeViewBase.java:387)
08-16 16:34:16.020: W/System.err(21747): at org.opencv.android.JavaCameraView$CameraWorker.run(JavaCameraView.java:321)
08-16 16:34:16.025: W/System.err(21747): at java.lang.Thread.run(Thread.java:856)
有谁知道这里发生了什么?