I want to use getPerspectiveTransform function, but it only accepts Mat as arguments and I have coordinate data in an array. So I convert them into points and then to Mat as follows:
List<Point> l = new ArrayList<Point>();
for (int i = 0; i < pts_1.length; i++) {
Point pt = new Point(pts_1[0][i], pts_1[1][i]);
l.add(i,pt);
}
Mat mat1 = Converters.vector_Point2f_to_Mat(l);
for (int i = 0; i < pts_2.length; i++) {
Point pt = new Point(pts_2[0][i], pts_2[1][i]);
l.add(i,pt);
}
Mat mat2 = Converters.vector_Point2f_to_Mat(l);
Mat perspectiveTransform = Imgproc.getPerspectiveTransform(mat1,mat2);
But when I run my app, then it gives me error 'Something went wrong', and in logcat I am getting the following error:
E/cv::error(): OpenCV Error: Assertion failed (src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4) in cv::Mat cv::getPerspectiveTransform(cv::InputArray, cv::InputArray), file /build/master_pack-android/opencv/modules/imgproc/src/imgwarp.cpp, line 6748
E/org.opencv.imgproc: imgproc::getPerspectiveTransform_10() caught cv::Exception: /build/master_pack-android/opencv/modules/imgproc/src/imgwarp.cpp:6748: error: (-215) src.checkVector(2, CV_32F) == 4 && dst.checkVector(2, CV_32F) == 4 in function cv::Mat cv::getPerspectiveTransform(cv::InputArray, cv::InputArray)
I am new to OpenCV4Android so I don't understand why this is happening. How to fix it? Is there any other better way to do this?
Thanks for help!
Note: I know that a similar procedure is followed here: Can't get OpenCV's warpPerspective to work on Android but he is not getting this error, so I am posting it here.