MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / estimate_translation_np

Function estimate_translation_np

detrsmpl/utils/geometry.py:278–326  ·  view source on GitHub ↗

Find camera translation that brings 3D joints S closest to 2D the corresponding joints_2d. Input: S: (25, 3) 3D joint locations joints: (25, 3) 2D joint locations and confidence Returns: (3,) camera translation vector

(S,
                            joints_2d,
                            joints_conf,
                            focal_length=5000,
                            img_size=224)

Source from the content-addressed store, hash-verified

276
277
278def estimate_translation_np(S,
279 joints_2d,
280 joints_conf,
281 focal_length=5000,
282 img_size=224):
283 """Find camera translation that brings 3D joints S closest to 2D the
284 corresponding joints_2d.
285
286 Input:
287 S: (25, 3) 3D joint locations
288 joints: (25, 3) 2D joint locations and confidence
289 Returns:
290 (3,) camera translation vector
291 """
292
293 num_joints = S.shape[0]
294 # focal length
295 f = np.array([focal_length, focal_length])
296 # optical center
297 center = np.array([img_size / 2., img_size / 2.])
298
299 # transformations
300 Z = np.reshape(np.tile(S[:, 2], (2, 1)).T, -1)
301 XY = np.reshape(S[:, 0:2], -1)
302 OO = np.tile(center, num_joints)
303 F = np.tile(f, num_joints)
304 weight2 = np.reshape(np.tile(np.sqrt(joints_conf), (2, 1)).T, -1)
305
306 # least squares
307 Q = np.array([
308 F * np.tile(np.array([1, 0]), num_joints),
309 F * np.tile(np.array([0, 1]), num_joints),
310 OO - np.reshape(joints_2d, -1)
311 ]).T
312 c = (np.reshape(joints_2d, -1) - OO) * Z - F * XY
313
314 # weighted least squares
315 W = np.diagflat(weight2)
316 Q = np.dot(W, Q)
317 c = np.dot(W, c)
318
319 # square matrix
320 A = np.dot(Q.T, Q)
321 b = np.dot(Q.T, c)
322
323 # solution
324 trans = np.linalg.solve(A, b)
325
326 return trans
327
328
329def estimate_translation(S, joints_2d, focal_length=5000., img_size=224.):

Callers 1

estimate_translationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected