chengche6230 / ReST

[ICCV 2023] ReST: A Reconfigurable Spatial-Temporal Graph Model for Multi-Camera Multi-Object Tracking
MIT License
130 stars 15 forks source link

Camera Calibration #9

Closed durbin-164 closed 3 months ago

durbin-164 commented 3 months ago

Hi, Thanks a lot for this excellent work. I am following your project to track basketball players but I can't understand how to calculate the camera calibration tomography matrix. I am using two GoPro 10 cameras both are fully overlapping. Could you mind If I request you help me how to calculate the homography matrix?

Thanks again.

chengche6230 commented 3 months ago

Hi,

The homography matrix is used to project all the cameras onto the same 3D ground plane. It can be calculated by camera calibration parameters (both intrinsic and extrinsic) or computed by yourself, e.g. transform.estimate_transform in skimage.

durbin-164 commented 3 months ago

Hello, Thanks for your reply. Let's say, I have two cameras but I don't know the camera calibration parameters, Therefore I need to estimate it.

For this, I have prepared a 2D map not 3D, and tried to transform the camera image to that common map. Is it the right way? Do you have any better suggestions to transform it into a 3D space?

I have got this type of estimation matrix. Though both images are not mapped 100%. I don't know why estimation did not work 100%.

Cam1

[[-1.1510461275014663, -0.2771969264985102, -24.050554607263795], [-0.5571325237346941, -5.834756788567005, 2640.467199523129], [8.847178980534715e-05, -0.004940055013579897, 1.0]]

Cam2 [[-0.6016001099248801, -8.08431176919911, 3781.266448808907], [0.6958366945243458, -4.344802484733891, 1047.8589246362646], [0.00012556019549752714, -0.004096814081959575, 1.0]]

Here are my camera images and map.

Cam 1 Sim0L Cam 2 Sim0R

Map 2D basketball_map_1080_draw

Thanks a lot.

chengche6230 commented 3 months ago

Hi,

Below is my implementation as a reference for you:

from skimage import transform
src1 = np.array([x1, y1, x2, y2, x3, y4, x4, y4]).reshape((4, 2)) # cam1
dst = np.array([X1, Y1, X2, Y2, X3, Y3, X4, Y4]).reshape((4, 2)) # Map2D
tform = transform.estimate_transform('projective', src, dst)
H1 = np.array(tform)
print("Homography matrix of cam1:", H1)
tf_img = transform.warp(img, tform.inverse)

You need to mark at least four points on both the source image and map to compute the homography matrix. For example, the left-top corner of the court in cam1 is [100, 350] (not correct, just for enumeration) and would be mapped to [0, 0]. Therefore, x1=100, y1=350, X1=0, Y1=0. Mark the left 3 points and you will get the transform matrix for cam1. Mark the same position in cam2 (with different x1, y1, ..., y4 and the same X1, Y1, ..., Y4) and get the matrix for cam2. Loop until all the cameras can be mapped to a similar 2D map. Fill the H matrices into config.json.

Best. Cheng-Che

durbin-164 commented 3 months ago

Hi @chengche6230

Thanks a lot for your detailed response. I am going to try it and get back to you if I face any other issues.

Thanks a lot.