Ask Your Question

Revision history [back]

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it,. This is how it is done:

    cv::solvePnPRansac(constants::calibration::rig.rig3DPoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(constants::calibration::rig.rig3DPoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                        points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                        points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

 point: [-0.0113968, -0.0236187, -0.000169321]
 point: [-0.0113949, -0.0236159, -0.000168893]
 point: [-0.011395, -0.0236219, -0.000169062]
 point: [-0.0113946, -0.0236289, -0.000169148]
 point: [-0.0113922, -0.0236095, -0.000168429]
 point: [-0.0113952, -0.0236172, -0.000168985]
 point: [-0.0113946, -0.0236198, -0.000168924]
 point: [-0.0113956, -0.0236198, -0.000169066]
 point: [-0.0113944, -0.0236077, -0.000168686]
 point: [-0.0113954, -0.0236207, -0.000169061]
 point: [-0.0113957, -0.0236164, -0.00016904]
 point: [-0.0113953, -0.0236187, -0.000169051]
 point: [-0.0113926, -0.0236058, -0.000168453]
 point: [-0.0113951, -0.0236117, -0.000168868]
 point: [-0.0113946, -0.0236115, -0.000168785]
 point: [-0.0113956, -0.0236141, -0.00016902]
 point: [-0.0113964, -0.0236195, -0.000169284]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, I mean they too close to zero, may be I am doing something wrong?

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it,. This is how it is done:

    cv::solvePnPRansac(constants::calibration::rig.rig3DPoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(constants::calibration::rig.rig3DPoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                        points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                        points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

 point: [-0.0113968, -0.0236187, -0.000169321]
 point: [-0.0113949, -0.0236159, -0.000168893]
 point: [-0.011395, -0.0236219, -0.000169062]
 point: [-0.0113946, -0.0236289, -0.000169148]
 point: [-0.0113922, -0.0236095, -0.000168429]
 point: [-0.0113952, -0.0236172, -0.000168985]
 point: [-0.0113946, -0.0236198, -0.000168924]
 point: [-0.0113956, -0.0236198, -0.000169066]
 point: [-0.0113944, -0.0236077, -0.000168686]
 point: [-0.0113954, -0.0236207, -0.000169061]
 point: [-0.0113957, -0.0236164, -0.00016904]
 point: [-0.0113953, -0.0236187, -0.000169051]
 point: [-0.0113926, -0.0236058, -0.000168453]
 point: [-0.0113951, -0.0236117, -0.000168868]
 point: [-0.0113946, -0.0236115, -0.000168785]
 point: [-0.0113956, -0.0236141, -0.00016902]
 point: [-0.0113964, -0.0236195, -0.000169284]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, I mean they too close to zero, may be I am doing something wrong?wrong? Here is additional prints for calculated data above:

[INFO] solvePnP: R: 
[INFO] [0.9588095856998964, -0.01481623915967968, 0.2836629292437701;
        0.01116279977923707, 0.9998326771368026, 0.01449170902768135;
       -0.2838301785770527, -0.0107283170449745, 0.9588145456459767]
[INFO] solvePnP: t: 
[INFO] [0.09641053427352947;
       -0.007467030698232915;
       -0.004027662235745022]
[INFO] 
[INFO] classes1: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords1: [194, 310] [209, 281] [226, 297] [248, 309] [240, 256] [211, 288] [219, 286] [206, 293] [205, 264] [210, 294] [200, 290] [216, 294] [234, 256] [200, 277] [206, 272] [198, 289] [203, 309]
[INFO] classes2: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords2:  [170.45, 307.344] [197.65, 287.464] [202.516, 300.729] [222.787, 306.736] [225.922, 250.291] [192.545, 293.876] [211.48, 289.716] [195.62, 299.105] [182.568, 275.265] [201.421, 297.509] [186.086, 294.605] [191.875, 297.952] [207.761, 250.645] [183.286, 284.2] [189.868, 280.667] [183.016, 288.224] [175.638, 307.159]
[INFO] Fused points:17
[INFO] points4d: [-0.011392879, -0.011390963, -0.011391113, -0.011390729,  -0.011388315, -0.011391266, -0.011390734, -0.011391651,  -0.011390463, -0.01139148, -0.011391737, -0.011391368,   -0.011388648, -0.011391174, -0.011390719, -0.011391672,  -0.011392521;
-0.023610568, -0.023607768, -0.023613777, -0.023620741, -0.02360137, -0.023609081,  -0.023611726, -0.023611646, -0.023599626, -0.023612563, -0.023608256, -0.023610609,  -0.023597704, -0.023603573, -0.023603428, -0.02360598, -0.023611398;
-0.000169263, -0.00016883481, -0.00016900359, -0.00016908991,   -0.00016837115, -0.000168927, -0.00016886617, -0.000169008, -0.00016862774, -0.00016900313, -0.00016898234, -0.00016899274, -0.00016839473, -0.00016881016, -0.00016872659, -0.00016896238, -0.00016922595;
0.99965632, 0.99965638, 0.99965626, 0.99965608, 0.99965656, 0.99965638, 0.99965632, 0.99965626, 0.99965656, 0.99965626, 0.99965638, 0.99965632, 0.99965668, 0.9996565, 0.9996565,  0.99965644, 0.99965626]

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it,. it. This is how it is done:

 cv::solvePnPRansac(constants::calibration::rig.rig3DPoints, cv::solvePnPRansac(objpoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(constants::calibration::rig.rig3DPoints, cv::solvePnPRansac(objpoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                     points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                    points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

 point: [-0.0113968, -0.0236187, -0.000169321]
 point: [-0.0113949, -0.0236159, -0.000168893]
 point: [-0.011395, -0.0236219, -0.000169062]
 point: [-0.0113946, -0.0236289, -0.000169148]
 point: [-0.0113922, -0.0236095, -0.000168429]
 point: [-0.0113952, -0.0236172, -0.000168985]
 point: [-0.0113946, -0.0236198, -0.000168924]
 point: [-0.0113956, -0.0236198, -0.000169066]
 point: [-0.0113944, -0.0236077, -0.000168686]
 point: [-0.0113954, -0.0236207, -0.000169061]
 point: [-0.0113957, -0.0236164, -0.00016904]
 point: [-0.0113953, -0.0236187, -0.000169051]
 point: [-0.0113926, -0.0236058, -0.000168453]
 point: [-0.0113951, -0.0236117, -0.000168868]
 point: [-0.0113946, -0.0236115, -0.000168785]
 point: [-0.0113956, -0.0236141, -0.00016902]
 point: [-0.0113964, -0.0236195, -0.000169284]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, I mean they too close to zero, may be I am doing something wrong? Here is additional prints for calculated data above:

[INFO] solvePnP: R: 
[INFO] [0.9588095856998964, -0.01481623915967968, 0.2836629292437701;
        0.01116279977923707, 0.9998326771368026, 0.01449170902768135;
       -0.2838301785770527, -0.0107283170449745, 0.9588145456459767]
[INFO] solvePnP: t: 
[INFO] [0.09641053427352947;
       -0.007467030698232915;
       -0.004027662235745022]
[INFO] 
[INFO] classes1: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords1: [194, 310] [209, 281] [226, 297] [248, 309] [240, 256] [211, 288] [219, 286] [206, 293] [205, 264] [210, 294] [200, 290] [216, 294] [234, 256] [200, 277] [206, 272] [198, 289] [203, 309]
[INFO] classes2: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords2:  [170.45, 307.344] [197.65, 287.464] [202.516, 300.729] [222.787, 306.736] [225.922, 250.291] [192.545, 293.876] [211.48, 289.716] [195.62, 299.105] [182.568, 275.265] [201.421, 297.509] [186.086, 294.605] [191.875, 297.952] [207.761, 250.645] [183.286, 284.2] [189.868, 280.667] [183.016, 288.224] [175.638, 307.159]
[INFO] Fused points:17
[INFO] points4d: [-0.011392879, -0.011390963, -0.011391113, -0.011390729,  -0.011388315, -0.011391266, -0.011390734, -0.011391651,  -0.011390463, -0.01139148, -0.011391737, -0.011391368,   -0.011388648, -0.011391174, -0.011390719, -0.011391672,  -0.011392521;
-0.023610568, -0.023607768, -0.023613777, -0.023620741, -0.02360137, -0.023609081,  -0.023611726, -0.023611646, -0.023599626, -0.023612563, -0.023608256, -0.023610609,  -0.023597704, -0.023603573, -0.023603428, -0.02360598, -0.023611398;
-0.000169263, -0.00016883481, -0.00016900359, -0.00016908991,   -0.00016837115, -0.000168927, -0.00016886617, -0.000169008, -0.00016862774, -0.00016900313, -0.00016898234, -0.00016899274, -0.00016839473, -0.00016881016, -0.00016872659, -0.00016896238, -0.00016922595;
0.99965632, 0.99965638, 0.99965626, 0.99965608, 0.99965656, 0.99965638, 0.99965632, 0.99965626, 0.99965656, 0.99965626, 0.99965638, 0.99965632, 0.99965668, 0.9996565, 0.9996565,  0.99965644, 0.99965626]

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it. This is how it is done:

    cv::solvePnPRansac(objpoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(objpoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                    points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                   points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

 point: [-0.0113968, -0.0236187, -0.000169321]
 point: [-0.0113949, -0.0236159, -0.000168893]
 point: [-0.011395, -0.0236219, -0.000169062]
 point: [-0.0113946, -0.0236289, -0.000169148]
 point: [-0.0113922, -0.0236095, -0.000168429]
 point: [-0.0113952, -0.0236172, -0.000168985]
 point: [-0.0113946, -0.0236198, -0.000168924]
 point: [-0.0113956, -0.0236198, -0.000169066]
 point: [-0.0113944, -0.0236077, -0.000168686]
 point: [-0.0113954, -0.0236207, -0.000169061]
 point: [-0.0113957, -0.0236164, -0.00016904]
 point: [-0.0113953, -0.0236187, -0.000169051]
 point: [-0.0113926, -0.0236058, -0.000168453]
 point: [-0.0113951, -0.0236117, -0.000168868]
 point: [-0.0113946, -0.0236115, -0.000168785]
 point: [-0.0113956, -0.0236141, -0.00016902]
 point: [-0.0113964, -0.0236195, -0.000169284]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, I mean they too close to zero, may be I am doing something wrong? Here is additional prints for calculated data above:

[INFO] solvePnP: R: 
[INFO] [0.9588095856998964, -0.01481623915967968, 0.2836629292437701;
        0.01116279977923707, 0.9998326771368026, 0.01449170902768135;
       -0.2838301785770527, -0.0107283170449745, 0.9588145456459767]
[INFO] solvePnP: t: 
[INFO] [0.09641053427352947;
       -0.007467030698232915;
       -0.004027662235745022]
[INFO] 
[INFO] classes1: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords1: [194, 310] [209, 281] [226, 297] [248, 309] [240, 256] [211, 288] [219, 286] [206, 293] [205, 264] [210, 294] [200, 290] [216, 294] [234, 256] [200, 277] [206, 272] [198, 289] [203, 309]
[INFO] classes2: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords2:  [170.45, 307.344] [197.65, 287.464] [202.516, 300.729] [222.787, 306.736] [225.922, 250.291] [192.545, 293.876] [211.48, 289.716] [195.62, 299.105] [182.568, 275.265] [201.421, 297.509] [186.086, 294.605] [191.875, 297.952] [207.761, 250.645] [183.286, 284.2] [189.868, 280.667] [183.016, 288.224] [175.638, 307.159]
[INFO] Fused points:17
[INFO] points4d: [-0.011392879, -0.011390963, -0.011391113, -0.011390729,  -0.011388315, -0.011391266, -0.011390734, -0.011391651,  -0.011390463, -0.01139148, -0.011391737, -0.011391368,   -0.011388648, -0.011391174, -0.011390719, -0.011391672,  -0.011392521;
-0.023610568, -0.023607768, -0.023613777, -0.023620741, -0.02360137, -0.023609081,  -0.023611726, -0.023611646, -0.023599626, -0.023612563, -0.023608256, -0.023610609,  -0.023597704, -0.023603573, -0.023603428, -0.02360598, -0.023611398;
-0.000169263, -0.00016883481, -0.00016900359, -0.00016908991,   -0.00016837115, -0.000168927, -0.00016886617, -0.000169008, -0.00016862774, -0.00016900313, -0.00016898234, -0.00016899274, -0.00016839473, -0.00016881016, -0.00016872659, -0.00016896238, -0.00016922595;
0.99965632, 0.99965638, 0.99965626, 0.99965608, 0.99965656, 0.99965638, 0.99965632, 0.99965626, 0.99965656, 0.99965626, 0.99965638, 0.99965632, 0.99965668, 0.9996565, 0.9996565,  0.99965644, 0.99965626]

I couldn't upload an image due to some error on chrome, but you can take a look here

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it. This is how it is done:

    cv::solvePnPRansac(objpoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(objpoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                    points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                   points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

 point: [-0.0113968, -0.0236187, -0.000169321]
 point: [-0.0113949, -0.0236159, -0.000168893]
 point: [-0.011395, -0.0236219, -0.000169062]
 point: [-0.0113946, -0.0236289, -0.000169148]
 point: [-0.0113922, -0.0236095, -0.000168429]
 point: [-0.0113952, -0.0236172, -0.000168985]
 point: [-0.0113946, -0.0236198, -0.000168924]
 point: [-0.0113956, -0.0236198, -0.000169066]
 point: [-0.0113944, -0.0236077, -0.000168686]
 point: [-0.0113954, -0.0236207, -0.000169061]
 point: [-0.0113957, -0.0236164, -0.00016904]
 point: [-0.0113953, -0.0236187, -0.000169051]
 point: [-0.0113926, -0.0236058, -0.000168453]
 point: [-0.0113951, -0.0236117, -0.000168868]
 point: [-0.0113946, -0.0236115, -0.000168785]
 point: [-0.0113956, -0.0236141, -0.00016902]
 point: [-0.0113964, -0.0236195, -0.000169284]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, I mean they too close to zero, may be I am doing something wrong? wrong?

I couldn't upload an image due to some error on chrome, but you can take a look here

Here is additional prints for calculated data above:

[INFO] solvePnP: R: 
[INFO] [0.9588095856998964, -0.01481623915967968, 0.2836629292437701;
        0.01116279977923707, 0.9998326771368026, 0.01449170902768135;
       -0.2838301785770527, -0.0107283170449745, 0.9588145456459767]
[INFO] solvePnP: t: 
[INFO] [0.09641053427352947;
       -0.007467030698232915;
       -0.004027662235745022]
[INFO] 
[INFO] classes1: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords1: [194, 310] [209, 281] [226, 297] [248, 309] [240, 256] [211, 288] [219, 286] [206, 293] [205, 264] [210, 294] [200, 290] [216, 294] [234, 256] [200, 277] [206, 272] [198, 289] [203, 309]
[INFO] classes2: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords2:  [170.45, 307.344] [197.65, 287.464] [202.516, 300.729] [222.787, 306.736] [225.922, 250.291] [192.545, 293.876] [211.48, 289.716] [195.62, 299.105] [182.568, 275.265] [201.421, 297.509] [186.086, 294.605] [191.875, 297.952] [207.761, 250.645] [183.286, 284.2] [189.868, 280.667] [183.016, 288.224] [175.638, 307.159]
[INFO] Fused points:17
[INFO] points4d: [-0.011392879, -0.011390963, -0.011391113, -0.011390729,  -0.011388315, -0.011391266, -0.011390734, -0.011391651,  -0.011390463, -0.01139148, -0.011391737, -0.011391368,   -0.011388648, -0.011391174, -0.011390719, -0.011391672,  -0.011392521;
-0.023610568, -0.023607768, -0.023613777, -0.023620741, -0.02360137, -0.023609081,  -0.023611726, -0.023611646, -0.023599626, -0.023612563, -0.023608256, -0.023610609,  -0.023597704, -0.023603573, -0.023603428, -0.02360598, -0.023611398;
-0.000169263, -0.00016883481, -0.00016900359, -0.00016908991,   -0.00016837115, -0.000168927, -0.00016886617, -0.000169008, -0.00016862774, -0.00016900313, -0.00016898234, -0.00016899274, -0.00016839473, -0.00016881016, -0.00016872659, -0.00016896238, -0.00016922595;
0.99965632, 0.99965638, 0.99965626, 0.99965608, 0.99965656, 0.99965638, 0.99965632, 0.99965626, 0.99965656, 0.99965626, 0.99965638, 0.99965632, 0.99965668, 0.9996565, 0.9996565,  0.99965644, 0.99965626]

I couldn't upload an image due to some error on chrome, but you can take a look here

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it. This is how it is done:

    cv::solvePnPRansac(objpoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(objpoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                    points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                   points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

 point: [-0.0113968, -0.0236187, -0.000169321]
 point: [-0.0113949, -0.0236159, -0.000168893]
 point: [-0.011395, -0.0236219, -0.000169062]
 point: [-0.0113946, -0.0236289, -0.000169148]
 point: [-0.0113922, -0.0236095, -0.000168429]
 point: [-0.0113952, -0.0236172, -0.000168985]
 point: [-0.0113946, -0.0236198, -0.000168924]
 point: [-0.0113956, -0.0236198, -0.000169066]
 point: [-0.0113944, -0.0236077, -0.000168686]
 point: [-0.0113954, -0.0236207, -0.000169061]
 point: [-0.0113957, -0.0236164, -0.00016904]
 point: [-0.0113953, -0.0236187, -0.000169051]
 point: [-0.0113926, -0.0236058, -0.000168453]
 point: [-0.0113951, -0.0236117, -0.000168868]
 point: [-0.0113946, -0.0236115, -0.000168785]
 point: [-0.0113956, -0.0236141, -0.00016902]
 point: [-0.0113964, -0.0236195, -0.000169284]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, I mean they too close to zero, may be I am doing something wrong?

I couldn't upload an image due to some error on chrome, but you can take a look here

Here is additional prints for calculated data above:

[INFO] solvePnP: R: 
[INFO] [0.9588095856998964, -0.01481623915967968, 0.2836629292437701;
        0.01116279977923707, 0.9998326771368026, 0.01449170902768135;
       -0.2838301785770527, -0.0107283170449745, 0.9588145456459767]
[INFO] solvePnP: t: 
[INFO] [0.09641053427352947;
       -0.007467030698232915;
       -0.004027662235745022]
[INFO] 
[INFO] classes1: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords1: [194, 310] [209, 281] [226, 297] [248, 309] [240, 256] [211, 288] [219, 286] [206, 293] [205, 264] [210, 294] [200, 290] [216, 294] [234, 256] [200, 277] [206, 272] [198, 289] [203, 309]
[INFO] classes2: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords2:  [170.45, 307.344] [197.65, 287.464] [202.516, 300.729] [222.787, 306.736] [225.922, 250.291] [192.545, 293.876] [211.48, 289.716] [195.62, 299.105] [182.568, 275.265] [201.421, 297.509] [186.086, 294.605] [191.875, 297.952] [207.761, 250.645] [183.286, 284.2] [189.868, 280.667] [183.016, 288.224] [175.638, 307.159]
[INFO] Fused points:17
[INFO] points4d: [-0.011392879, -0.011390963, -0.011391113, -0.011390729,  -0.011388315, -0.011391266, -0.011390734, -0.011391651,  -0.011390463, -0.01139148, -0.011391737, -0.011391368,   -0.011388648, -0.011391174, -0.011390719, -0.011391672,  -0.011392521;
-0.023610568, -0.023607768, -0.023613777, -0.023620741, -0.02360137, -0.023609081,  -0.023611726, -0.023611646, -0.023599626, -0.023612563, -0.023608256, -0.023610609,  -0.023597704, -0.023603573, -0.023603428, -0.02360598, -0.023611398;
-0.000169263, -0.00016883481, -0.00016900359, -0.00016908991,   -0.00016837115, -0.000168927, -0.00016886617, -0.000169008, -0.00016862774, -0.00016900313, -0.00016898234, -0.00016899274, -0.00016839473, -0.00016881016, -0.00016872659, -0.00016896238, -0.00016922595;
0.99965632, 0.99965638, 0.99965626, 0.99965608, 0.99965656, 0.99965638, 0.99965632, 0.99965626, 0.99965656, 0.99965626, 0.99965638, 0.99965632, 0.99965668, 0.9996565, 0.9996565,  0.99965644, 0.99965626]

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it. This is how it is done:

    cv::solvePnPRansac(objpoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(objpoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                    points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                   points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

 point: [-0.0113968, -0.0236187, -0.000169321]
 point: [-0.0113949, -0.0236159, -0.000168893]
 point: [-0.011395, -0.0236219, -0.000169062]
 point: [-0.0113946, -0.0236289, -0.000169148]
 point: [-0.0113922, -0.0236095, -0.000168429]
 point: [-0.0113952, -0.0236172, -0.000168985]
 point: [-0.0113946, -0.0236198, -0.000168924]
 point: [-0.0113956, -0.0236198, -0.000169066]
 point: [-0.0113944, -0.0236077, -0.000168686]
 point: [-0.0113954, -0.0236207, -0.000169061]
 point: [-0.0113957, -0.0236164, -0.00016904]
 point: [-0.0113953, -0.0236187, -0.000169051]
 point: [-0.0113926, -0.0236058, -0.000168453]
 point: [-0.0113951, -0.0236117, -0.000168868]
 point: [-0.0113946, -0.0236115, -0.000168785]
 point: [-0.0113956, -0.0236141, -0.00016902]
 point: [-0.0113964, -0.0236195, -0.000169284]

[09:24:16.698798 UTC] [INFO] point: [0.15577, -0.0311016, -0.419652] [09:24:16.698811 UTC] [INFO] point: [0.149928, -0.0278522, -0.435363] [09:24:16.698822 UTC] [INFO] point: [0.144644, -0.0221644, -0.431932] [09:24:16.698833 UTC] [INFO] point: [0.137404, -0.00682196, -0.405794] [09:24:16.698844 UTC] [INFO] point: [0.159018, -0.027003, -0.414171] [09:24:16.698855 UTC] [INFO] point: [0.143428, -0.00303873, -0.408063] [09:24:16.698865 UTC] [INFO] point: [0.132802, -0.00845412, -0.412402] [09:24:16.698876 UTC] [INFO] point: [0.13201, -0.0356931, -0.390782] [09:24:16.698887 UTC] [INFO] point: [0.12493, -0.0286363, -0.395042] [09:24:16.698898 UTC] [INFO] point: [0.125111, -0.0300958, -0.395634] [09:24:16.698909 UTC] [INFO] point: [0.147039, -0.0254305, -0.436357] [09:24:16.698919 UTC] [INFO] point: [0.155997, -0.0364843, -0.422006] [09:24:16.698930 UTC] [INFO] point: [0.132421, -0.00401771, -0.411159] [09:24:16.698941 UTC] [INFO] point: [0.147133, -0.028227, -0.436422] [09:24:16.698951 UTC] [INFO] point: [0.156003, -0.0150506, -0.40577] [09:24:16.698962 UTC] [INFO] point: [0.132803, -0.00180741, -0.407651] [09:24:16.698973 UTC] [INFO] point: [0.154273, -0.0172923, -0.409168] [09:24:16.698983 UTC] [INFO] point: [0.132361, -0.0221948, -0.384885]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, I mean they too close to zero, this points even not close, may be I am doing something wrong?

Here is additional prints for calculated data above:Couldn't upload image on site with chrome, it can be found here https://ibb.co/ji4z2U

[INFO] solvePnP: R: 
[INFO] [0.9588095856998964, -0.01481623915967968, 0.2836629292437701;
        0.01116279977923707, 0.9998326771368026, 0.01449170902768135;
       -0.2838301785770527, -0.0107283170449745, 0.9588145456459767]
[INFO] solvePnP: t: 
[INFO] [0.09641053427352947;
       -0.007467030698232915;
       -0.004027662235745022]
[INFO] 
[INFO] classes1: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords1: [194, 310] [209, 281] [226, 297] [248, 309] [240, 256] [211, 288] [219, 286] [206, 293] [205, 264] [210, 294] [200, 290] [216, 294] [234, 256] [200, 277] [206, 272] [198, 289] [203, 309]
[INFO] classes2: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[INFO] 
[INFO] coords2:  [170.45, 307.344] [197.65, 287.464] [202.516, 300.729] [222.787, 306.736] [225.922, 250.291] [192.545, 293.876] [211.48, 289.716] [195.62, 299.105] [182.568, 275.265] [201.421, 297.509] [186.086, 294.605] [191.875, 297.952] [207.761, 250.645] [183.286, 284.2] [189.868, 280.667] [183.016, 288.224] [175.638, 307.159]
[INFO] Fused points:17
[INFO] points4d: [-0.011392879, -0.011390963, -0.011391113, -0.011390729,  -0.011388315, -0.011391266, -0.011390734, -0.011391651,  -0.011390463, -0.01139148, -0.011391737, -0.011391368,   -0.011388648, -0.011391174, -0.011390719, -0.011391672,  -0.011392521;
-0.023610568, -0.023607768, -0.023613777, -0.023620741, -0.02360137, -0.023609081,  -0.023611726, -0.023611646, -0.023599626, -0.023612563, -0.023608256, -0.023610609,  -0.023597704, -0.023603573, -0.023603428, -0.02360598, -0.023611398;
-0.000169263, -0.00016883481, -0.00016900359, -0.00016908991,   -0.00016837115, -0.000168927, -0.00016886617, -0.000169008, -0.00016862774, -0.00016900313, -0.00016898234, -0.00016899274, -0.00016839473, -0.00016881016, -0.00016872659, -0.00016896238, -0.00016922595;
0.99965632, 0.99965638, 0.99965626, 0.99965608, 0.99965656, 0.99965638, 0.99965632, 0.99965626, 0.99965656, 0.99965626, 0.99965638, 0.99965632, 0.99965668, 0.9996565, 0.9996565,  0.99965644, 0.99965626]

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it. This is how it is done:

    cv::solvePnPRansac(objpoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(objpoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                    points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                   points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

[09:24:16.698798 UTC]

[INFO] point: [0.15577, -0.0311016, -0.419652]
[09:24:16.698811 UTC] [INFO] point: [0.149928, -0.0278522, -0.435363]
[09:24:16.698822 UTC] [INFO] point: [0.144644, -0.0221644, -0.431932]
[09:24:16.698833 UTC] [INFO] point: [0.137404, -0.00682196, -0.405794]
[09:24:16.698844 UTC] [INFO] point: [0.159018, -0.027003, -0.414171]
[09:24:16.698855 UTC] [INFO] point: [0.143428, -0.00303873, -0.408063]
[09:24:16.698865 UTC] [INFO] point: [0.132802, -0.00845412, -0.412402]
[09:24:16.698876 UTC] [INFO] point: [0.13201, -0.0356931, -0.390782]
[09:24:16.698887 UTC] [INFO] point: [0.12493, -0.0286363, -0.395042]
[09:24:16.698898 UTC] [INFO] point: [0.125111, -0.0300958, -0.395634]
[09:24:16.698909 UTC] [INFO] point: [0.147039, -0.0254305, -0.436357]
[09:24:16.698919 UTC] [INFO] point: [0.155997, -0.0364843, -0.422006]
[09:24:16.698930 UTC] [INFO] point: [0.132421, -0.00401771, -0.411159]
[09:24:16.698941 UTC] [INFO] point: [0.147133, -0.028227, -0.436422]
[09:24:16.698951 UTC] [INFO] point: [0.156003, -0.0150506, -0.40577]
[09:24:16.698962 UTC] [INFO] point: [0.132803, -0.00180741, -0.407651]
[09:24:16.698973 UTC] [INFO] point: [0.154273, -0.0172923, -0.409168]
[09:24:16.698983 UTC] [INFO] point: [0.132361, -0.0221948, -0.384885]

-0.384885]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, this points even not close, may be I am doing something wrong?

Couldn't upload image on site with chrome, it can be found here https://ibb.co/ji4z2U

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it. This is how it is done:

    cv::solvePnPRansac(objpoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(objpoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                    points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                   points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

[INFO] point: [0.15577, -0.0311016, -0.419652]
[INFO] point: [0.149928, -0.0278522, -0.435363]
[INFO] point: [0.144644, -0.0221644, -0.431932]
[INFO] point: [0.137404, -0.00682196, -0.405794]
[INFO] point: [0.159018, -0.027003, -0.414171]
[INFO] point: [0.143428, -0.00303873, -0.408063]
[INFO] point: [0.132802, -0.00845412, -0.412402]
[INFO] point: [0.13201, -0.0356931, -0.390782]
[INFO] point: [0.12493, -0.0286363, -0.395042]
[INFO] point: [0.125111, -0.0300958, -0.395634]
[INFO] point: [0.147039, -0.0254305, -0.436357]
[INFO] point: [0.155997, -0.0364843, -0.422006]
[INFO] point: [0.132421, -0.00401771, -0.411159]
[INFO] point: [0.147133, -0.028227, -0.436422]
[INFO] point: [0.156003, -0.0150506, -0.40577]
[INFO] point: [0.132803, -0.00180741, -0.407651]
[INFO] point: [0.154273, -0.0172923, -0.409168]
[INFO] point: [0.132361, -0.0221948, -0.384885]
 [INFO] point: [0.17739, -0.0417149, -0.569071]
 [INFO] point: [0.177434, -0.0365413, -0.569185]
 [INFO] point: [0.179331, -0.046826, -0.568601]
 [INFO] point: [0.309903, -0.0841421, -0.753341]
 [INFO] point: [0.310883, -0.0879948, -0.752346]
 [INFO] point: [0.192887, -0.0294726, -0.614926]
 [INFO] point: [0.212949, -0.033606, -0.678697]
 [INFO] point: [0.212837, -0.0347488, -0.678065]
 [INFO] point: [0.216449, -0.0652773, -0.690147]
 [INFO] point: [0.262796, -0.0612305, -0.712385]
 [INFO] point: [0.266117, -0.0210713, -0.707122]
 [INFO] point: [0.284981, -0.0762475, -0.735736]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, this points even not close, may be I am doing something wrong?wrong? Also x values are wrong ang this depend on the run, values looks like random

Couldn't upload image on site with chrome, it can be found here https://ibb.co/ji4z2Uhttps://ibb.co/c0KGhU

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it. This is how it is done:

    cv::solvePnPRansac(objpoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(objpoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                    points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                   points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

 [INFO] point: [0.17739, -0.0417149, -0.569071]
 [INFO] point: [0.177434, -0.0365413, -0.569185]
 [INFO] point: [0.179331, -0.046826, -0.568601]
 [INFO] point: [0.309903, -0.0841421, -0.753341]
 [INFO] point: [0.310883, -0.0879948, -0.752346]
 [INFO] point: [0.192887, -0.0294726, -0.614926]
 [INFO] point: [0.212949, -0.033606, -0.678697]
 [INFO] point: [0.212837, -0.0347488, -0.678065]
 [INFO] point: [0.216449, -0.0652773, -0.690147]
 [INFO] point: [0.262796, -0.0612305, -0.712385]
 [INFO] point: [0.266117, -0.0210713, -0.707122]
 [INFO] point: [0.284981, -0.0762475, -0.735736]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, this points even not close, may be I am doing something wrong? Also x values are wrong ang this depend on the run, values looks like random

Couldn't upload image on site with chrome, it can be found here https://ibb.co/c0KGhUhttps://postimg.cc/mtdLw5nk

triangulatePoints: why calculated data is wrong

Hi, I am trying to triangulate points of tracked marker by using calibration board near it. This is how it is done:

    cv::solvePnPRansac(objpoints, corners1, camMat, distortion, 
                       rvecPNP1, tvecPNP1, false, 200, 5.0, 0.999);
    cv::solvePnPRansac(objpoints, corners2, camMat, distortion, 
                       rvecPNP2, tvecPNP2,  false, 200, 5.0, 0.999);

    Mat rodriguesRPNP1, rodriguesRPNP2;
    cv::Rodrigues(rvecPNP1, rodriguesRPNP1);
    cv::Rodrigues(rvecPNP2, rodriguesRPNP2);

    // relative pose by rotation and translation composition
    rvecPNP = rodriguesRPNP1.inv() * rodriguesRPNP2;
    tvecPNP = rodriguesRPNP2 * tvecPNP2 - rodriguesRPNP1 * tvecPNP1;

    cv::Mat P1 = Mat::eye(cv::Size(4, 3), CV_64F);
    cv::Mat P2;
    cv::hconcat(rvecPNP, tvecPNP, P2);

    Mat F = findFundamentalMat(coords3, coords4, cv::FM_RANSAC, 3, 0.999);

    cv::undistortPoints(coords3, coords3, camMat, distortion);
    cv::undistortPoints(coords4, coords4, camMat, distortion);

    std::vector<Point2f> coords5, coords6;
    cv::correctMatches(F, coords3, coords4, coords5, coords6);

    std::vector<cv::Point3d> points3d = triangulate(coords5, coords6, P1, P2);

And triangulate() looks like this:

std::vector<cv::Point3d> triangulate(const std::vector<cv::Point2f> &coords0,
                                 const std::vector<cv::Point2f> &coords1, 
                                 const cv::Mat &P0, const cv::Mat &P1) {

    cv::Mat points4d;
    cv::triangulatePoints(P0, P1, coords0, coords1, points4d);

    std::vector<cv::Point3d> results;

    for (int i = 0, cols = points4d.cols; i < cols; i++) {

        cv::Point3d point = cv::Point3d(points4d.at<float>(0, i) / points4d.at<float>(3, i),
                                    points4d.at<float>(1, i) / points4d.at<float>(3, i),
                                   points4d.at<float>(2, i) / points4d.at<float>(3, i));
        results.emplace_back(point);
    }
    return results;
}

And this gives me triangulated points:

 [INFO] point: [0.17739, -0.0417149, -0.569071]
 [INFO] point: [0.177434, -0.0365413, -0.569185]
 [INFO] point: [0.179331, -0.046826, -0.568601]
 [INFO] point: [0.309903, -0.0841421, -0.753341]
 [INFO] point: [0.310883, -0.0879948, -0.752346]
 [INFO] point: [0.192887, -0.0294726, -0.614926]
 [INFO] point: [0.212949, -0.033606, -0.678697]
 [INFO] point: [0.212837, -0.0347488, -0.678065]
 [INFO] point: [0.216449, -0.0652773, -0.690147]
 [INFO] point: [0.262796, -0.0612305, -0.712385]
 [INFO] point: [0.266117, -0.0210713, -0.707122]
 [INFO] point: [0.284981, -0.0762475, -0.735736]

The thing is that calibrating rig's Z value is set to zero, and Z for the points must be from -3 to -7 cm, this points even not close, may be I am doing something wrong? Also x values are wrong ang this depend on the run, values looks like randomrandom. If you take a look on screenshot, and wonder what is green square (near red one), it's just the old scaled position of the marker.

Couldn't upload image on site with chrome, it can be found here https://postimg.cc/mtdLw5nk