3

A get the following error when executing my code:

Caused by: CvException [org.opencv.core.CvException: cv::Exception: /home/reports/ci/slave_desktop/50-SDK/opencv/modules/calib3d/src/fundam.cpp:1152: error: (-215) npoints >= 0 && (src.depth() == CV_32F || src.depth() == CV_32S) in function void cv::convertPointsFromHomogeneous(cv::InputArray, cv::OutputArray)

Here is the code I am using:

    Mat res = new Mat(); // Result mat for triangulation

    Mat P1 = new Mat(3,4,CvType.CV_32F);
    double[] diagVal = {1,0,0,0,
                        0,1,0,0,
                        0,0,1,0};       
    P1.put(0, 0, diagVal);



    int[] max = new int[4];
    for(int i = 0; i < max.length; i++)
        max[i] = 0;

    Mat P2 = buildCameraMatrix(R1, T1);     
    Calib3d.triangulatePoints(P1, P2, objLeft, objRight, res);

TriangulatePoints results in a (914,4) Mat of Type CV_32F (res.type() == 5 is true).

What Am I doing wrong?

glethien
  • 2,440
  • 2
  • 26
  • 36

1 Answers1

1

I use the following conversion function instead:

private Mat convertPointsFromHomogeneous(Mat src) {
    Mat ret = new Mat(3, src.cols(), src.type());
    double[] data = new double[4];
    for (int i = 0; i < src.cols(); i++) {
        src.col(i).get(0, 0, data);
        ret.col(i).put(0, 0, data[0] / data[3], data[1] / data[3], data[2] / data[3]);
    }
    return ret;
}
M. Noreikis
  • 173
  • 6