Reputation: 6079
I want to calculate Homography of images using OpenCV in Java, but it throws Exception: OpenCV Error: Bad argument (The input arrays should be 2D or 3D point sets) in cv::findHomography
My code is like this (because the code is very long I just posted the part of code):
....
List<Point> obj = new ArrayList<>();
List<Point> scene = new ArrayList<>();
KeyPoint[] _keypoints_object = keypoints_object.toArray();
KeyPoint[] _keypoints_scene = keypoints_scene.toArray();
for (int i = 0; i < good_matches.size(); i++) {
obj.add(_keypoints_object[good_matches.get(i).queryIdx].pt);
scene.add(_keypoints_scene[good_matches.get(i).trainIdx].pt);
}
MatOfPoint2f _obj = new MatOfPoint2f();
_obj.fromList(obj);
MatOfPoint2f _scene = new MatOfPoint2f();
_scene.fromList(scene);
**Mat H = Calib3d.findHomography(_obj, _scene, Calib3d.RANSAC, 3);**
....
No error during compiling, I have already declared a 2D Point
which is MatOfPoint2f
and compiler is accepted, but when run the code it will throws the exception. What will be the reason, is this OpenCV bug or the code has problem?
If someone knows about please tell me how to solve. Thanks in advance!
Upvotes: 0
Views: 3028
Reputation: 9
if (obj.isEmpty() || scene.isEmpty()) {
LOGGER.debug("No matches found at all.....");
}
The List of obj or scene will be empty. try to avoid findHomography when the list is empty.
Upvotes: 1