-
Notifications
You must be signed in to change notification settings - Fork 8
/
CapturePointCloud.py
98 lines (78 loc) · 3.38 KB
/
CapturePointCloud.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
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from MechEye import Device
import open3d as o3d
import numpy as np
from struct import unpack
def show_error(status):
if status.ok():
return
print("Error Code : {}".format(status.code()),
",Error Description: {}".format(status.description()))
def print_device_info(num, info):
print(" Mech-Eye device index: {}\n".format(str(num)),
"Camera Model Name: {}\n".format(info.model()),
"Camera ID: {}\n".format(info.id()),
"Camera IP: {}\n".format(info.ip()),
"Hardware Version: {}\n".format(info.hardware_version()),
"Firmware Version: {}\n".format(info.firmware_version()),
"...............................................")
class CapturePointCloud(object):
def __init__(self):
self.device = Device()
def find_camera_list(self):
print("Find Mech-Eye devices...")
self.device_list = self.device.get_device_list()
if len(self.device_list) == 0:
print("No Mech-Eye device found.")
quit()
for i, info in enumerate(self.device_list):
print_device_info(i, info)
def choose_camera(self):
while True:
user_input = input(
"Please enter the device index you want to connect: ")
if user_input.isdigit() and len(self.device_list) > int(user_input) and int(user_input) >= 0:
self.index = int(user_input)
break
print("Input invalid!")
def connect_device_info(self):
status = self.device.connect(self.device_list[self.index])
if not status.ok():
show_error(status)
quit()
print("Connected to the Mech-Eye device successfully.")
color = self.device.capture_color()
color_data = color.data()
point_xyz = self.device.capture_point_xyz()
point_xyz_data = point_xyz.data()
point_cloud_xyz = o3d.geometry.PointCloud()
points_xyz = np.zeros(
(point_xyz.width() * point_xyz.height(), 3), dtype=np.float64)
pos = 0
for dd in np.nditer(point_xyz_data):
points_xyz[int(pos / 3)][int(pos % 3)] = 0.001 * dd
pos = pos + 1
point_cloud_xyz.points = o3d.utility.Vector3dVector(points_xyz)
o3d.visualization.draw_geometries([point_cloud_xyz])
o3d.io.write_point_cloud("PointCloudXYZ.ply", point_cloud_xyz)
print("Point cloud saved to path PointCloudXYZ.ply")
point_cloud_xyz_rgb = o3d.geometry.PointCloud()
point_cloud_xyz_rgb.points = o3d.utility.Vector3dVector(points_xyz)
points_rgb = np.zeros(
(point_xyz.width() * point_xyz.height(), 3), dtype=np.float64)
pos = 0
for dd in np.nditer(color_data):
points_rgb[int(pos / 3)][int(2 - (pos % 3))] = dd / 255
pos = pos + 1
point_cloud_xyz_rgb.colors = o3d.utility.Vector3dVector(points_rgb)
o3d.visualization.draw_geometries([point_cloud_xyz_rgb])
o3d.io.write_point_cloud("PointCloudXYZRGB.ply", point_cloud_xyz_rgb)
print("Color point cloud saved to path PointCloudXYZRGB.ply")
self.device.disconnect()
print("Disconnected from the Mech-Eye device successfully.")
def main(self):
self.find_camera_list()
self.choose_camera()
self.connect_device_info()
if __name__ == '__main__':
a = CapturePointCloud()
a.main()