Home

Awesome

MultiViewUnsynch

3D trajectory reconstruction of moving objects using multiple unsynchronized cameras. Requires 2D detections of a moving object in 2+ cameras with sufficient time overlap and reconstructs the objects 3D trajectory along with the camera poses. Only single target currently supported.

If you use this software for your research, please cite our paper.

Here you can find the dataset we used for our experiments.

<p align="center"> <img src="BA_pipeline.jpg" width="600" alt="Multi-view 3D trajectory reconstruction"> </p>

Table of Contents

<!-- toc -->

Inputs

Configuration JSON file

The reconstruction configuration file initializes the settings and defines the data regarding the 2D tracks and cameras that are used in the flight reconstruction. The file shall be in json format. An example config file is as follows:

{
    "comments":
    [
        "betas: Sony G: 3516", 
        " Mate 10: 0 "
    ],

    
    "necessary inputs":
    {
        "path_detections": ["drone-tracking-datasets/dataset4/detections/cam2.txt",
                            "drone-tracking-datasets/dataset4/detections/cam3.txt",
                            "drone-tracking-datasets/dataset4/detections/cam0.txt",
                            "drone-tracking-datasets/dataset4/detections/cam1.txt",
                            "drone-tracking-datasets/dataset4/detections/cam4.txt",
                            "drone-tracking-datasets/dataset4/detections/cam5.txt",
                            "drone-tracking-datasets/dataset4/detections/cam6.txt"],

        
        "path_cameras": ["drone-tracking-datasets/calibration/mate7/mate7.json",
                         "drone-tracking-datasets/calibration/mate10/mate10_2.json",
                         "drone-tracking-datasets/calibration/gopro3/gopro3.json",
                         "drone-tracking-datasets/calibration/p20pro/p20pro.json",
                         "drone-tracking-datasets/calibration/sony5100/sony5100.json",
                         "drone-tracking-datasets/calibration/sonyG/sonyG_2.json",
                         "drone-tracking-datasets/calibration/sony5n_1440x1080/sony5n_1440x1080.json"],
                    
        "corresponding_frames":[0, 92, -2255, 32, -238, 1136, -2502]
    },


    "optional inputs":
    {
        "ground_truth": {"filepath":"drone-tracking-datasets/dataset4/trajectory/rtk.txt", "frequency":5}
    },


    "settings":
    {
        "num_detections": 100000,
        "opt_calib": false,
        "cf_exact": true,
        "undist_points": true,
        "rolling_shutter": true,
        "init_rs": [0.6,0.75,0.5,0.1,0.1,0.1,0.1],
        "motion_type":"F",
        "motion_reg":true,
        "motion_weights":1e4,
        "rs_bounds":false,
        "cut_detection_second": 0.5,
        "camera_sequence": [],
        "ref_cam": 0,
        "thres_Fmatix": 30,
        "thres_PnP": 30,
        "thres_outlier": 10,
        "thres_triangulation": 20,
        "smooth_factor": [10,20],
        "sampling_rate": 0.5,
        "path_output": "drone-tracking-datasets/dataset4/result_f_rs.pkl"
    }
}

A description of each section in the configuration file is as follows:

comments

notes/information on the reconstruction configuration

necessary inputs

FlagDescription
"path_detections"path to 2D detections for each camera
"path_cameras"path to calibration JSON files for each camera
"corresponding_frames"initial corresponding frame indicies between camera streams

optional inputs

FlagDescription
"ground_truth"path to ground truth trajectory data if available

settings

FlagDescription
"num_detections": intmaximum number of detections to load from each camera track
"opt_calib" : true/falsedetermines whether to optimize the intrinsic camera parameters
"cf_exact" : true/falsedetermines whether to use the exact corresponding frames offsets provided or to optimize them
"undist_points" : true/falsedetermines whether to undistort the 2D detections
"rolling_shutter" : true/falsedetermines whether to apply rolling shutter correction
"init_rs": int/float listdetermines initial rolling shutter correction value applied to each camera
"rs_bounds" : true/falsedetermines whether to bound rolling shutter read out speed to between 0 and 1
"motion_reg" : true/falsedetermines whether to apply motion prior regularization to the reconstruction
"motion_type" : "F" or "KE"determines whether to apply least force ("F") or least kinetic energy ("KE") regularization
"motion_weights" : int/floatweight factor to apply to the motion prior regularization error term
"cut_detection_second"number of seconds to remove from each contiguous detection track to reduce influence of misdetections when the object leaves the field of view
"camera_sequence": * default [] or optional list*optional list to fix the order in which camera detections are added to the reconstruction. The camera detections will be automatically determined based on the number of inlier correspondences in the even an empty list, [], is provided.
"ref_cam": intdetermines which camera in the network to start the reconstruction with
"thres_Fmatix"The maximum distance from a point to an epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. See:cv2 findFundametalMat
"thres_PnP"Inlier threshold value used by the opencv solvePnPRANSAC procedure. The parameter value is the maximum allowed distance between the observed and computed point projections to consider it an inlier. See:cv2 solvePnPRANSAC, reprojectionError
"thres_outlier"Maximum reprojection error in pixels beyond which an associated 2D detection is removed from a given camera track.
"thres_triangulation"Maximum reprojection error in pixels below which an associated triangulated 3D point is added to the trajectory.
"smooth_factor": list length 2Defines the minimum and maximum ratio between the number of points described by a spline and the number of knots used to parameterize that spline. These thresholds are used to scale the smoothness factor within the spline function that controls the balance between closeness of fit and smoothness of the spline. See: scipy.interpolate.splprep
"sampling_rate": default 1time step interval at which the set of splines representing the reconstructed trajectory is sampled to obtain a discrete set of 3D points.
"path output"path of the saved reconstruction result as a pickle file

2D Detection Tracks

text files containing the 2D detections of the target for each camera. The file should contain one detection per row, with each row/detection containing three columns in the following order:

|x-coordinate|y-coordinate|frame-id|

Example:

525 313 923
526 311 924
524 309 925
524 307 926
523 305 927
522 303 928
521 301 929
521 299 930
521 297 931
520 294 932

Intrinsic Camera Parameters

Each camera in the network should have a corresponding calibration file in JSON format containing the following information as shown in the example below:

{
    "comment":["Templete for providing camera information.",
               "The path of this file should be included in the 'config.json' file under 'path_cameras'",
               "K-matrix should be a 3*3 matrix",
               "distCoeff should be a vector of [k1,k2,p1,p2[,k3]]"],

    "K-matrix":[[874.4721846047786, 0.0, 970.2688358898922], [0.0, 894.1080937815644, 531.2757796052425], [0.0, 0.0, 1.0]],

    "distCoeff":[-0.260720634999793, 0.07494782427852716, -0.00013631462898833923, 0.00017484761775924765, -0.00906247784302948],
           
    "fps":59.940060,

    "resolution":[1920,1080]

}

A description of each section in the calibration file is as follows:

FlagDescription
"K-matrix"3*3 matrix of intrinsic camera parameters in the form:
<p align="left"> <img src="k_matrix.jpg" width="200" alt="Intrinsic camera parameter matrix"> </p>
where:
    - (cx, cy) is a principal point that is usually at the image center.
    - fx, fy are the focal lengths expressed in pixel units.
FlagDescription
"distCoeff"a vector of [k1,k2,p1,p2[,k3]] where k1, k2, k3 are radial distortion coefficients and p1 and p2 are tangential distortion coefficients.
"fps"nominal fixed frame rate of the camera
"resolution"sensor resolution (x,y) of the camera

Outputs

The output object of the bundle adjustment procedure contains the following attributes:

Attributes

AttributeDescription
alphaoptimized nominal frame rate of each network camera
betaoptimized relative time offset between each camera and the reference camera
beta_after_Fbetainitial time offset estimate between each camera and the reference camera as determined by the fundamental matrix/time offset minimal solver
camerasoptimized parameters describing each network camera
cfinitial corresponding frame indicies between camera streams
detections2D detections for each camera with camera time stamps.
detections_global2D detections for each camera with global time stamps relative to the reference camera.
detections_raw
find_order: True/Falsedefines whether the order of camera additions were defined automatically or manually
frame_id_allcombined frame_ids from all network cameras
global_detectionscombined detections from all cameras with global time stamps
global_time_stamps_allcombined global timestamps from all network cameras
global_traja combined set of 3D points interpolated from the global stamps of each camera
gtoptional file location and sampling frequency of the ground-truth 3D trajectory for reconstruction accuracy evaluation.
outoutput 3D trajectory transformed to the provided ground-truth. See out.
ref_camindex of the camera in the network that is used as the reference camera. Default is 0.
rsoptimized rolling-shutter read-out speed for each camera
sequencesequence of camera indexes arranged in the order in which they were added to the reconstruction
settingsinitial settings that were applied in the reconstruction as defined in the config JSON file.
splinetime-step interval over which a spline was fit to the trajectory and the spline parameters that describe the spline for each interval.
trajset of 3D points sampled from the reconstruction splines
traj_lennumber of points in the sampled trajectory.
visiblebool defining whether a given camera detection is visible within a spline interval.

The following output attributes contain the following sub-attributes:

Sub-attributes

cameras

The following parameters are defined for each camera included in the reconstruction:

AttributeDescription
K3*3 matrix of optimized intrinsic camera parameters
P2D-3D projection matrix
Rcamera rotation matrix
ccamera center coordinates
dradial distortion coefficients
fpsnominal fixed frame rate of the camera
resolutionsensor resolution (x,y) of the camera
ttranslation vector of the camera

out

AttributeDescription
align_paramArray defining the optimized time scale and time offset values determined in the alignment operation between the reconstruction and the ground truth.
error3D error (meters) between the reconstructed trajectory points and the provided ground-truth data.
gtSet of measured 3D ground truth measurements describing the trajectory.
reconst_tranSet of transformed reconstructed 3D points used to compare to the ground truth.
tran_matrixTransformation matrix determined to transform the reconstructed 3D points into the ground truth frame of orientation.

settings

FlagDescription
"camera_sequence": * optional list*List defining the order in which camera detections were added to the reconstruction. Default [].
"cf_exact" : True/FalseDefines whether the corresponding frame offsets provided in the config file were used in the reconstruction or whether the solved values from the minimal solver were used.
"cut_detection_second": intNumber of seconds that were removed from each contiguous detection track to reduce influence of misdetections when the object leaves the field of view.
"init_rs": int/float listDefines rolling shutter correction values determined for each camera after the reconstruction.
motion_reg : True/FalseDefines whether motion prior regularization was applied to the reconstruction.
"motion_type" : "F" or "KE"Defines whether the least force ("F") or least kinetic energy ("KE") regularization was applied in reconstruction
"motion_weights" : int/floatWeight factor applied to the motion prior regularization error term
"num_detections": intmaximum number of detections loaded from each camera track.
"opt_calib" : True/FalseDefines whether the intrinsic camera parameters were optimized in the reconstruction.
"path output"Path of the reconstruction result saved as a pickle file
"ref_cam": intDefines which camera in the network the reconstruction was started with.
"rolling_shutter" : True/FalseDefines whether rolling shutter distortion correction was applied during the reconstruction
"rs_bounds" : True/FalseDefines whether rolling shutter read out speed was bound between 0 and 1
"sampling_rate": int/floatTime step interval at which the set of splines representing the reconstructed trajectory was sampled to obtain a discrete set of 3D points. default 1
"smooth_factor": list length 2Defines the minimum and maximum ratio between the number of points described by a spline and the number of knots used to parameterize that spline. See Inputs>settings>smooth_factor
"thres_Fmatix": int/floatThe maximum distance from a point to an epipolar line in pixels, beyond which the point is considered an outlier and is not used for computing the final fundamental matrix. See:Inputs>settings>thres_Fmatix
"thres_PnP": int/floatInlier threshold value used by the opencv solvePnPRANSAC procedure. The parameter value is the maximum allowed distance between the observed and computed point projections to consider it an inlier. See:Inputs>settings>thres_PnP
"thres_outlier": int/floatMaximum reprojection error in pixels beyond which an associated 2D detection was removed from a given camera track.
"thres_triangulation" : int/floatMaximum reprojection error in pixels below which an associated triangulated 3D point was added to the trajectory.
"undist_points" : True/Falsedefines whether the 2D detections were undistorted

spline

FlagDescription
intTime intervals over which the set of splines that describe the trajectory are defined.
tckA tuple (t,c,k) containing the vector of knots, the B-spline coefficients, and the degree of the spline. See: scipy.interpolate.splprep

traj

The set of 3D points that are interpolated from the set of splines that describe the reconstructed trajectory.

visible

Attribute defining which spline interval a given detection is visible in for each 2D camera track.

Acknowledgement

The software was written by Jingtong Li and Jesse Murray, supervised by Cenek Albl and Konrad Schindler in the group of Photogrammetry and Remote Sensing, ETH Zurich.