Ask Your Question
0

Most basic projectPoints example gives wrong answer

asked 2018-02-17 09:47:25 -0500

jetkaczyk gravatar image

updated 2018-02-17 12:30:35 -0500

When I run projectPoints function using java code below with most simple inputs I get what I believe is incorrect answer. Did I miss something?

I get the following result:

(x,y,z)= [{0.0, 1.0, 1.0}, {0.0, 1.0, 5.0}, {0.0, 1.0, 10.0}]
(u,v)= [{0.0, 78.5398178100586}, {0.0, 19.73955535888672}, {0.0, 9.966865539550781}]
 should be
(u,v)=[{0.0, 100.0}, {0.0, 20.0}, {0.0, 10.0}]

public static void main(String[] args) {
    setDllLibraryPath("C:/aaa_eric/code/lib/x64");
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    MatOfPoint3f objectPts3f = new MatOfPoint3f(
            new Point3(0.0,1.0, 1.0),
            new Point3(0.0,1.0, 5.0),
            new Point3(0.0,1.0,10.0));
    MatOfPoint2f imagePts2f = new MatOfPoint2f();
    Mat rVec =  Mat.zeros(3,1, CvType.CV_64F);
    Mat tVec = Mat.zeros(3,1, CvType.CV_64F);

    //camera matrix, no distortion
    Mat kMat = Mat.zeros(3, 3, CvType.CV_64F);
    kMat.put(0, 0,
            100.0, 0.0, 0.0,
            0.0, 100.0, 0.0,
            0.0, 0.0, 1.0);
    Mat dMat = Mat.zeros(4, 1, CvType.CV_64F);

    Calib3d.projectPoints(objectPts3f, imagePts2f, rVec, tVec, kMat, dMat);

    System.out.println(objectPts3f.toList());
    System.out.println(imagePts2f.toList());
}
edit retag flag offensive close merge delete

Comments

I submitted a bug report: #11099. I'll report back if I learn more

jetkaczyk gravatar imagejetkaczyk ( 2018-03-17 10:30:44 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-02-18 10:11:15 -0500

Eduardo gravatar image

Your kMat looks not correct. It is a 3x3 matrix but you filled it with 11 values.

edit flag offensive delete link more

Comments

Thanks for your answer. You are right there are 11 arguments =2+9, but I believe that is correct. The first two arguments are row_index, col_index indicating the starting point for insertion and the remaining arguments are the 3x3 matrix values to be inserted.

Here is the signature for the Mat.put() function

public int put(int row, int col, double... data)

Found here: Mat Docs

jetkaczyk gravatar imagejetkaczyk ( 2018-02-18 16:26:54 -0500 )edit

My bad, I don't use the Java bindings. The corresponding code works in C++. It should be either an issue in the code or in projectPoints Java binding. Does everything print correctly for the different matrices?

Eduardo gravatar imageEduardo ( 2018-02-19 04:38:52 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-02-17 09:47:25 -0500

Seen: 326 times

Last updated: Feb 18 '18