Ask Your Question

Revision history [back]

Most basic projectPoints example gives wrong answer

When I run projectPoints function using kotlin 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}]
fun main(args : Array<String>) {
    setDllLibraryPath("C:/aaa_eric/code/lib/x64")
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
    val objectPts3f = MatOfPoint3f(Point3(0.0,1.0,1.0),Point3(0.0,1.0,5.0),Point3(0.0,1.0,10.0))
    val imagePts2f = MatOfPoint2f()
    val rVec =  Mat.zeros(3,1, CvType.CV_64F)
    val tVec = Mat.zeros(3,1, CvType.CV_64F)
    val mag = 100.0
    println(objectPts3f.toList())
    //camera matrix, no distortion
    val kMat = array2Mat(3, CvType.CV_64F,
            arrayOf(mag, 0.0, 0.0,
                    0.0, mag, 0.0,
                    0.0, 0.0, 1.0))
    val dMat = Mat.zeros(4, 1, CvType.CV_64F)
    Calib3d.projectPoints(objectPts3f, imagePts2f, rVec, tVec, kMat, dMat)
    println(imagePts2f.toList())
}

Most basic projectPoints example gives wrong answer

When I run projectPoints function using kotlin 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}]
fun main(args : Array<String>) {
    setDllLibraryPath("C:/aaa_eric/code/lib/x64")
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
    //
    val objectPts3f = MatOfPoint3f(Point3(0.0,1.0,1.0),Point3(0.0,1.0,5.0),Point3(0.0,1.0,10.0))
    val imagePts2f = MatOfPoint2f()
    val rVec =  Mat.zeros(3,1, CvType.CV_64F)
    val tVec = Mat.zeros(3,1, CvType.CV_64F)
    val mag = 100.0
    //
    println(objectPts3f.toList())
    //
    //camera matrix, no distortion
    val kMat = array2Mat(3, CvType.CV_64F,
            arrayOf(mag, Mat.zeros(3, 3, CvType.CV_64F)
    kMat.put(0, 0, 
            mag, 0.0, 0.0,
             0.0, mag, 0.0,
                    0.0, 0.0, 1.0))
0.0, 0.0, 1.0)
    val dMat = Mat.zeros(4, 1, CvType.CV_64F)
    //
    Calib3d.projectPoints(objectPts3f, imagePts2f, rVec, tVec, kMat, dMat)
    //
    println(imagePts2f.toList())
}

Most basic projectPoints example gives wrong answer

When I run projectPoints function using kotlin 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}]
fun main(args : Array<String>) {
    setDllLibraryPath("C:/aaa_eric/code/lib/x64")
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
    //
    val objectPts3f = MatOfPoint3f(Point3(0.0,1.0,1.0),Point3(0.0,1.0,5.0),Point3(0.0,1.0,10.0))
    val imagePts2f = MatOfPoint2f()
    val rVec =  Mat.zeros(3,1, CvType.CV_64F)
    val tVec = Mat.zeros(3,1, CvType.CV_64F)
    val mag = 100.0
    //
    println(objectPts3f.toList())
    //
    //camera matrix, no distortion
    val mag = 100.0
    val kMat = Mat.zeros(3, 3, CvType.CV_64F)
    kMat.put(0, 0, 
            mag, 0.0, 0.0,
            0.0, mag, 0.0,
            0.0, 0.0, 1.0)
    val dMat = Mat.zeros(4, 1, CvType.CV_64F)
    //
    Calib3d.projectPoints(objectPts3f, imagePts2f, rVec, tVec, kMat, dMat)
    //
    println(imagePts2f.toList())
}

Most basic projectPoints example gives wrong answer

When I run projectPoints function using kotlin 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}]
fun main(args : Array<String>) 
public static void main(String[] args) {
    setDllLibraryPath("C:/aaa_eric/code/lib/x64")
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME)
    //
    val setDllLibraryPath("C:/aaa_eric/code/lib/x64");
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    MatOfPoint3f objectPts3f = MatOfPoint3f(Point3(0.0,1.0,1.0),Point3(0.0,1.0,5.0),Point3(0.0,1.0,10.0))
    val 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 = MatOfPoint2f()
    val new MatOfPoint2f();
    Mat rVec =  Mat.zeros(3,1, CvType.CV_64F)
    val CvType.CV_64F);
    Mat tVec = Mat.zeros(3,1, CvType.CV_64F)
    //
    println(objectPts3f.toList())
    //
CvType.CV_64F);

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

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

    System.out.println(objectPts3f.toList());
    System.out.println(imagePts2f.toList());
}