I am using the following code to clone my array:
aproximatedContours = cloneList(contours);
The body of method:
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;
}
However, even though both contours and clone are type of ArrayList, and obviously their elements are type of MatOfPoint, I get the following error:
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)
Does anyone have an idea what is happeining here?