c++opencvcamera-calibration

Hand To Eye Calibration


I want to do Hand-To-Eye calibration to get the pose of external fixed camera compared to the base of the robot using calibrateRobotWorldHandEye

However most of the code examples (including OpenCV docs) are explaining Hand-in-Eye calibration.

to do so I do the following:

cv::calibrateRobotWorldHandEye(
    r_marker_2_cams, t_marker_2_cams, 
    r_base_2_eefs,   t_base_2_eefs, 
    r_base_2_marker, t_base_2_marker, 
    r_eef_2_cam, t_eef_2_cam
);

However the transform that I want is from camera to the base r_cam_2_base, t_cam_2_base but I'm not sure how I can do that as I didn't find any example.

the values of the base_2_eefs, marker_2_cams vectors are the following:

{
    "0" : 
    {
        "eef_to_base" : 
        {
            "rotation" : 
            [
                [
                    -0.095606111055037801,
                    -0.51025118851622564,
                    -0.85469479707478668
                ],
                [
                    -0.2832817770222838,
                    -0.80917743832918987,
                    0.51476529419348682
                ],
                [
                    -0.95425934961939407,
                    0.29133416881098761,
                    -0.067182555378477338
                ]
            ],
            "translation" : 
            [
                0.90001126059008763,
                0.26805892340487769,
                0.98525793586232102
            ]
        },
        "marker_to_camera" : 
        {
            "rotation" : 
            [
                [
                    0.92253465633644494,
                    -0.2152414766107825,
                    0.32031377523392118
                ],
                [
                    -0.2152414766107825,
                    -0.97590218043617782,
                    -0.035861413334157398
                ],
                [
                    0.32031377523392118,
                    -0.035861413334157398,
                    -0.94663247590026744
                ]
            ],
            "translation" : 
            [
                0.03402884930726869,
                0.014143468196645812,
                0.15751829284878796
            ]
        }
    },
    "1" : 
    {
        "eef_to_base" : 
        {
            "rotation" : 
            [
                [
                    -0.20698015831412614,
                    -0.61227580911613599,
                    -0.76307112881791062
                ],
                [
                    -0.41541975402669973,
                    -0.65115455185373627,
                    0.6351568133654526
                ],
                [
                    -0.88576839073691027,
                    0.44845967842308965,
                    -0.11957539378987342
                ]
            ],
            "translation" : 
            [
                0.96772548551068494,
                0.19639468634609225,
                0.89220657837415496
            ]
        },
        "marker_to_camera" : 
        {
            "rotation" : 
            [
                [
                    0.95787953058770325,
                    -0.23867817485777876,
                    0.15968573426465274
                ],
                [
                    -0.23867817485777876,
                    -0.97090358713932667,
                    -0.019466723569897548
                ],
                [
                    0.15968573426465274,
                    -0.019466723569897548,
                    -0.98697594344837614
                ]
            ],
            "translation" : 
            [
                0.044783191711068503,
                0.023470920523726766,
                0.15747101277574513
            ]
        }
    },
    "2" : 
    {
        "eef_to_base" : 
        {
            "rotation" : 
            [
                [
                    -0.12350759604901118,
                    -0.20680972023673849,
                    -0.97055428149784384
                ],
                [
                    -0.18232558826984002,
                    -0.95666344874673281,
                    0.22705159258209323
                ],
                [
                    -0.97545028247484278,
                    0.20499947670082008,
                    0.080448498880580921
                ]
            ],
            "translation" : 
            [
                0.73249608671719035,
                0.66220009961098181,
                0.89221177149030129
            ]
        },
        "marker_to_camera" : 
        {
            "rotation" : 
            [
                [
                    0.78348037242671398,
                    -0.11539983601306734,
                    0.61060738930204139
                ],
                [
                    -0.11539983601306734,
                    -0.99253307053011008,
                    -0.039509261600644968
                ],
                [
                    0.61060738930204139,
                    -0.039509261600644968,
                    -0.79094730189660378
                ]
            ],
            "translation" : 
            [
                -0.021747313435247093,
                0.026637357656369078,
                0.1910133070186012
            ]
        }
    },
    "3" : 
    {
        "eef_to_base" : 
        {
            "rotation" : 
            [
                [
                    -0.14139277743876,
                    -0.58163823962076944,
                    -0.80106494162396458
                ],
                [
                    -0.066538421728242203,
                    -0.80178083087220542,
                    0.59390246478676123
                ],
                [
                    -0.98771489860286521,
                    0.13727511594141062,
                    0.074664728093018773
                ]
            ],
            "translation" : 
            [
                0.91470660231510692,
                0.28704308433655318,
                0.9501287577881915
            ]
        },
        "marker_to_camera" : 
        {
            "rotation" : 
            [
                [
                    0.95967525014499111,
                    -0.063827726844024352,
                    0.27376894554546011
                ],
                [
                    -0.063827726844024352,
                    -0.99792109498052117,
                    -0.0089168087790869148
                ],
                [
                    0.27376894554546011,
                    -0.0089168087790869148,
                    -0.96175415516447016
                ]
            ],
            "translation" : 
            [
                0.026701151449500173,
                0.023098944615863572,
                0.16560896248519821
            ]
        }
    },
    "4" : 
    {
        "eef_to_base" : 
        {
            "rotation" : 
            [
                [
                    -0.15445547258729375,
                    -0.78526027945890686,
                    -0.59959136125527657
                ],
                [
                    -0.023678306619458522,
                    -0.6037576161025463,
                    0.79681621393757118
                ],
                [
                    -0.98771597374117148,
                    0.13726993298712675,
                    0.074660034250187302
                ]
            ],
            "translation" : 
            [
                0.95856056973329129,
                0.015659241202002405,
                0.95013413396721758
            ]
        },
        "marker_to_camera" : 
        {
            "rotation" : 
            [
                [
                    0.99915164331289708,
                    -0.033625485075008531,
                    -0.02377646774876508
                ],
                [
                    -0.033625485075008531,
                    -0.99943442347142009,
                    0.00039991726695511552
                ],
                [
                    -0.02377646774876508,
                    0.00039991726695511552,
                    -0.99971721984147655
                ]
            ],
            "translation" : 
            [
                0.052542209909467959,
                0.026759669926727965,
                0.14180080527811537
            ]
        }
    }
}

But when I call the calibration function I get and error:

lib/opencv-4.5.2/modules/calib3d/src/calibration_handeye.cpp:524: 
error: (-7:Iterations do not converge) Rotation normalization issue: determinant(R) is null in function 'normalizeRotation

Can you please tell me if my approach in computing Hand-To-Eye calibration is wrong, and how can I fix it? thanks


Solution

  • for hand-to-eye calibration my approach was wrong, we need to compute T_cam2base:

    cv::calibrateRobotWorldHandEye(
        r_marker_2_cams, t_marker_2_cams, 
        r_eefs_2_base, t_eefs_2_base, 
        r_base_2_marker, t_base_2_marker, 
        r_base_2_cam, t_base_2_cam
    );