Search code examples
opencv3dlinear-algebrapose-estimation

Parameter "triangulatedPoints" of recoverPose and math behind it


cv::recoverPose has parameter "triangulatedPoints" as seen in documentation, though math behind it is not documented, even in sources (relevant commit on github). When I use it, I get this matrix in following form:

[0.06596200907402348, 0.1074107606919504, 0.08120752154556411, 
 0.07162400555712592, 0.1112415181779849, 0.06479560707001968, 
 0.06812069103377787, 0.07274771866295617, 0.1036230973846902, 
 0.07643884790206311, 0.09753859499789987, 0.1050111597547035, 
 0.08431322508162108, 0.08653721971228882, 0.06607013741719928, 
 0.1088621999959361, 0.1079215237863785, 0.07874160849424018, 
 0.07888037486261903, 0.07311940086190356;

 -0.3474319603010109, -0.3492386196164926, -0.3592673043398864,
 -0.3301695131649525, -0.3398606744869519, -0.3240186574427479, 
 -0.3302508442361889, -0.3534091474425142, -0.3134288005980755, 
 -0.3456284001726975, -0.3372514921152191, -0.3229005408417835, 
 -0.3156005118578394, -0.3545418178651592, -0.3427899760859008,  
 -0.3552801904337188, -0.3368860879000375, -0.3268499974874541,
 -0.3221050630233929, -0.3395139819250934;

 -0.9334091581425227, -0.9288726274060354, -0.9277125424980246,
 -0.9392374374147775, -0.9318967835907961, -0.941870018271934,
 -0.9394698966781299, -0.9306592884695234, -0.9419749503870455,
 -0.9332801148509925, -0.9343740431697417, -0.9386198310107222,
 -0.9431781968459053, -0.9290466865633286, -0.9351167772249444,
 -0.9264105322194914, -0.933362882155191, -0.9398254944757025,
 -0.9414486961893244, -0.935785675955617;

 -0.0607238817598344, -0.0607532477465341, -0.06067768097603395,
 -0.06075467523485482, -0.06073245675798231, -0.06078081616640227,
 -0.06074754785132623, -0.0606879948481664, -0.06089198212719162,
 -0.06071522666667255, -0.06076842109618678, -0.06083346023742937,
 -0.06084805655000008, -0.0606931888685702, -0.06071558440082779,
 -0.06073329803512636, -0.06078189449161094, -0.06080195858434526,
 -0.06083228813425822, -0.06073695721101467]

e.g. 4x20 matrix (in this case there were 20 points). I want to convert this data to std::vector in order to use it in solvePnP. How to do it, what is the math here? Thanks!


Solution

  • OpenCV offers a triangulatePoints function, which has the same output:

    points4D 4xN array of reconstructed points in homogeneous coordinates.

    Which indicates that each column is a 3D point in homogeneous coordinate system. However your points looks quite not as I would expect. For instance your first point is:

    [0.06596200907402348, -0.3474319603010109, -0.9334091581425227, -0.0607238817598344]
    

    But I would expect the last component to be 1.0 already. You should double check if something is not wrong here. You can always remove the "scaling" of the point by dividing each dimension by the last component:

     [ x, y z, w ] = w [x/w, y/w, z/w, 1]
    

    And then use the first three parts for your PnP solution.

    I hope this helps