Spaces:
Sleeping
Sleeping
imabackstabber
commited on
Commit
•
6072e4f
1
Parent(s):
f65bf7c
test postometro pipeline
Browse files- common/utils/__pycache__/vis.cpython-39.pyc +0 -0
- common/utils/vis.py +19 -1
- main/inference.py +6 -6
common/utils/__pycache__/vis.cpython-39.pyc
CHANGED
Binary files a/common/utils/__pycache__/vis.cpython-39.pyc and b/common/utils/__pycache__/vis.cpython-39.pyc differ
|
|
common/utils/vis.py
CHANGED
@@ -138,6 +138,20 @@ def perspective_projection(vertices, cam_param):
|
|
138 |
vertices[:, 1] = vertices[:, 1] * fy / vertices[:, 2] + cy
|
139 |
return vertices
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
class WeakPerspectiveCamera(pyrender.Camera):
|
142 |
def __init__(self, scale, translation, znear=pyrender.camera.DEFAULT_Z_NEAR, zfar=None, name=None):
|
143 |
super(WeakPerspectiveCamera, self).__init__(znear=znear, zfar=zfar, name=name)
|
@@ -156,7 +170,11 @@ class WeakPerspectiveCamera(pyrender.Camera):
|
|
156 |
def render_mesh(img, mesh, face, cam_param, mesh_as_vertices=False):
|
157 |
if mesh_as_vertices:
|
158 |
# to run on cluster where headless pyrender is not supported for A100/V100
|
159 |
-
|
|
|
|
|
|
|
|
|
160 |
img = vis_keypoints(img, vertices_2d, alpha=0.8, radius=2, color=(0, 0, 255))
|
161 |
else:
|
162 |
# mesh
|
|
|
138 |
vertices[:, 1] = vertices[:, 1] * fy / vertices[:, 2] + cy
|
139 |
return vertices
|
140 |
|
141 |
+
def orthographic_projection(X, cam_param):
|
142 |
+
"""Perform orthographic projection of 3D points X using the camera parameters
|
143 |
+
Args:
|
144 |
+
X: size = [N, 3]
|
145 |
+
camera: size = [4]: sx, sy, tx, ty
|
146 |
+
Returns:
|
147 |
+
Projected 2D points -- size = [N, 2]
|
148 |
+
"""
|
149 |
+
sx, sy, tx, ty = cam_param
|
150 |
+
X_trans = X[:,:2].copy()
|
151 |
+
X_trans[:,0] = (X_trans[:,0] + tx) * sx
|
152 |
+
X_trans[:,1] = (X_trans[:,1] + ty) * sy
|
153 |
+
return X_trans.copy()
|
154 |
+
|
155 |
class WeakPerspectiveCamera(pyrender.Camera):
|
156 |
def __init__(self, scale, translation, znear=pyrender.camera.DEFAULT_Z_NEAR, zfar=None, name=None):
|
157 |
super(WeakPerspectiveCamera, self).__init__(znear=znear, zfar=zfar, name=name)
|
|
|
170 |
def render_mesh(img, mesh, face, cam_param, mesh_as_vertices=False):
|
171 |
if mesh_as_vertices:
|
172 |
# to run on cluster where headless pyrender is not supported for A100/V100
|
173 |
+
viewport_height, viewport_width = img.shape[0], img.shape[1]
|
174 |
+
vertices_2d = orthographic_projection(mesh, cam_param) # [-1,1]
|
175 |
+
vertices_2d = (vertices_2d + 1) / 2
|
176 |
+
vertices_2d[:,0] *= viewport_width
|
177 |
+
vertices_2d[:,1] *= viewport_height
|
178 |
img = vis_keypoints(img, vertices_2d, alpha=0.8, radius=2, color=(0, 0, 255))
|
179 |
else:
|
180 |
# mesh
|
main/inference.py
CHANGED
@@ -100,10 +100,10 @@ class Inferer:
|
|
100 |
ok_bboxes.append(bbox)
|
101 |
|
102 |
# [DEBUG] test mmdet pipeline
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
|
108 |
# human model inference
|
109 |
img, img2bb_trans, bb2img_trans = generate_patch_image(original_img, bbox, 1.0, 0.0, False, self.cfg.input_img_shape)
|
@@ -141,12 +141,12 @@ class Inferer:
|
|
141 |
|
142 |
if __name__ == '__main__':
|
143 |
from PIL import Image
|
144 |
-
inferer = Inferer('postometro',
|
145 |
image_path = f'../assets/07.jpg'
|
146 |
image = Image.open(image_path)
|
147 |
# Convert the PIL image to a NumPy array
|
148 |
image_np = np.array(image)
|
149 |
-
vis_img, _ , _ = inferer.infer(image_np, 0.2, multi_person=True, mesh_as_vertices=
|
150 |
save_path = f'./saved_vis_07.jpg'
|
151 |
|
152 |
# Ensure the image is in the correct format (PIL expects uint8)
|
|
|
100 |
ok_bboxes.append(bbox)
|
101 |
|
102 |
# [DEBUG] test mmdet pipeline
|
103 |
+
if bbox is not None:
|
104 |
+
top_left = (int(bbox[0]), int(bbox[1]))
|
105 |
+
bottom_right = (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3]))
|
106 |
+
cv2.rectangle(vis_img, top_left, bottom_right, (0, 0, 255), 2)
|
107 |
|
108 |
# human model inference
|
109 |
img, img2bb_trans, bb2img_trans = generate_patch_image(original_img, bbox, 1.0, 0.0, False, self.cfg.input_img_shape)
|
|
|
141 |
|
142 |
if __name__ == '__main__':
|
143 |
from PIL import Image
|
144 |
+
inferer = Inferer('postometro', 1, './out_folder') # gpu
|
145 |
image_path = f'../assets/07.jpg'
|
146 |
image = Image.open(image_path)
|
147 |
# Convert the PIL image to a NumPy array
|
148 |
image_np = np.array(image)
|
149 |
+
vis_img, _ , _ = inferer.infer(image_np, 0.2, multi_person=True, mesh_as_vertices=True)
|
150 |
save_path = f'./saved_vis_07.jpg'
|
151 |
|
152 |
# Ensure the image is in the correct format (PIL expects uint8)
|