Findhomography error 2D or 3D point sets?

3,222 views
Skip to first unread message

Dinh Thap

unread,
Jun 12, 2016, 3:07:04 PM6/12/16
to javacv
I shearing object with findHomography then get error

OpenCV Error: Bad argument (The input arrays should be 2D or 3D point sets) in cv::findHomography, file src\fundam.cpp, line 362
Exception in thread "main" java.lang.RuntimeException: src\fundam.cpp:362: error: (-5) The input arrays should be 2D or 3D point sets in function cv::findHomography

Here my code:


Rect box = rr.boundingRect();

Point2f points = new Point2f(4);
rr.points(points);

Point2f src = new Point2f(4);

src.put(points.get(0));
src.put(points.get(1));
src.put(points.get(3));
src.put(points.get(2));

Point2f dest = new Point2f(4);

dest.put(new Point2f(0,0));
dest.put(new Point2f(box.width(),0));
dest.put(new Point2f(0,box.height()));
dest.put(new Point2f(box.width(),box.height()));

Mat h = opencv_calib3d.findHomography(new Mat(src),new Mat(dest));

Mat out = new Mat();

warpPerspective(subImage,out,h,box.size(),INTER_LINEAR,BORDER_CONSTANT,Scalar.all(0));

Imshow.showMultiple("Shear",out);

Samuel Audet

unread,
Jun 14, 2016, 1:06:09 AM6/14/16
to jav...@googlegroups.com
On 06/13/2016 04:07 AM, Dinh Thap wrote:
> OpenCV Error: Bad argument (The input arrays should be 2D or 3D point sets) in cv::findHomography, file src\fundam.cpp, line 362
> Exception in thread "main" java.lang.RuntimeException: src\fundam.cpp:362: error: (-5) The input arrays should be 2D or 3D point sets in function cv::findHomography

Try to allocate your Mat objects this way:
new Mat(4, 1, CV_32FC2);

We can also put the data pointer of Points2f, for example:
new Mat(4, 1, CV_32FC2, src);

Samuel
Reply all
Reply to author
Forward
0 new messages