-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalcDepth.py
More file actions
42 lines (32 loc) · 1.43 KB
/
Copy pathcalcDepth.py
File metadata and controls
42 lines (32 loc) · 1.43 KB
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
37
38
39
40
41
42
import os, sys, pickle
import cv2, numpy
#NOTE: this program is DEPRECATED, calculating depth in plt_stereo_err
def load_meta(metapath):
with open(os.path.join(metapath), 'rb') as metaf:
metadata = pickle.load(metaf)
return metadata
def load_foclx(calib_path):
'''
Averages x focal length of left and right cameras stored in calibrated settings
'''
lcalib = numpy.load(os.path.join(calib_path, 'calib_settings_left.npy'))
rcalib = numpy.load(os.path.join(calib_path, 'calib_settings_right.npy'))
foclx = (lcalib[0][0][0] + rcalib[0][0][0])/2
return foclx
def estdepth(baseline, foclx, lcoords, rcoords):
lx, rx = lcoords[0], rcoords[0]
estdepth = (baseline*foclx)/(lx-rx) - 0.5816505235602084
return estdepth
if __name__ == "__main__":
print('enter path of data directory, then calibration (settings) directory as command line args')
DATA_DIR = sys.argv[1]
CALIB_DIR = sys.argv[2]
#straight-line distance between optical centers
BASELINE = float(input('Distance between cameras in cm: '))
metadata = load_meta(os.path.join(DATA_DIR, 'metadata.dat'))
for pairind in len(metadata.keys()):
paird = metadata[pairind]
lcoord, rcoord = paird['left']['coords'], paird['right']['coords']
#estimate depth
depth = estdepth(BASELINE, load_foclx(CALIB_DIR), lcoord, rcoord)
print('pair index {}\n\tfire depth = {}'.format(pairind, depth))