Skip to content

Commit

Permalink
add tracking demo
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxi-wang committed Nov 29, 2022
1 parent 7dcd32d commit e9fc635
Show file tree
Hide file tree
Showing 62 changed files with 106 additions and 0 deletions.
105 changes: 105 additions & 0 deletions grasp_tracking/demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import os
import argparse
import numpy as np
import open3d as o3d
from PIL import Image
from graspnetAPI import GraspGroup

from tracker import AnyGraspTracker

parser = argparse.ArgumentParser()
parser.add_argument('--checkpoint_path', required=True, help='Model checkpoint path')
parser.add_argument('--filter', type=str, default='oneeuro', help='filter to smooth grasp parameters(rotation, width, depth). [oneeuro/kalman/none]')

parser.add_argument('--debug', action='store_true', help='Enable debug mode')
cfgs = parser.parse_args()

class CameraInfo:
def __init__(self, width, height, fx, fy, cx, cy, scale):
self.width = width
self.height = height
self.fx = fx
self.fy = fy
self.cx = cx
self.cy = cy
self.scale = scale

def create_point_cloud_from_depth_image(depth, camera, organized=True):
assert(depth.shape[0] == camera.height and depth.shape[1] == camera.width)
xmap = np.arange(camera.width)
ymap = np.arange(camera.height)
xmap, ymap = np.meshgrid(xmap, ymap)
points_z = depth / camera.scale
points_x = (xmap - camera.cx) * points_z / camera.fx
points_y = (ymap - camera.cy) * points_z / camera.fy
points = np.stack([points_x, points_y, points_z], axis=-1)
if not organized:
points = points.reshape([-1, 3])
return points

def get_data(data_dir, index):
# load image
colors = np.array(Image.open(os.path.join(data_dir, 'color_%03d.png'%index)), dtype=np.float32) / 255.0
depths = np.load(os.path.join(data_dir, 'depth_%03d.npy'%index))

# set camera intrinsics
width, height = depths.shape[1], depths.shape[0]
fx, fy = 927.17, 927.37
cx, cy = 651.32, 349.62
scale = 1000.0
camera = CameraInfo(width, height, fx, fy, cx, cy, scale)

# get point cloud
points = create_point_cloud_from_depth_image(depths, camera)
mask = (points[:,:,2] > 0) & (points[:,:,2] < 1.5)
points = points[mask]
colors = colors[mask]

return points, colors

def demo(data_dir_list, indices):
# intialization
anygrasp_tracker = AnyGraspTracker(cfgs)
anygrasp_tracker.load_net()

grasp_ids = [0]
vis = o3d.visualization.Visualizer()
vis.create_window(height=720, width=1280)
for i in range(len(indices)):
# get prediction
points, colors = get_data(data_dir_list, indices[i])
target_gg, curr_gg, target_grasp_ids, corres_preds = anygrasp_tracker.update(points, colors, grasp_ids)

if i == 0:
# select grasps on objects to track for the 1st frame
grasp_mask_x = ((curr_gg.translations[:,0]>-0.18) & (curr_gg.translations[:,0]<0.18))
grasp_mask_y = ((curr_gg.translations[:,1]>-0.12) & (curr_gg.translations[:,1]<0.12))
grasp_mask_z = ((curr_gg.translations[:,2]>0.35) & (curr_gg.translations[:,2]<0.55))
grasp_ids = np.where(grasp_mask_x & grasp_mask_y & grasp_mask_z)[0][:30:6]
target_gg = curr_gg[grasp_ids]
else:
grasp_ids = target_grasp_ids
print(i, target_grasp_ids)

# visualization
if cfgs.debug:
trans_mat = np.array([[1,0,0,0],[0,1,0,0],[0,0,-1,0],[0,0,0,1]])
cloud = o3d.geometry.PointCloud()
cloud.points = o3d.utility.Vector3dVector(points)
cloud.colors = o3d.utility.Vector3dVector(colors)
cloud.transform(trans_mat)
grippers = target_gg.to_open3d_geometry_list()
for gripper in grippers:
gripper.transform(trans_mat)
vis.add_geometry(cloud)
for gripper in grippers:
vis.add_geometry(gripper)
vis.poll_events()
vis.remove_geometry(cloud)
for gripper in grippers:
vis.remove_geometry(gripper)

if __name__ == "__main__":
data_dir = "example_data"
data_dir_list = [x for x in range(30)]
demo(data_dir, data_dir_list)
1 change: 1 addition & 0 deletions grasp_tracking/demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python demo.py --checkpoint_path log/checkpoint_track_graspnetv1_4depth.tar --filter oneeuro
Binary file added grasp_tracking/example_data/color_000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_001.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_002.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_003.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_005.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_006.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_007.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_008.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_009.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_010.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_011.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_012.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_013.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_014.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_015.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_016.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_017.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_018.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_019.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_020.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_021.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_022.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_023.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_024.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added grasp_tracking/example_data/color_025.png
Binary file added grasp_tracking/example_data/color_026.png
Binary file added grasp_tracking/example_data/color_027.png
Binary file added grasp_tracking/example_data/color_028.png
Binary file added grasp_tracking/example_data/color_029.png
Binary file added grasp_tracking/example_data/depth_000.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_001.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_002.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_003.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_004.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_005.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_006.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_007.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_008.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_009.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_010.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_011.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_012.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_013.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_014.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_015.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_016.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_017.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_018.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_019.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_020.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_021.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_022.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_023.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_024.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_025.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_026.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_027.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_028.npy
Binary file not shown.
Binary file added grasp_tracking/example_data/depth_029.npy
Binary file not shown.

0 comments on commit e9fc635

Please sign in to comment.