1 | initial version |
I did this tutorial in Android... I think you have a type problem again.. :) Here is my solution with "Mat" for the corners:
Mat hg = Calib3d.findHomography(obj, scene);
Mat obj_corners = new Mat(4,1,CvType.CV_32FC2);
Mat scene_corners = new Mat(4,1,CvType.CV_32FC2);
obj_corners.put(0, 0, new double[] {0,0});
obj_corners.put(1, 0, new double[] {mat2.cols(),0});
obj_corners.put(2, 0, new double[] {mat2.cols(),mat2.rows()});
obj_corners.put(3, 0, new double[] {0,mat2.rows()});
Core.perspectiveTransform(obj_corners,scene_corners, hg);
Core.line(mat, new Point(scene_corners.get(0,0)), new Point(scene_corners.get(1,0)), new Scalar(0, 255, 0),4);
Core.line(mat, new Point(scene_corners.get(1,0)), new Point(scene_corners.get(2,0)), new Scalar(0, 255, 0),4);
Core.line(mat, new Point(scene_corners.get(2,0)), new Point(scene_corners.get(3,0)), new Scalar(0, 255, 0),4);
Core.line(mat, new Point(scene_corners.get(3,0)), new Point(scene_corners.get(0,0)), new Scalar(0, 255, 0),4);