赞
踩
您可以通过以下代码检查数据集中是否有任何丢失的文件。
from graspnetAPI import GraspNet # GraspNetAPI example for checking the data completeness. # change the graspnet_root path ### ROOT PATH FOR GRASPNET ### graspnet_root = 'E:\datasets\GraspNet' g = GraspNet(graspnet_root, 'kinect', 'all') if g.checkDataCompleteness(): print('\n') print('Check for kinect passed') g = GraspNet(graspnet_root, 'realsense', 'all') if g.checkDataCompleteness(): print('Check for realsense passed')
您可以自行生成矩形抓取标签。
# 1.导入必要的库: # GraspNetAPI example for generating rectangle grasp from 6d grasp. # change the graspnet_root path and NUM_PROCESS from graspnetAPI import GraspNet from graspnetAPI.graspnet import TOTAL_SCENE_NUM import os import numpy as np from tqdm import tqdm # 2.设置在生成标签时使用的进程数。 ###################################################################### NUM_PROCESS = 24 # change NUM_PROCESS to the number of cores to use. # ###################################################################### # 3. 生成标签的函数。 def generate_scene_rectangle_grasp(sceneId, dump_folder, camera): g = GraspNet(graspnet_root, camera=camera, split='all') objIds = g.getObjIds(sceneIds = sceneId) grasp_labels = g.loadGraspLabels(objIds) collision_labels = g.loadCollisionLabels(sceneIds = sceneId) scene_dir = os.path.join(dump_folder,'scene_%04d' % sceneId) if not os.path.exists(scene_dir): os.mkdir(scene_dir) camera_dir = os.path.join(scene_dir, camera) if not os.path.exists(camera_dir): os.mkdir(camera_dir) for annId in tqdm(range(256), 'Scene:{}, Camera:{}'.format(sceneId, camera)): _6d_grasp = g.loadGrasp(sceneId = sceneId, annId = annId, format = '6d', camera = camera, grasp_labels = grasp_labels, collision_labels = collision_labels, fric_coef_thresh = 1.0) rect_grasp_group = _6d_grasp.to_rect_grasp_group(camera) rect_grasp_group.save_npy(os.path.join(camera_dir, '%04d.npy' % annId)) # 4.为每个场景和相机运行该函数。 if __name__ == '__main__': #################################################################### graspnet_root = 'E:\datasets\GraspNet' # ROOT PATH FOR GRASPNET ## #################################################################### dump_folder = 'rect_labels' if not os.path.exists(dump_folder): os.mkdir(dump_folder) if NUM_PROCESS > 1: from multiprocessing import Pool pool = Pool(24) for camera in ['realsense', 'kinect']: for sceneId in range(120): pool.apply_async(func = generate_scene_rectangle_grasp, args = (sceneId, dump_folder, camera)) pool.close() pool.join() else: generate_scene_rectangle_grasp(sceneId, dump_folder, camera)
6D 和 rect 格式标签都可以被加载。
# 1.导入相关库。 from graspnetAPI import GraspNet import open3d as o3d import cv2 # GraspNetAPI example for loading grasp for a scene. # change the graspnet_root path # 2.设置参数 and 创建 GraspNet 实例 #################################################################### graspnet_root = 'E:\datasets\GraspNet' # ROOT PATH FOR GRASPNET #################################################################### sceneId = 1 annId = 3 # initialize a GraspNet instance g = GraspNet(graspnet_root, camera='kinect', split='train') # 3.以6d格式加载 Grasp Label,并可视化结果。 # load grasps of scene 1 with annotation id = 3, camera = kinect and fric_coef_thresh = 0.2 _6d_grasp = g.loadGrasp(sceneId = sceneId, annId = annId, format = '6d', camera = 'kinect', fric_coef_thresh = 0.2) print('6d grasp:\n{}'.format(_6d_grasp)) # visualize the grasps using open3d geometries = [] geometries.append(g.loadScenePointCloud(sceneId = sceneId, annId = annId, camera = 'kinect')) geometries += _6d_grasp.random_sample(numGrasp = 20).to_open3d_geometry_list() o3d.visualization.draw_geometries(geometries) # 4.以矩形格式加载 Grasp Label ,并可视化结果。 # load rectangle grasps of scene 1 with annotation id = 3, camera = realsense and fric_coef_thresh = 0.2 rect_grasp = g.loadGrasp(sceneId = sceneId, annId = annId, format = 'rect', camera = 'realsense', fric_coef_thresh = 0.2) print('rectangle grasp:\n{}'.format(rect_grasp)) # visualize the rectanglegrasps using opencv bgr = g.loadBGR(sceneId = sceneId, annId = annId, camera = 'realsense') img = rect_grasp.to_opencv_image(bgr, numGrasp = 20) cv2.imshow('rectangle grasps', img) cv2.waitKey(0) cv2.destroyAllWindows()
Visualization of Dataset
# GraspNetAPI example for visualization.
# change the graspnet_root path
####################################################################
graspnet_root = 'E:\datasets\GraspNet' # ROOT PATH FOR GRASPNET
####################################################################
from graspnetAPI import GraspNet
# 1. initialize a GraspNet instance
g = GraspNet(graspnet_root, camera='kinect', split='train')
在物体上显示grasp labels。
# 2.1 show object grasps
g.showObjGrasp(objIds = 0, show=True)
显示场景中物体的6d poses。
# 2.2 show 6d poses
g.show6DPose(sceneIds = 0, show = True)
在场景中显示矩形grasp labels。
# 2.3 show scene rectangle grasps
g.showSceneGrasp(sceneId = 0, camera = 'realsense', annId = 0, format = 'rect', numGrasp = 20)
在场景中显示 6D grasp labels。
# 2.4 show scene 6d grasps(You may need to wait several minutes)
g.showSceneGrasp(sceneId = 4, camera = 'kinect', annId = 2, format = '6d')
每个物体的初始标签均为一个np.arry列表。
。
。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。