add focal length argument (#6)

This commit is contained in:
Lorenzo Bertoni 2021-02-09 12:12:44 +01:00 committed by GitHub
parent 23ab2f05aa
commit 00f9d3ee80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 5 deletions

View File

@ -17,7 +17,6 @@ z_min = 4
z_max = 60
D_MIN = BF / z_max
D_MAX = BF / z_min
FL = 5.7 # nuScenes focal length (mm)
Sx = 7.2 # nuScenes sensor size (mm)
Sy = 5.4 # nuScenes sensor size (mm)
@ -67,7 +66,7 @@ def preprocess_monoloco(keypoints, kk, zero_center=False):
return kps_out
def factory_for_gt(im_size, name=None, path_gt=None, verbose=True):
def factory_for_gt(im_size, focal_length=5.7, name=None, path_gt=None, verbose=True):
"""Look for ground-truth annotations file and define calibration matrix based on image size """
try:
@ -91,8 +90,8 @@ def factory_for_gt(im_size, name=None, path_gt=None, verbose=True):
kk = [[718.3351, 0., 600.3891], [0., 718.3351, 181.5122], [0., 0., 1.]] # Kitti calibration
else: # nuScenes camera parameters
kk = [
[im_size[0]*FL/Sx, 0., im_size[0]/2],
[0., im_size[1]*FL/Sy, im_size[1]/2],
[im_size[0]*focal_length/Sx, 0., im_size[0]/2],
[0., im_size[1]*focal_length/Sy, im_size[1]/2],
[0., 0., 1.]]
if verbose:
logger.info("Using a standard calibration matrix...")

View File

@ -130,7 +130,7 @@ def predict(args):
im_name = os.path.basename(meta['file_name'])
im_size = (cpu_image.size[0], cpu_image.size[1]) # Original
kk, dic_gt = factory_for_gt(im_size, name=im_name, path_gt=args.path_gt)
kk, dic_gt = factory_for_gt(im_size, focal_length=args.focal, name=im_name, path_gt=args.path_gt)
# Preprocess pifpaf outputs and run monoloco
boxes, keypoints = preprocess_pifpaf(pifpaf_outs['left'], im_size, enlarge_boxes=False)

View File

@ -39,6 +39,9 @@ def cli():
predict_parser.add_argument('--dpi', help='image resolution', type=int, default=150)
predict_parser.add_argument('--long-edge', default=None, type=int,
help='rescale the long side of the image (aspect ratio maintained)')
predict_parser.add_argument('--focal',
help='focal length in mm for a sensor size of 7.2x5.4 mm. Default nuScenes sensor',
type=float, default=5.7)
# Pifpaf parsers
decoder.cli(predict_parser)