Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def animate(geom):
vis = o3d.visualization.Visualizer()
vis.create_window()
geom.rotate(geom.get_rotation_matrix_from_xyz((0.75, 0.5, 0)))
vis.add_geometry(geom)
scales = [0.9 for _ in range(30)] + [1 / 0.9 for _ in range(30)]
axisangles = [(0.2 / np.sqrt(2), 0.2 / np.sqrt(2), 0) for _ in range(60)]
ts = [(0.1, 0.1, -0.1) for _ in range(30)
] + [(-0.1, -0.1, 0.1) for _ in range(30)]
for scale, aa in zip(scales, axisangles):
R = geom.get_rotation_matrix_from_axis_angle(aa)
geom.scale(scale).rotate(R, center=False)
vis.update_geometry()
vis.poll_events()
vis.update_renderer()
# Getting the depth sensor's depth scale (see rs-align example for explanation)
depth_scale = depth_sensor.get_depth_scale()
# We will not display the background of objects more than
# clipping_distance_in_meters meters away
clipping_distance_in_meters = 3 # 3 meter
clipping_distance = clipping_distance_in_meters / depth_scale
# print(depth_scale)
# Create an align object
# rs.align allows us to perform alignment of depth frames to others frames
# The "align_to" is the stream type to which we plan to align depth frames.
align_to = rs.stream.color
align = rs.align(align_to)
vis = o3d.visualization.Visualizer()
vis.create_window()
pcd = o3d.geometry.PointCloud()
flip_transform = [[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]]
# Streaming loop
frame_count = 0
try:
while True:
dt0 = datetime.now()
# Get frameset of color and depth
frames = pipeline.wait_for_frames()
# Align the depth frame to color frame
def draw_geometries_with_back_face(geometries):
visualizer = o3d.visualization.Visualizer()
visualizer.create_window()
render_option = visualizer.get_render_option()
render_option.mesh_show_back_face = True
for geometry in geometries:
visualizer.add_geometry(geometry)
visualizer.run()
visualizer.destroy_window()
if __name__ == "__main__":
o3d.utility.set_verbosity_level(o3d.utility.VerbosityLevel.Debug)
source_raw = o3d.io.read_point_cloud("../../TestData/ICP/cloud_bin_0.pcd")
target_raw = o3d.io.read_point_cloud("../../TestData/ICP/cloud_bin_1.pcd")
source = source_raw.voxel_down_sample(voxel_size=0.02)
target = target_raw.voxel_down_sample(voxel_size=0.02)
trans = [[0.862, 0.011, -0.507, 0.0], [-0.139, 0.967, -0.215, 0.7],
[0.487, 0.255, 0.835, -1.4], [0.0, 0.0, 0.0, 1.0]]
source.transform(trans)
flip_transform = [[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]]
source.transform(flip_transform)
target.transform(flip_transform)
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(source)
vis.add_geometry(target)
threshold = 0.05
icp_iteration = 100
save_image = False
for i in range(icp_iteration):
reg_p2l = o3d.registration.registration_icp(
source, target, threshold, np.identity(4),
o3d.registration.TransformationEstimationPointToPlane(),
o3d.registration.ICPConvergenceCriteria(max_iteration=1))
source.transform(reg_p2l.transformation)
vis.update_geometry()
vis.poll_events()
vis.update_renderer()
time_start = time.time()
globalPointcloud = o3d.geometry.PointCloud()
Point2 = o3d.geometry.PointCloud()
Point3 = o3d.geometry.PointCloud()
Point4 = o3d.geometry.PointCloud()
prePoint3 = o3d.geometry.PointCloud()
prePoint4 = o3d.geometry.PointCloud()
temPoint3 = o3d.geometry.PointCloud()
color_l = [(255,0,0),(255,0,255),(0,0,255),(0,255,255),(255,255,0),(96,96,96),(1,97,0),(227,207,87),(176,224,230),
(106,90,205),(56,94,15),(61,89,171),(51,161,201),(178,34,34),(138,43,226)]
pointcloud = o3d.geometry.PointCloud()
vis = o3d.visualization.Visualizer()
vis.create_window("Pointcloud",640,480)
geometrie_added = False
i = 0
### Load template
template_rgb = cv2.imread('./template/template.png')
template_p = template.Template(template_rgb)
_,_,temPoint3 = template_p.getPt()
temFeatureList ,tem_xyr = template_p.getFeature()
print("press 'a' three times to calculate the table plane coefficient(on the cv2 window).\n")
# temFeatureList,tem_new_xyr = registration.extractFeatures(temPoint2,tem_old_xyr,n = 3)
def __init__(self, source, target, save=False,
keep_window=True):
self._vis = o3.visualization.Visualizer()
self._vis.create_window()
self._source = source
self._target = target
self._result = copy.deepcopy(self._source)
self._save = save
self._keep_window = keep_window
self._source.paint_uniform_color([1, 0, 0])
self._target.paint_uniform_color([0, 1, 0])
self._result.paint_uniform_color([0, 0, 1])
self._vis.add_geometry(self._source)
self._vis.add_geometry(self._target)
self._vis.add_geometry(self._result)
self._cnt = 0
def load_view_point(pcd, filename):
vis = o3d.visualization.Visualizer()
vis.create_window()
ctr = vis.get_view_control()
param = o3d.io.read_pinhole_camera_parameters(filename)
vis.add_geometry(pcd)
ctr.convert_from_pinhole_camera_parameters(param)
vis.run()
vis.destroy_window()
def save_view_point(pcd, filename):
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd)
vis.run() # user changes the view and press "q" to terminate
param = vis.get_view_control().convert_to_pinhole_camera_parameters()
o3d.io.write_pinhole_camera_parameters(filename, param)
vis.destroy_window()