Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import trimesh
filename = self.getMeshPath(input_urdf, link_name)
# box around current COM in case no mesh is availabe
length = self.opt['cubeSize']
cube = [[-0.5*length+old_com[0], -0.5*length+old_com[1], -0.5*length+old_com[2]],
[ 0.5*length+old_com[0], 0.5*length+old_com[1], 0.5*length+old_com[2]]]
if scaling:
hullScale = self.opt['hullScaling']
else:
hullScale = 1.0
pos_0 = [0.0, 0.0, 0.0]
rot_0 = np.identity(3)
if filename and os.path.exists(filename):
mesh = trimesh.load_mesh(filename)
#TODO: get geometry origin attributes, rotate and shift mesh data
#gazebo and urdf use 1m for 1 stl unit
scale_x = float(self.mesh_scaling.split()[0])
scale_y = float(self.mesh_scaling.split()[1])
scale_z = float(self.mesh_scaling.split()[2])
bounding_box = mesh.bounding_box.bounds * scale_x * hullScale
# switch order of min/max if scaling is negative
for s in range(0,3):
if [scale_x, scale_y, scale_z][s] < 0:
bounding_box[0][s], bounding_box[1][s] = bounding_box[1][s], bounding_box[0][s]
return bounding_box, pos_0, rot_0
else:
of each body, then combine them back into one mesh.
Useful for generating collision models of an object.
"""
import trimesh
import numpy as np
if __name__ == '__main__':
# attach to trimesh logs
trimesh.util.attach_to_log()
# load the mesh from filename
# file objects are also supported
mesh = trimesh.load_mesh('../models/box.STL')
# split the mesh into connected components of face adjacency
# splitting sometimes produces non- watertight meshes
# though the splitter will try to repair single quad and
# single triangle holes, in our case here we are going to be
# taking convex hulls anyway so there is no reason to discard
# the non- watertight bodies
meshes = mesh.split(only_watertight=False)
# the convex hull of every component
meshes_convex = [i.convex_hull for i in meshes]
# combine all components into one mesh
convex_combined = np.sum(meshes_convex)
print('Showing original mesh')
number of points to take from the scan
Returns
-------
scans : numpy array [n_scans, n_scan_points, 3]
scans point clouds
"""
n_test_scans = 200
scans_path = os.path.join(data_dir, 'test/scans/')
scans = np.zeros([n_test_scans, n_scan_points, 3])
for fid in tqdm(range(0, n_test_scans)):
mesh_scan = trimesh.load_mesh(os.path.join(scans_path, 'test_scan_%03d.ply' % fid))
x = np.asarray(mesh_scan.sample(n_scan_points))
scans[fid] = x
return scans
def load_mesh(mesh_path):
"""Loads a mesh from file &computes it's centroid using V-REP style."""
mesh = trimesh.load_mesh(mesh_path)
# V-REP encodes the object centroid as the literal center of the object,
# so we need to make sure the points are centered the same way
center = lib.utils.calc_mesh_centroid(mesh, center_type='vrep')
mesh.vertices -= center
return mesh
f, ext = os.path.splitext(filename)
if ext == '.json':
return cls.from_json(filename=filename,
import_kwargs=import_kwargs,
**init_kwargs)
try:
import trimesh
except ImportError:
raise ImportError('Unable to import: trimesh missing - please '
'install: "pip install trimesh"')
except BaseException:
raise
tm = trimesh.load_mesh(filename, **import_kwargs)
return cls.from_object(tm, **init_kwargs)
for t_id,target_obj in enumerate(self.target_objs):
if(self.backbone=='resnet50'):
weight_fn = os.path.join(pix2pose_dir,"{:02d}/inference_resnet_model.hdf5".format(target_obj))
else:
weight_fn = os.path.join(pix2pose_dir,"{:02d}/inference.hdf5".format(target_obj))
print("Load pix2pose weights from ",weight_fn)
model_param = self.model_params['{}'.format(target_obj)]
obj_param=bop_io.get_model_params(model_param)
recog_temp = recog.pix2pose(weight_fn,camK= self.camK,
res_x=self.im_width,res_y=self.im_height,obj_param=obj_param,
th_ransac=self.ransac_th,th_outlier=th_outlier,th_inlier=self.inlier_th,backbone=self.backbone)
self.obj_pix2pose.append(recog_temp)
ply_fn = os.path.join(self.cfg['model_dir'],self.cfg['ply_files'][t_id])
if(self.icp):
#for pyrender rendering
obj_model = trimesh.load_mesh(ply_fn)
obj_model.vertices = obj_model.vertices*self.model_scale
mesh = pyrender.Mesh.from_trimesh(obj_model)
self.obj_models.append(mesh)
self.obj_bboxes.append(self.get_3d_box_points(obj_model.vertices))
else:
obj_model = inout.load_ply(ply_fn)
self.obj_bboxes.append(self.get_3d_box_points(obj_model['pts']))
rospy.init_node('pix2pose', anonymous=True)
self.detect_pub = rospy.Publisher("/pix2pose/detected_object",ros_image)
#self.pose_pub = rospy.Publisher("/pix2pose/object_pose", Pose)
self.pose_pub = rospy.Publisher("/pix2pose/object_pose", ros_image)
self.have_depth=False
plt.axis('off')
plt.draw()
plt.pause(GUI_PAUSE)
# read workspace bounds
workspace_box = Box(np.array(workspace_config['min_pt']),
np.array(workspace_config['max_pt']),
frame='world')
# read workspace objects
workspace_objects = {}
for obj_key, obj_config in workspace_config['objects'].iteritems():
mesh_filename = obj_config['mesh_filename']
pose_filename = obj_config['pose_filename']
print(mesh_filename)
obj_mesh = trimesh.load_mesh(mesh_filename)
obj_pose = RigidTransform.load(pose_filename)
obj_mat_props = MaterialProperties(smooth=True,
wireframe=False)
scene_obj = SceneObject(obj_mesh, obj_pose, obj_mat_props)
workspace_objects[obj_key] = scene_obj
# setup each sensor
datasets = {}
sensors = {}
sensor_poses = {}
camera_intrs = {}
workspace_ims = {}
for sensor_name, sensor_config in sensor_configs.iteritems():
# read params
sensor_type = sensor_config['type']
sensor_frame = sensor_config['frame']
cmap=plt.cm.gray_r)
plt.axis('off')
plt.draw()
plt.pause(GUI_PAUSE)
# read workspace bounds
workspace_box = Box(np.array(workspace_config['min_pt']),
np.array(workspace_config['max_pt']),
frame='world')
# read workspace objects
workspace_objects = {}
for obj_key, obj_config in workspace_config['objects'].iteritems():
mesh_filename = obj_config['mesh_filename']
pose_filename = obj_config['pose_filename']
obj_mesh = trimesh.load_mesh(mesh_filename)
obj_pose = RigidTransform.load(pose_filename)
obj_mat_props = MaterialProperties(smooth=True,
wireframe=False)
scene_obj = SceneObject(obj_mesh, obj_pose, obj_mat_props)
workspace_objects[obj_key] = scene_obj
# setup each sensor
datasets = {}
sensors = {}
sensor_poses = {}
camera_intrs = {}
workspace_ims = {}
for sensor_name, sensor_config in sensor_configs.iteritems():
# read params
sensor_type = sensor_config['type']
sensor_frame = sensor_config['frame']