TemugeB / python_stereo_camera_calibrate

Stereo camera calibration with python and openCV
Apache License 2.0
151 stars 35 forks source link

ways to support more than 2 viewpoint to triangulate 3d points ? #10

Closed Stephenfang51 closed 2 years ago

Stephenfang51 commented 2 years ago

DLT supoort 2 points to triangulate 3d point

if i can provide more than 2 points like 3 or 4, is there any method to do that ?

Thanks in advanced !

TemugeB commented 2 years ago

Yes there is. You need to modify DLT code to accept more points and more projection matrices. Keep in mind that I didn't test the instructions below but this is the correct way to do this.

  1. Add additional points and projection matrices here:

https://github.com/TemugeB/bodypose3d/blob/4d505a50f9ae9d2b36326ea37de001f390b32b04/utils.py#L14

For 3 points:

    A = [point1[1]*P1[2,:] - P1[1,:],
         P1[0,:] - point1[0]*P1[2,:],
         point2[1]*P2[2,:] - P2[1,:],
         P2[0,:] - point2[0]*P2[2,:]
         point3[1]*P3[2,:] - P3[1,:],
         P3[0,:] - point3[0]*P3[2,:]
        ]
  1. Reshape to new size: (6, 4) for 3 points, (8, 4) for 4 points.

https://github.com/TemugeB/bodypose3d/blob/4d505a50f9ae9d2b36326ea37de001f390b32b04/utils.py#L19

  1. Take the last row vector from the output.

https://github.com/TemugeB/bodypose3d/blob/4d505a50f9ae9d2b36326ea37de001f390b32b04/utils.py#L29

It is probably best to write this line as:

return Vh[-1,0:3]/Vh[-1,3]

This is supposed to work in the presence of noise in all of your points. Read this post if you want to understand what this is doing: DLT

Stephenfang51 commented 2 years ago

@TemugeB

Thanks for your quick response ! It works ! it's really helpful !

aviralchharia commented 1 year ago

@Stephenfang51 Here, does $3$ viewpoints refer to $3$ cameras? For more than $2$ cameras, how did you find the extrinsic matrix? Specifically should we use $[C1, C2]$, $[C2, C3]$ pairs or should we use $[C1, C2]$, $[C1, C3]$?

TemugeB commented 1 year ago

If you are using camera1 (C1) as the origin of your coordinate system, then you would use [C1, C2] and [C1, C3] and [C1, C1] to define your three projection matrices. Here [C1, C1] is just identity matrix and [0,0,0] for translation.

If the coordinate system is outside the camera, then you would use [O, C2] and [O, C3] and [O, C1].