Small speed improvements.
This commit is contained in:
@ -46,7 +46,7 @@ def undistort_points(points: np.ndarray, caminfo: dict):
|
||||
points = cv2.undistortPoints(points, K, DC, P=newK)
|
||||
points = points.reshape(pshape)
|
||||
|
||||
return points
|
||||
return points, caminfo
|
||||
|
||||
|
||||
# ==================================================================================================
|
||||
@ -104,9 +104,7 @@ def calc_pose_scored(pose1, pose2, cam1, cam2, roomparams):
|
||||
# Triangulate points
|
||||
points1 = pose1[mask, 0:2].T
|
||||
points2 = pose2[mask, 0:2].T
|
||||
P1 = get_camera_P(cam1)
|
||||
P2 = get_camera_P(cam2)
|
||||
points3d = cv2.triangulatePoints(P1, P2, points1, points2)
|
||||
points3d = cv2.triangulatePoints(cam1["P"], cam2["P"], points1, points2)
|
||||
points3d = (points3d / points3d[3, :])[0:3, :].T
|
||||
pose3d = np.zeros([len(pose1), 4])
|
||||
pose3d[mask] = np.concatenate([points3d, np.ones([points3d.shape[0], 1])], axis=-1)
|
||||
@ -295,14 +293,26 @@ def get_3d_pose(poses_2d, camparams, roomparams, joint_names_2d, min_score=0.95)
|
||||
camparams[i]["K"] = np.array(camparams[i]["K"])
|
||||
camparams[i]["R"] = np.array(camparams[i]["R"])
|
||||
camparams[i]["T"] = np.array(camparams[i]["T"])
|
||||
camparams[i]["DC"] = np.array(camparams[i]["DC"][0:5])
|
||||
camparams[i]["DC"] = np.array(camparams[i]["DC"])
|
||||
|
||||
# Undistort 2D points
|
||||
for i in range(len(camparams)):
|
||||
poses = poses_2d[i]
|
||||
cam = camparams[i]
|
||||
poses[:, :, 0:2] = undistort_points(poses[:, :, 0:2], cam)
|
||||
poses[:, :, 0:2], cam = undistort_points(poses[:, :, 0:2], cam)
|
||||
# Mask out points that are far outside the image (points slightly outside are still valid)
|
||||
offset = (cam["width"] + cam["height"]) / 40
|
||||
mask = (
|
||||
(poses[:, :, 0] >= 0 - offset)
|
||||
& (poses[:, :, 0] < cam["width"] + offset)
|
||||
& (poses[:, :, 1] >= 0 - offset)
|
||||
& (poses[:, :, 1] < cam["height"] + offset)
|
||||
)
|
||||
poses = poses * np.expand_dims(mask, axis=-1)
|
||||
poses_2d[i] = poses
|
||||
# Calc projection matrix with updated camera parameters
|
||||
cam["P"] = get_camera_P(cam)
|
||||
camparams[i] = cam
|
||||
|
||||
# Create pairs of persons
|
||||
num_persons = [len(p) for p in poses_2d]
|
||||
|
||||
Reference in New Issue
Block a user