-
Notifications
You must be signed in to change notification settings - Fork 0
/
tune_blockmatcher
executable file
·67 lines (53 loc) · 2.52 KB
/
tune_blockmatcher
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/home/pi/.virtualenvs/cv/bin/python3
"""
Let user tune all images in the input folder and report chosen values.
Load a calibration from file and instantiate a ``BlockMatcher`` of the type
requested by the user. Load images successively from input folder and display
their resultant disparity map generated with the ``BlockMatcher`` and the
parameters chosen in the ``BMTuner``'s GUI. Afterwards, report user's chosen
settings and, if a file for the BM settings is provided, save the most common
settings to file.
"""
from argparse import ArgumentParser
import cv2
from stereovision.blockmatchers import StereoBM, StereoSGBM
from stereovision.calibration import StereoCalibration
from stereovision.ui_utils import find_files, BMTuner, STEREO_BM_FLAG
def main():
parser = ArgumentParser(description="Read images taken from a calibrated "
"stereo pair, compute disparity maps from them and "
"show them interactively to the user, allowing the "
"user to tune the stereo block matcher settings in "
"the GUI.", parents=[STEREO_BM_FLAG])
parser.add_argument("calibration_folder",
help="Directory where calibration files for the stereo "
"pair are stored.")
parser.add_argument("image_folder",
help="Directory where input images are stored.")
parser.add_argument("--bm_settings",
help="File to save last block matcher settings to.",
default="")
args = parser.parse_args()
calibration = StereoCalibration(input_folder=args.calibration_folder)
input_files = find_files(args.image_folder)
if args.use_stereobm:
block_matcher = StereoBM()
else:
block_matcher = StereoSGBM()
image_pair = [cv2.imread(image) for image in input_files[:2]]
print( input_files)
input_files = input_files[2:]
rectified_pair = calibration.rectify(image_pair)
tuner = BMTuner(block_matcher, calibration, rectified_pair)
while input_files:
image_pair = [cv2.imread(image) for image in input_files[:2]]
print(image_pair)
rectified_pair = calibration.rectify(image_pair)
tuner.tune_pair(rectified_pair)
input_files = input_files[2:]
for param in block_matcher.parameter_maxima:
print("{}\n".format(tuner.report_settings(param)))
if args.bm_settings:
block_matcher.save_settings(args.bm_settings)
if __name__ == "__main__":
main()