-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimages_to_pointcloud
executable file
·54 lines (41 loc) · 1.8 KB
/
images_to_pointcloud
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
#!/home/pi/.virtualenvs/cv/bin/python3
"""
Tool for creating and exporting colored point clouds from stereo image pairs.
"""
import argparse
import cv2
from stereovision.blockmatchers import StereoBM, StereoSGBM
from stereovision.calibration import StereoCalibration
from stereovision.stereo_cameras import CalibratedPair
from stereovision.ui_utils import STEREO_BM_FLAG
def main():
"""Produce PLY point clouds from stereo image pair."""
parser = argparse.ArgumentParser(description="Read images taken with "
"stereo pair and use them to produce 3D "
"point clouds that can be viewed with "
"MeshLab.", parents=[STEREO_BM_FLAG])
parser.add_argument("calibration", help="Path to calibration folder.")
parser.add_argument("left", help="Path to left image")
parser.add_argument("right", help="Path to right image")
parser.add_argument("output", help="Path to output file.")
parser.add_argument("--bm_settings",
help="Path to block matcher's settings.")
args = parser.parse_args()
image_pair = [cv2.imread(image) for image in [args.left, args.right]]
calib_folder = args.calibration
'''if args.use_stereobm:
block_matcher = StereoBM()
else:
block_matcher = StereoSGBM()
'''
block_matcher = StereoSGBM()
if args.bm_settings:
block_matcher.load_settings(args.bm_settings)
camera_pair = CalibratedPair(None,
StereoCalibration(input_folder=calib_folder),
block_matcher)
points = camera_pair.get_point_cloud(image_pair)#rectified_pair)
points = points.filter_infinity()
points.write_ply(args.output)
if __name__ == "__main__":
main()