-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalibration.py
36 lines (31 loc) · 1.4 KB
/
calibration.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import os
import cv2
import torch
import numpy as np
import argparse
from src.constant import phantom_FB
from src.calibrator import FanbeamCalibrator
from src.utils import load_cameras_init
def main(args):
cameras = load_cameras_init()
calibrator = FanbeamCalibrator(phantom_FB, cameras, optim_f=args.optim_f, optim_beads=args.optim_beads, n_iter=args.n_iter)
calibrator.save_fig = args.save_fig
calibrator.run()
plt = calibrator.viz()
params = calibrator.params # Tx, Tz, theta
params_f = calibrator.params_f # f
params_beads = calibrator.params_beads # beads_3d
params_all = torch.cat([params, params_f.unsqueeze(1)], dim=1)
save_dir = './results/'
os.makedirs(save_dir, exist_ok=True)
np.save(os.path.join(save_dir, 'calibration_results.npy'), params_all.detach().numpy())
np.save(os.path.join(save_dir, 'beads_optimized.npy'), params_beads.detach().numpy())
print('done')
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('--optim_f', type=bool, default=False, help='Optimize f')
parser.add_argument('--optim_beads', type=bool, default=False, help='Optimize beads')
parser.add_argument('--n_iter', type=int, default=20000, help='Number of iterations')
parser.add_argument('--save_fig', type=bool, default=False, help='Save figure')
args = parser.parse_args()
main(args)