1

is it possible to calculate the distance between points which i created with cv2.projectPoints?

I have two aruco markers and from both markers i have created (with cv2.projectPoints) points which are in a specific distance to the marker. Now i want to know how far these points are away from each other?

I know you cant give a specific code without an MVP and it is not necessary i only need an idea how this is possible to calculate. I would be awesome if someone knows maybe a cv2 function or a way to calculate these?

Thank you very much <3

enter image description here

Edit:

I generated the four identity matrixes and inversed all of them. Code and result ist below.

#T_point1_marker1 = np.linalg.inv(T_marker1_point1)
#T_marker1_cam = np.linalg.inv(T_cam_marker1)

T_point1_marker1 = np.array([
    [ 1.,  0.,  0., -0.1 ],
    [ 0.,  1.,  0., -0.05],
    [ 0.,  0.,  1.,  0.  ],
    [ 0.,  0.,  0.,  1.  ],
])

T_marker1_cam = np.array([
    [ 1.,  0.,  0.,  0.10809129],
    [ 0.,  1.,  0.,  0.03833054],
    [ 0.,  0.,  1., -0.35931477],
    [ 0.,  0.,  0.,  1.        ],
])

T_cam_marker2 = np.array([
    [ 1.,  0.,  0.,  0.09360527],
    [ 0.,  1.,  0., -0.01229168],
    [ 0.,  0.,  1.,  0.36470099],
    [ 0.,  0.,  0.,  1.        ],
])

T_marker2_point2 = np.array([
    [ 1.,  0.,  0.,  0.005],
    [ 0.,  1.,  0.,  0.1  ],
    [ 0.,  0.,  1.,  0.   ],
    [ 0.,  0.,  0.,  1.   ],
])
#Process finished with exit code 1

The think i don't understand is this part:

T_point1_point2 = T_point1_marker1 @ T_marker1_cam @ T_cam_marker2 @ T_marker2_point2

How do i bring these four matrixes together so i get T_point1_point2? Thanks again :)

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Major23
  • 53
  • 7
  • If you have the (X,Y) pixel coordinates, and you know the resolution in pixels-per-millimeter, then it's a simple division. I think you do know the resolution, if you placed those two points so precisely from the center of the marker. – Tim Roberts Aug 19 '22 at 22:25
  • What's the length of the blue line in pixels? What's the 5mm, 10 mm, 20mm and 50mm in pixels? – Micka Aug 20 '22 at 12:51
  • stuffing a bunch of translation vectors into a matrix is generally not useful. – Christoph Rackwitz Sep 14 '22 at 14:09
  • I edited it again. Guess i understood something wrong at the first try. Hopefully you have a moment to look at it again :) – Major23 Sep 14 '22 at 18:08
  • 1
    ah, those matrices look better. the part you "don't understand" is perhaps so simple that it spooks you. that line is literally just a line of python code. the result of it is `T_point1_point2[0:3,3] == np.array([0.1067 , 0.07604, 0.00539])` (assuming all the translations are ok) – Christoph Rackwitz Sep 14 '22 at 20:50
  • 1
    since you seem to actually be detecting and pose-recovering those markers from a camera picture, you should use not just the translation but the entire pose (including rvec). you'll need `Rodrigues` to turn the rvec into a 3x3 matrix. that's the top left part of a 4x4 matrix. – Christoph Rackwitz Sep 14 '22 at 20:59
  • yeah but how do i get T_point1_point2? Just add them all together? T_point1_point2 = T_point1_marker1 + T_marker1_cam + T_cam_marker2 + T_marker2_point2 – Major23 Sep 15 '22 at 09:59
  • And is the rvec really neccessary? You are right the camera is mounted on my head and films my hands. For the question i simplifyed the task normally one marker is flexible and the other is fixed. So i need from every frame the distance between the two points. But its always just points and the distance between them is the only information i need. Thanks again and sry for my "stupid" questions. – Major23 Sep 15 '22 at 10:35
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/248065/discussion-between-major23-and-christoph-rackwitz). – Major23 Sep 15 '22 at 10:49
  • this is no longer one question but a discussion with unbounded scope creep. it is unreasonable ask anyone to spend any more time on this. – Christoph Rackwitz Sep 15 '22 at 12:10
  • related: https://forum.opencv.org/t/calibrated-camera-distance-between-two-projected-points/10241 – Christoph Rackwitz Sep 18 '22 at 12:51
  • Thanks but i still dont get the line: T_point1_point2 = T_point1_marker1 @ T_marker1_cam @ T_cam_marker2 @ T_marker2_point2 What did you calculate to get this: T_point1_point2[0:3,3] == np.array([0.1067 , 0.07604, 0.00539]) – Major23 Sep 19 '22 at 14:09

1 Answers1

0

Since your graphic contains measurements of physical distance, rather than pixels, I'll assume you're asking about 3D, i.e. you want a 3D distance between those points...

You just need to define the poses of those points, relative to their markers. That is T_marker1_point1 and T_marker2_point2. Make those be pure translation, probably with Z=0 if these points are in each respective marker's plane. Literally make a 4x4 identity matrix, then stick your nominal (constructed) dimensions into the last column.

Then you need the marker poses relative to the camera, T_cam_marker1 and T_cam_marker2.

Finally you calculate

T_point1_point2 = T_point1_marker1 @ T_marker1_cam @ T_cam_marker2 @ T_marker2_point2
# where
# T_marker1_cam = np.linalg.inv(T_cam_marker1)
# and so on

The translation part of that pose matrix gives you the distance between those points. You can ignore the rotation component. That'd only give you the rotation between those markers, because your points were defined as poses of the same orientation as their respective markers. Yes, orientation is silly for points but eh...

All of that is 4x4 matrices. Compose from tvec, put in third column, and rvec, turned into a 3x3 rotation matrix using cv.Rodrigues. Decompose 4x4 matrix into rvec and tvec accordingly (Rodrigues goes both ways).

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • Oh wow that was a big help. I added some more informations at the first post. Maybe you have a second to look at it. – Major23 Sep 14 '22 at 13:47