From ac576e22c325bb8e586a2a359d8e8db26e0b38d6 Mon Sep 17 00:00:00 2001
From: liuxingyu <lxy17@foxmail.com>
Date: Mon, 17 Apr 2023 10:59:46 +0800
Subject: [PATCH] add algorithm for compute keypoint

---
 .../tools/lmo/lmo_1_compute_keypoints_3d.py   | 46 +++++++++++++++++++
 1 file changed, 46 insertions(+)
 create mode 100644 core/gdrn_modeling/tools/lmo/lmo_1_compute_keypoints_3d.py

diff --git a/core/gdrn_modeling/tools/lmo/lmo_1_compute_keypoints_3d.py b/core/gdrn_modeling/tools/lmo/lmo_1_compute_keypoints_3d.py
new file mode 100644
index 0000000..8305268
--- /dev/null
+++ b/core/gdrn_modeling/tools/lmo/lmo_1_compute_keypoints_3d.py
@@ -0,0 +1,46 @@
+# compute bbox3d, fps (farthest point sampling) for models
+import os.path as osp
+import sys
+from tqdm import tqdm
+
+cur_dir = osp.dirname(osp.abspath(__file__))
+sys.path.insert(0, osp.join(cur_dir, "../../../../"))
+import mmcv
+from lib.pysixd import inout, misc
+import ref
+from core.utils.data_utils import get_fps_and_center
+
+
+ref_key = "lmo_full"
+data_ref = ref.__dict__[ref_key]
+
+model_dir = data_ref.model_dir
+id2obj = data_ref.id2obj
+
+
+def main():
+    vertex_scale = 0.001
+    kpts3d_dict = {}
+    for obj_id in tqdm(id2obj):
+        print(obj_id)
+        model_path = osp.join(model_dir, f"obj_{obj_id:06d}.ply")
+        model = inout.load_ply(model_path, vertex_scale=vertex_scale)
+        kpts3d_dict[str(obj_id)] = {}
+        kpts3d_dict[str(obj_id)]["bbox3d_and_center"] = misc.get_bbox3d_and_center(model["pts"])
+        kpts3d_dict[str(obj_id)]["fps4_and_center"] = get_fps_and_center(model["pts"], num_fps=4, init_center=True)
+        kpts3d_dict[str(obj_id)]["fps8_and_center"] = get_fps_and_center(model["pts"], num_fps=8, init_center=True)
+        kpts3d_dict[str(obj_id)]["fps12_and_center"] = get_fps_and_center(model["pts"], num_fps=12, init_center=True)
+        kpts3d_dict[str(obj_id)]["fps16_and_center"] = get_fps_and_center(model["pts"], num_fps=16, init_center=True)
+        kpts3d_dict[str(obj_id)]["fps20_and_center"] = get_fps_and_center(model["pts"], num_fps=20, init_center=True)
+        kpts3d_dict[str(obj_id)]["fps32_and_center"] = get_fps_and_center(model["pts"], num_fps=32, init_center=True)
+        kpts3d_dict[str(obj_id)]["fps64_and_center"] = get_fps_and_center(model["pts"], num_fps=64, init_center=True)
+        kpts3d_dict[str(obj_id)]["fps128_and_center"] = get_fps_and_center(model["pts"], num_fps=128, init_center=True)
+        kpts3d_dict[str(obj_id)]["fps256_and_center"] = get_fps_and_center(model["pts"], num_fps=256, init_center=True)
+
+    save_path = osp.join(model_dir, "keypoints_3d.pkl")
+    mmcv.dump(kpts3d_dict, save_path)
+    print(f"saved to {save_path}")
+
+
+if __name__ == "__main__":
+    main()
-- 
GitLab