forked from GouMinghao/rgb_matters
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gen_normals.py
50 lines (47 loc) · 1.81 KB
/
gen_normals.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
__author__ = "Minghao Gou"
__version__ = "1.0"
import cv2
import numpy as np
import open3d as o3d
import os
from graspnetAPI import GraspNet
from tqdm import tqdm
import argparse
from rgbd_graspnet.constant import GRASPNET_ROOT, NORMALS_DIR
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--camera",
default="realsense",
choices=["realsense", "kinect", "both"],
help="which camera(s) to generate",
)
parser.add_argument("--skip", default=True, help="skip existed normals")
args = parser.parse_args()
cameras = ["realsense", "kinect"] if args.camera == "both" else [args.camera]
for camera in cameras:
g = GraspNet(GRASPNET_ROOT, camera=camera)
scene_list = list(range(190))
for scene_id in scene_list:
for ann_id in tqdm(
range(256), "Generating normal for scene {}".format(scene_id)
):
normal_dir = os.path.join(NORMALS_DIR, "scene_%04d" % scene_id, camera)
normal_path = os.path.join(normal_dir, "%04d.png" % ann_id)
if args.skip:
if os.path.exists(normal_path):
continue
os.makedirs(normal_dir, exist_ok=True)
pcd = g.loadScenePointCloud(
scene_id,
camera,
ann_id,
use_inpainting=True,
use_mask=False,
use_workspace=False,
)
pcd.estimate_normals(o3d.geometry.KDTreeSearchParamKNN(150))
normals = np.asarray(pcd.normals)
normal = normals.reshape((720, 1280, 3))
normal = ((normal + 1.0) / 2 * 255.0).astype(np.uint8)
cv2.imwrite(normal_path, normal)