code stringlengths 66 870k | docstring stringlengths 19 26.7k | func_name stringlengths 1 138 | language stringclasses 1
value | repo stringlengths 7 68 | path stringlengths 5 324 | url stringlengths 46 389 | license stringclasses 7
values |
|---|---|---|---|---|---|---|---|
def get_checkpoints(y):
"""
Args:
y (torch.Tensor or np.ndarray): (bs, )
Returns:
checkpoints (list): all checkpoints of the jumpint points.
"""
y_len = len(y)
checkpoints = [0]
for i in range(1, y_len - 1):
pre = y[i] - y[... |
Args:
y (torch.Tensor or np.ndarray): (bs, )
Returns:
checkpoints (list): all checkpoints of the jumpint points.
| get_checkpoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/cam_pose_utils.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/cam_pose_utils.py | Apache-2.0 |
def get_jump_mask(self, final_foot_y):
"""
Args:
final_foot_y (np.ndarray): (bs,)
Returns:
jump_info_list (list of tuple): [(start_idx, end_idx), ...];
jump_mask (np.ndarray): (bs,), 1 for jumping status.
"""
frame_num = final_foot_y.shape[0... |
Args:
final_foot_y (np.ndarray): (bs,)
Returns:
jump_info_list (list of tuple): [(start_idx, end_idx), ...];
jump_mask (np.ndarray): (bs,), 1 for jumping status.
| get_jump_mask | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/cam_pose_utils.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/cam_pose_utils.py | Apache-2.0 |
def cam_init2orig(cam, scale: Union[float, torch.Tensor], start_pt: torch.Tensor, N=224):
"""
Args:
cam (bs, 3): (s, tx, ty)
scale (bs,): scale = resize_h / orig_h
start_pt (bs, 2): (lt_x, lt_y)
N (int): hmr_image_size (224) or IMG_SIZE
Returns:
cam_orig (bs, 3): (s,... |
Args:
cam (bs, 3): (s, tx, ty)
scale (bs,): scale = resize_h / orig_h
start_pt (bs, 2): (lt_x, lt_y)
N (int): hmr_image_size (224) or IMG_SIZE
Returns:
cam_orig (bs, 3): (s, tx, ty), camera in original image coordinates.
| cam_init2orig | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/cam_pose_utils.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/cam_pose_utils.py | Apache-2.0 |
def temporal_smooth_keypoints(stack_keypoints):
"""
Args:
stack_keypoints (dict): the stacked keypoints information, it contains,
--pose_keypoints_2d (np.ndarray): (n, 25 * 3) = (n, 25 * (x,y,score));
Returns:
ts_keypoints (dict): the temporal smoothed k... |
Args:
stack_keypoints (dict): the stacked keypoints information, it contains,
--pose_keypoints_2d (np.ndarray): (n, 25 * 3) = (n, 25 * (x,y,score));
Returns:
ts_keypoints (dict): the temporal smoothed keypoints information, it contains,
--pose_k... | temporal_smooth_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def format_keypoints(self, keypoints, im_shape=None):
"""
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
If im_shape is None, then keypoints must be [-1, 1].
Args:
keypoints (dict): the keypoints information, and it contains,
... |
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
If im_shape is None, then keypoints must be [-1, 1].
Args:
keypoints (dict): the keypoints information, and it contains,
--pose_keypoints_2d (np.ndarray or list): (25 * 3) = ... | format_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def format_stacked_keypoints(self, ids, keypoints, im_shape):
"""
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
Args:
ids (int): the index.
keypoints (dict): the keypoints information, it contains,
--pose_keypo... |
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
Args:
ids (int): the index.
keypoints (dict): the keypoints information, it contains,
--pose_keypoints_2d (np.ndarray): (n, 25 * 3) = (n, 25 * (x,y,score))
im... | format_stacked_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def stack_keypoints(self, keypoints_list):
"""
Stack all list of keypoints dict in t-axis.
Args:
keypoints_list (dict):
--pose_keypoints_2d (list of dict): [keypoints_info_1, keypoints_info_2, ..., keypoints_info_n],
each keypoints_info_i is dicti... |
Stack all list of keypoints dict in t-axis.
Args:
keypoints_list (dict):
--pose_keypoints_2d (list of dict): [keypoints_info_1, keypoints_info_2, ..., keypoints_info_n],
each keypoints_info_i is dictionary, and it contains the following information:
... | stack_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def format_keypoints(self, keypoints, im_shape=None):
"""
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
If im_shape is None, then keypoints must be [-1, 1].
Args:
keypoints (dict): the keypoints information, and it contains,
... |
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
If im_shape is None, then keypoints must be [-1, 1].
Args:
keypoints (dict): the keypoints information, and it contains,
--pose_keypoints_2d (np.ndarray or list): (23 * 3) = ... | format_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def format_stacked_keypoints(self, ids, keypoints, im_shape):
"""
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
Args:
ids (int): the index.
keypoints (dict): the keypoints information, it contains,
--pose_keypo... |
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
Args:
ids (int): the index.
keypoints (dict): the keypoints information, it contains,
--pose_keypoints_2d (np.ndarray): (n, 23 * 3) = (n, 23 * (x,y,score))
im... | format_stacked_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def stack_keypoints(self, keypoints_list):
"""
Stack all list of keypoints dict in t-axis.
Args:
keypoints_list (List[Dict]): list of keypoints dictionary information, and each dict contains,
--pose_keypoints_2d (np.ndarray or list): (23, 3) is in the range of [0, he... |
Stack all list of keypoints dict in t-axis.
Args:
keypoints_list (List[Dict]): list of keypoints dictionary information, and each dict contains,
--pose_keypoints_2d (np.ndarray or list): (23, 3) is in the range of [0, height/width];
--face_keypoints_2d (np.n... | stack_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def format_keypoints(self, keypoints, im_shape=None):
"""
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
If im_shape is None, then keypoints must be [-1, 1].
Args:
keypoints (dict): the keypoints information, and it contains,
... |
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
If im_shape is None, then keypoints must be [-1, 1].
Args:
keypoints (dict): the keypoints information, and it contains,
--pose_keypoints_2d (np.ndarray or list): (26 * 3) = ... | format_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def format_stacked_keypoints(self, ids, keypoints, im_shape):
"""
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
Args:
ids (int): the index.
keypoints (dict): the keypoints information, it contains,
--pose_keypo... |
Format the keypoints, normalize the range from [0, height/width] to [0, 224] for simplify.
Args:
ids (int): the index.
keypoints (dict): the keypoints information, it contains,
--pose_keypoints_2d (np.ndarray): (n, 26 * 3) = (n, 26 * (x,y,score))
im... | format_stacked_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def stack_keypoints(self, keypoints_list_or_dict):
"""
Stack all list of keypoints dict in t-axis.
Args:
keypoints_list_or_dict (list of dict): [keypoints_1, keypoints_2, ..., keypoints_n].
Each keypoints_i contains,
--pose_keypoints_2d (np.ndarra... |
Stack all list of keypoints dict in t-axis.
Args:
keypoints_list_or_dict (list of dict): [keypoints_1, keypoints_2, ..., keypoints_n].
Each keypoints_i contains,
--pose_keypoints_2d (np.ndarray or list): (26 * 3) = (26 * (x,y,score))
... | stack_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/keypoints.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/keypoints.py | Apache-2.0 |
def save_to_obj(path, verts, faces, vts, vns, faces_vts, faces_vns):
"""
Save the SMPL model into .obj file.
Parameter:
---------
path: Path to save.
"""
with open(path, "w") as fp:
fp.write("g\n")
for v in verts:
fp.write("v %.8f %.8f %.8f\n" % (v[0], v[1], v[... |
Save the SMPL model into .obj file.
Parameter:
---------
path: Path to save.
| save_to_obj | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/mesh.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/mesh.py | Apache-2.0 |
def compute_uvsampler(verts, faces, tex_size=2):
"""
For this mesh, pre-computes the UV coordinates for
F x T x T points.
Returns F x T x T x 2
"""
alpha = np.arange(tex_size, dtype=np.float) / (tex_size - 1)
beta = np.arange(tex_size, dtype=np.float) / (tex_size - 1)
# Barycentric coord... |
For this mesh, pre-computes the UV coordinates for
F x T x T points.
Returns F x T x T x 2
| compute_uvsampler | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/mesh.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/mesh.py | Apache-2.0 |
def create_uvsampler(uv_mapping_path="data/uv_mappings.txt", tex_size=2, fill_back=False):
"""
For this mesh, pre-computes the UV coordinates for
F x T x T points.
Returns F x T*T x 2
"""
alpha = np.arange(tex_size, dtype=np.float32) / (tex_size - 1)
beta = np.arange(tex_size, dtype=np.float... |
For this mesh, pre-computes the UV coordinates for
F x T x T points.
Returns F x T*T x 2
| create_uvsampler | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/mesh.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/mesh.py | Apache-2.0 |
def get_f2vts(uv_map_path_or_obj_info, fill_back=False, z=1):
"""
For this mesh, pre-computes the bary-center coords.
Returns F x 3 x 3
"""
if isinstance(uv_map_path_or_obj_info, str):
obj_info = load_obj(uv_map_path_or_obj_info)
else:
obj_info = uv_map_path_or_obj_info
vts... |
For this mesh, pre-computes the bary-center coords.
Returns F x 3 x 3
| get_f2vts | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/mesh.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/mesh.py | Apache-2.0 |
def cal_face_k_nearest(fbc, nearest_k=10):
"""
Args:
fbc (np.ndarray): f x 3 or (nf x 2)
nearest_k (int): the nearest percent
Returns:
nearest_ids (np.ndarray): f x nearest_k
"""
# f x f
nf = fbc.shape[0]
fbc_square = fbc ** 2
fbc_square_sum = np.sum(fbc_square,... |
Args:
fbc (np.ndarray): f x 3 or (nf x 2)
nearest_k (int): the nearest percent
Returns:
nearest_ids (np.ndarray): f x nearest_k
| cal_face_k_nearest | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/mesh.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/mesh.py | Apache-2.0 |
def find_part_k_nearest_faces(f2vts, parts, k=20):
"""
Args:
f2vts (np.ndarray): F x 3 x 3
parts (dict):
k (int):
Returns:
face_k_nearest:
"""
fbc = compute_barycenter(f2vts)
nf = fbc.shape[0]
face_k_nearest = np.empty((nf, k), dtype=np.int)
for name, f... |
Args:
f2vts (np.ndarray): F x 3 x 3
parts (dict):
k (int):
Returns:
face_k_nearest:
| find_part_k_nearest_faces | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/mesh.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/mesh.py | Apache-2.0 |
def create_mapping(map_name, obj_info,
part_path="assets/configs/pose3d/smpl_part_info.json",
front_path="assets/configs/pose3d/front_body.json",
facial_path="assets/configs/pose3d/front_facial.json",
head_path="assets/configs/pose3d/head.json"... |
Args:
map_name:
"uv" -> (F + 1) x 2 (bg as -1)
"uv_seg" -> (F + 1) x 3 (bs as -1)
"ids" -> (F + 1) x 1 (bg as -1)
"binary" -> (F + 1) x 14 (bs as -1)
"seg" -> (F + 1) x 1 (bs as 0)
"par" -> (F + 1) x (10 + 1)
... | create_mapping | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/mesh.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/mesh.py | Apache-2.0 |
def get_map_fn_dim(map_name):
"""
:param map_name:
"seg" -> (F + 1) x 1 (bs as -1 or 0)
"uv" -> (F + 1) x 2 (bg as -1)
"uv_seg" -> (F + 1) x 3 (bg as -1)
"ids" -> (F + 1) x 1 (bg as -1)
"binary" -> (F + 1) x 15 (bs as -1)
"par" -> (F + 1) x (10 + ... |
:param map_name:
"seg" -> (F + 1) x 1 (bs as -1 or 0)
"uv" -> (F + 1) x 2 (bg as -1)
"uv_seg" -> (F + 1) x 3 (bg as -1)
"ids" -> (F + 1) x 1 (bg as -1)
"binary" -> (F + 1) x 15 (bs as -1)
"par" -> (F + 1) x (10 + 1)
:return:
| get_map_fn_dim | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/mesh.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/mesh.py | Apache-2.0 |
def rotation_matrix_to_quaternion(rotation_matrix, eps=1e-6):
"""Convert 3x4 rotation matrix to 4d quaternion vector
This algorithm is based on algorithm described in
https://github.com/KieranWynn/pyquaternion/blob/master/pyquaternion/quaternion.py#L201
Args:
rotation_matrix (Tensor): the rota... | Convert 3x4 rotation matrix to 4d quaternion vector
This algorithm is based on algorithm described in
https://github.com/KieranWynn/pyquaternion/blob/master/pyquaternion/quaternion.py#L201
Args:
rotation_matrix (Tensor): the rotation matrix to convert.
Return:
Tensor: the rotation in ... | rotation_matrix_to_quaternion | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def quaternion_to_angle_axis(quaternion: torch.Tensor) -> torch.Tensor:
"""Convert quaternion vector to angle axis of rotation.
Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.h
Args:
quaternion (torch.Tensor): tensor with quaternions.
Return:
torch.Tensor: tensor ... | Convert quaternion vector to angle axis of rotation.
Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.h
Args:
quaternion (torch.Tensor): tensor with quaternions.
Return:
torch.Tensor: tensor with angle axis of rotation.
Shape:
- Input: :math:`(*, 4)` where ... | quaternion_to_angle_axis | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def angle_axis_to_quaternion(angle_axis: torch.Tensor) -> torch.Tensor:
"""Convert an angle axis to a quaternion.
Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.h
Args:
angle_axis (torch.Tensor): tensor with angle axis.
Return:
torch.Tensor: tensor with quaternion... | Convert an angle axis to a quaternion.
Adapted from ceres C++ library: ceres-solver/include/ceres/rotation.h
Args:
angle_axis (torch.Tensor): tensor with angle axis.
Return:
torch.Tensor: tensor with quaternion.
Shape:
- Input: :math:`(*, 3)` where `*` means, any number of di... | angle_axis_to_quaternion | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def rotation_matrix_to_angle_axis(rotation_matrix):
"""Convert 3x4 rotation matrix to Rodrigues vector
Args:
rotation_matrix (Tensor): rotation matrix.
Returns:
Tensor: Rodrigues vector transformation.
Shape:
- Input: :math:`(N, 3, 4)`
- Output: :math:`(N, 3)`
Exa... | Convert 3x4 rotation matrix to Rodrigues vector
Args:
rotation_matrix (Tensor): rotation matrix.
Returns:
Tensor: Rodrigues vector transformation.
Shape:
- Input: :math:`(N, 3, 4)`
- Output: :math:`(N, 3)`
Example:
>>> input = torch.rand(2, 3, 4) # Nx4x4
... | rotation_matrix_to_angle_axis | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def angle_axis_to_rotation_matrix(angle_axis):
"""Convert 3d vector of axis-angle rotation to 4x4 rotation matrix
Args:
angle_axis (Tensor): tensor of 3d vector of axis-angle rotations.
Returns:
Tensor: tensor of 4x4 rotation matrices.
Shape:
- Input: :math:`(N, 3)`
- ... | Convert 3d vector of axis-angle rotation to 4x4 rotation matrix
Args:
angle_axis (Tensor): tensor of 3d vector of axis-angle rotations.
Returns:
Tensor: tensor of 4x4 rotation matrices.
Shape:
- Input: :math:`(N, 3)`
- Output: :math:`(N, 4, 4)`
Example:
>>> in... | angle_axis_to_rotation_matrix | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def rotvec_to_rotmat(rot_vecs):
"""Convert axis-angle representation to rotation matrix.
Args:
rot_vecs: size = [B, 3]
Returns:
Rotation matrix corresponding to the quaternion -- size = [B, 3, 3]
"""
l1norm = torch.norm(rot_vecs + 1e-8, p=2, dim=1)
angle = torch.unsqueeze(l1norm,... | Convert axis-angle representation to rotation matrix.
Args:
rot_vecs: size = [B, 3]
Returns:
Rotation matrix corresponding to the quaternion -- size = [B, 3, 3]
| rotvec_to_rotmat | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def rotmat_to_rotvec(rotmat):
"""
Args:
rotmat (torch.Tensor): (n, 3, 3)
Returns:
rotvec (torch.Tensor): (n, 3)
"""
bs = rotmat.shape[0]
pad_hom = torch.tensor([0, 0, 1], dtype=torch.float32, device=rotmat.device).view(1, 3, 1).expand(bs, -1, -1)
pred_rotmat_hom = torch.c... |
Args:
rotmat (torch.Tensor): (n, 3, 3)
Returns:
rotvec (torch.Tensor): (n, 3)
| rotmat_to_rotvec | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def quat_to_rotmat(quat):
"""Convert quaternion coefficients to rotation matrix.
Args:
quat: size = [B, 4] 4 <===>(w, x, y, z)
Returns:
Rotation matrix corresponding to the quaternion -- size = [B, 3, 3]
"""
norm_quat = quat
norm_quat = norm_quat / norm_quat.norm(p=2, dim=1, keep... | Convert quaternion coefficients to rotation matrix.
Args:
quat: size = [B, 4] 4 <===>(w, x, y, z)
Returns:
Rotation matrix corresponding to the quaternion -- size = [B, 3, 3]
| quat_to_rotmat | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def rotmat_to_rot6d(rotmat):
"""Convert 6D rotation representation to 3x3 rotation matrix.
Based on Zhou et al., "On the Continuity of Rotation Representations in Neural Networks", CVPR 2019
Input:
(B,3,3) Batch of 6-D rotation representations
Output:
(B,6) Batch of corresponding rotatio... | Convert 6D rotation representation to 3x3 rotation matrix.
Based on Zhou et al., "On the Continuity of Rotation Representations in Neural Networks", CVPR 2019
Input:
(B,3,3) Batch of 6-D rotation representations
Output:
(B,6) Batch of corresponding rotation matrices
| rotmat_to_rot6d | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def rotvec_to_rot6d(rotvec):
"""
Args:
rotvec (torch.Tensor): (n, 3)
Returns:
rot6d (torch.Tensor): (n, 6)
"""
rotmat = rotvec_to_rotmat(rotvec)
rot6d = rotmat_to_rot6d(rotmat)
return rot6d |
Args:
rotvec (torch.Tensor): (n, 3)
Returns:
rot6d (torch.Tensor): (n, 6)
| rotvec_to_rot6d | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def rot6d_to_rotvec(rot6d):
"""
Args:
rot6d (torch.Tensor): (n, 6)
Returns:
rotvec (torch.Tensor): (n, 3)
"""
rotmat = rot6d_to_rotmat(rot6d)
rotvec = rotmat_to_rotvec(rotmat)
return rotvec |
Args:
rot6d (torch.Tensor): (n, 6)
Returns:
rotvec (torch.Tensor): (n, 3)
| rot6d_to_rotvec | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def rotvec_to_rot6d_np(rotvec):
"""
Args:
rotvec (np.ndarray): (n, 3)
Returns:
rot6d (np.ndarray): (n, 6)
"""
from scipy.spatial.transform.rotation import Rotation as R
rotmat = R.from_rotvec(rotvec).as_matrix()
rotmat = torch.from_numpy(rotmat)
rot6d = rotmat_to_rot6... |
Args:
rotvec (np.ndarray): (n, 3)
Returns:
rot6d (np.ndarray): (n, 6)
| rotvec_to_rot6d_np | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def perspective_projection(points, rotation, translation,
focal_length, camera_center):
"""
This function computes the perspective projection of a set of points.
Input:
points (bs, N, 3): 3D points
rotation (bs, 3, 3): Camera rotation
translation (bs, 3): C... |
This function computes the perspective projection of a set of points.
Input:
points (bs, N, 3): 3D points
rotation (bs, 3, 3): Camera rotation
translation (bs, 3): Camera translation
focal_length (bs,) or scalar: Focal length
camera_center (bs, 2): Camera center
| perspective_projection | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def estimate_translation_np(S, joints_2d, joints_conf, focal_length=5000, img_size=224):
"""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,) ... | 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
| estimate_translation_np | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def estimate_translation(S, joints_2d, focal_length=5000., img_size=224.):
"""Find camera translation that brings 3D joints S closest to 2D the corresponding joints_2d.
Input:
S: (B, 49, 3) 3D joint locations
joints: (B, 49, 3) 2D joint locations and confidence
Returns:
(B, 3) camera... | Find camera translation that brings 3D joints S closest to 2D the corresponding joints_2d.
Input:
S: (B, 49, 3) 3D joint locations
joints: (B, 49, 3) 2D joint locations and confidence
Returns:
(B, 3) camera translation vectors
| estimate_translation | python | iPERDance/iPERCore | iPERCore/tools/utils/geometry/rotations.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/geometry/rotations.py | Apache-2.0 |
def morph(src_bg_mask, ks, mode="erode", kernel=None):
"""
Args:
src_bg_mask (torch.tensor):
ks (int):
mode (str):
kernel (torch.tensor or None):
Returns:
out (torch.tensor):
"""
n_ks = ks ** 2
pad_s = ks // 2
if kernel is None:
kernel = to... |
Args:
src_bg_mask (torch.tensor):
ks (int):
mode (str):
kernel (torch.tensor or None):
Returns:
out (torch.tensor):
| morph | python | iPERDance/iPERCore | iPERCore/tools/utils/morphology/morph_ops.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/morphology/morph_ops.py | Apache-2.0 |
def soft_dilate(src_bg_mask, ks, kernel=None):
"""
Args:
src_bg_mask (torch.tensor):
ks (int):
kernel (torch.tensor or None):
Returns:
out (torch.tensor):
"""
n_ks = ks ** 2
pad_s = ks // 2
if kernel is None:
kernel = torch.ones(1, 1, ks, ks, dtype... |
Args:
src_bg_mask (torch.tensor):
ks (int):
kernel (torch.tensor or None):
Returns:
out (torch.tensor):
| soft_dilate | python | iPERDance/iPERCore | iPERCore/tools/utils/morphology/morph_ops.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/morphology/morph_ops.py | Apache-2.0 |
def make_video(output_mp4_path, img_path_list, save_frames_dir=None, fps=24, pool_size=40):
"""
output_path is the final mp4 name
img_dir is where the images to make into video are saved.
"""
global default_ffmpeg_vcodec, default_ffmpeg_pix_fmt, default_ffmpeg_exe_path
ffmpeg_exc_path = os.env... |
output_path is the final mp4 name
img_dir is where the images to make into video are saved.
| make_video | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def load_image(image_path, image_size=512):
"""
Args:
image_path (str):
image_size (int):
Returns:
image (np.ndarray): (image_size, image_size, 3), BGR channel space, in the range of [0, 255], np.uint8.
"""
if image_path:
image = cv2.imread(image_path)
imag... |
Args:
image_path (str):
image_size (int):
Returns:
image (np.ndarray): (image_size, image_size, 3), BGR channel space, in the range of [0, 255], np.uint8.
| load_image | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def fuse_two_images(img_paths, image_size):
"""
Args:
img_paths (list of str):
image_size (int):
Returns:
fuse_img (np.ndarray): (image_size // 2, image_size, 3), BGR channel space, in the range of [0, 255], np.uint8.
"""
img_size = image_size // 2
img_1 = load_image(... |
Args:
img_paths (list of str):
image_size (int):
Returns:
fuse_img (np.ndarray): (image_size // 2, image_size, 3), BGR channel space, in the range of [0, 255], np.uint8.
| fuse_two_images | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def fuse_four_images(img_paths, image_size):
"""
Args:
img_paths (list of str):
image_size (int):
Returns:
fuse_img (np.ndarray): (image_size, image_size, 3), BGR channel space, in the range of [0, 255], np.uint8.
"""
fuse_img_1 = fuse_two_images(img_paths[0:2], image_size... |
Args:
img_paths (list of str):
image_size (int):
Returns:
fuse_img (np.ndarray): (image_size, image_size, 3), BGR channel space, in the range of [0, 255], np.uint8.
| fuse_four_images | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def fuse_eight_images(img_paths, image_size):
"""
Args:
img_paths (List[Union[str, None]]):
image_size (int):
Returns:
fuse_img (np.ndarray): (image_size // 2, image_size, 3), BGR channel space, in the range of [0, 255], np.uint8.
"""
fuse_img_1 = fuse_two_images(img_paths... |
Args:
img_paths (List[Union[str, None]]):
image_size (int):
Returns:
fuse_img (np.ndarray): (image_size // 2, image_size, 3), BGR channel space, in the range of [0, 255], np.uint8.
| fuse_eight_images | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def fuse_source(all_src_img_paths, image_size=512):
"""
Args:
all_src_img_paths (list of str): the list of source image paths. Denotes ns as the number of source images,
if ns == 1, we will display one single image;
if ns == 2, we will display two images;
if ns == 3,... |
Args:
all_src_img_paths (list of str): the list of source image paths. Denotes ns as the number of source images,
if ns == 1, we will display one single image;
if ns == 2, we will display two images;
if ns == 3, we will pad them to four images and display them;
... | fuse_source | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def video2frames(vid_path, out_dir):
"""
Extracts all frames from the video at vid_path and saves them inside of
out_dir.
"""
global default_ffmpeg_vcodec, default_ffmpeg_pix_fmt, default_ffmpeg_exe_path
ffmpeg_exc_path = os.environ.get("ffmpeg_exe_path", default_ffmpeg_exe_path)
imgs = g... |
Extracts all frames from the video at vid_path and saves them inside of
out_dir.
| video2frames | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def extract_audio_from_video(video_path, save_audio_path):
"""
Extract the audio from a video.
Args:
video_path (str): the input video path;
save_audio_path (str): the saved audio path.
Returns:
"""
global default_ffmpeg_exe_path
ffmpeg_exe_path = os.environ.get("ffmpeg... |
Extract the audio from a video.
Args:
video_path (str): the input video path;
save_audio_path (str): the saved audio path.
Returns:
| extract_audio_from_video | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def get_video_fps(video_path, ret_type="float"):
"""
Get the fps of the video.
Args:
video_path (str): the video path;
ret_type (str): the return type, it supports `str`, `float`, and `tuple` (numerator, denominator).
Returns:
--fps (str): if ret_type is `str`.
--fps (f... |
Get the fps of the video.
Args:
video_path (str): the video path;
ret_type (str): the return type, it supports `str`, `float`, and `tuple` (numerator, denominator).
Returns:
--fps (str): if ret_type is `str`.
--fps (float): if ret_type is `float`.
--fps (tuple): if... | get_video_fps | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def check_video_has_audio(video_path):
"""
Check the video has audio or not.
Args:
video_path (str): the video path.
Returns:
has_audio (bool): True, if it has audio; otherwise it returns False.
"""
global default_ffprobe_exe_path
ffprobe_exe_path = os.environ.get("ffprob... |
Check the video has audio or not.
Args:
video_path (str): the video path.
Returns:
has_audio (bool): True, if it has audio; otherwise it returns False.
| check_video_has_audio | python | iPERDance/iPERCore | iPERCore/tools/utils/multimedia/video.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/multimedia/video.py | Apache-2.0 |
def fist_order_low_pass_filter(signal, alpha=0.7):
"""
Y(n) = alpha * Y(n-1) + (1 - alpha) * X(n).
Args:
signal (np.ndarray or torch.Tensor): (n, c);
alpha (float): Y(n) = alpha * Y(n-1) + (1 - alpha) * X(n)
Returns:
sm_signal (np.ndarray or torch.Tensor): (n, c)
"""
... |
Y(n) = alpha * Y(n-1) + (1 - alpha) * X(n).
Args:
signal (np.ndarray or torch.Tensor): (n, c);
alpha (float): Y(n) = alpha * Y(n-1) + (1 - alpha) * X(n)
Returns:
sm_signal (np.ndarray or torch.Tensor): (n, c)
| fist_order_low_pass_filter | python | iPERDance/iPERCore | iPERCore/tools/utils/signals/smooth.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/signals/smooth.py | Apache-2.0 |
def get_smooth_params(sig, n=5, fc=300):
"""
Low-pass filters.
Args:
sig (np.ndarray): (length, feature dimension);
n (int): the number of low-pass order;
fc (float): the factor to control the degree of smoothness. The smaller of fc, the more smoother.
Returns:
smooth_s... |
Low-pass filters.
Args:
sig (np.ndarray): (length, feature dimension);
n (int): the number of low-pass order;
fc (float): the factor to control the degree of smoothness. The smaller of fc, the more smoother.
Returns:
smooth_sig (np.ndarray): (length, feature dimension).
... | get_smooth_params | python | iPERDance/iPERCore | iPERCore/tools/utils/signals/smooth.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/signals/smooth.py | Apache-2.0 |
def pose2d_distance(kps1, kps2):
"""
Args:
kps1 (np.ndarray): (length, num_joints_1, 2)
kps2 (np.ndarray): (length, num_joints_2, 2)
Returns:
"""
n, num_joints = kps1.shape[0:2]
assert n == kps2.shape[0]
# (length, num_joints_1, 2) -> (length, num_joints_1, 1, 2) -> (len... |
Args:
kps1 (np.ndarray): (length, num_joints_1, 2)
kps2 (np.ndarray): (length, num_joints_2, 2)
Returns:
| pose2d_distance | python | iPERDance/iPERCore | iPERCore/tools/utils/signals/smooth.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/signals/smooth.py | Apache-2.0 |
def pose2d_temporal_filter(keypoints, window_size, mode, **kwargs):
"""
Temporal filter the keypoints. It mainly focuses on fixing the case that the coordinates of the keypoints are
estimated successfully, while the it fails on the right-left orders. Here, we try to deal with it by following
strategies:... |
Temporal filter the keypoints. It mainly focuses on fixing the case that the coordinates of the keypoints are
estimated successfully, while the it fails on the right-left orders. Here, we try to deal with it by following
strategies:
1. temporal smooth the keypoints, get the filtered_kps, and the sm... | pose2d_temporal_filter | python | iPERDance/iPERCore | iPERCore/tools/utils/signals/smooth.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/signals/smooth.py | Apache-2.0 |
def temporal_smooth_smpls(ref_smpls, pose_fc=300, cam_fc=100):
"""
Args:
ref_smpls (np.ndarray): (length, 72)
pose_fc:
cam_fc:
Returns:
ref_smpls (np.ndarray): (length, 72)
"""
ref_rotvec = ref_smpls[:, 3:-10]
n = ref_rotvec.shape[0]
ref_rotvec = ref_rotvec... |
Args:
ref_smpls (np.ndarray): (length, 72)
pose_fc:
cam_fc:
Returns:
ref_smpls (np.ndarray): (length, 72)
| temporal_smooth_smpls | python | iPERDance/iPERCore | iPERCore/tools/utils/signals/smooth.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/signals/smooth.py | Apache-2.0 |
def pose_temporal_smooth(init_pose_rotvec, opt_pose_rotvec, threshold: float = 10):
"""
Args:
init_pose_rotvec (torch.Tensor): (n, 72);
opt_pose_rotvec (torch.Tensor): (n, 72);
threshold (float):
Returns:
opt_pose_rotvec (torch.Tensor): (n, 72).
"""
n = opt_pose_ro... |
Args:
init_pose_rotvec (torch.Tensor): (n, 72);
opt_pose_rotvec (torch.Tensor): (n, 72);
threshold (float):
Returns:
opt_pose_rotvec (torch.Tensor): (n, 72).
| pose_temporal_smooth | python | iPERDance/iPERCore | iPERCore/tools/utils/signals/smooth.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/signals/smooth.py | Apache-2.0 |
def vis_keypoints(self, preds, gts):
"""
Args:
preds (torch.Tensor): (self.time_step, num_points, 2), the time series of predicted keypoints.
gts (torch.Tensor): (self.time_step, num_points, 2), the time series of ground truth keypoints.
Returns:
None
... |
Args:
preds (torch.Tensor): (self.time_step, num_points, 2), the time series of predicted keypoints.
gts (torch.Tensor): (self.time_step, num_points, 2), the time series of ground truth keypoints.
Returns:
None
| vis_keypoints | python | iPERDance/iPERCore | iPERCore/tools/utils/visualizers/visdom_visualizer.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/visualizers/visdom_visualizer.py | Apache-2.0 |
def draw_skeleton(self, key_points, win_name, plus=False):
"""
Args:
key_points (np.ndarray or torch.Tensor): (14 or 19, 2)
win_name (str):
plus (bool):
Returns:
None
"""
lsp_key_points_name = ['Right ankle', 'Right knee', 'Right... |
Args:
key_points (np.ndarray or torch.Tensor): (14 or 19, 2)
win_name (str):
plus (bool):
Returns:
None
| draw_skeleton | python | iPERDance/iPERCore | iPERCore/tools/utils/visualizers/visdom_visualizer.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/visualizers/visdom_visualizer.py | Apache-2.0 |
def vis_named_img(self, name, imgs, denormalize=True, transpose=False):
"""
Args:
name (str): window name
imgs (np.ndarray or torch.Tensor): (bs, 3, height, width) or (bs, height, width, 3)
denormalize (bool): if it is true, then denormalize the imgs from [-1, 1] to ... |
Args:
name (str): window name
imgs (np.ndarray or torch.Tensor): (bs, 3, height, width) or (bs, height, width, 3)
denormalize (bool): if it is true, then denormalize the imgs from [-1, 1] to [0, 1]
transpose (bool): if it is true, then transpose the images to (b... | vis_named_img | python | iPERDance/iPERCore | iPERCore/tools/utils/visualizers/visdom_visualizer.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/visualizers/visdom_visualizer.py | Apache-2.0 |
def vis_preds_gts(self, preds=None, gts=None):
"""
:type preds: np.ndarray, (self.time_step, 1, self.image_size, self.image_size) or
(self.time_step, self.image_size, self.image_size)
:param preds: the time series of predicted silhouettes,
if preds.n... |
:type preds: np.ndarray, (self.time_step, 1, self.image_size, self.image_size) or
(self.time_step, self.image_size, self.image_size)
:param preds: the time series of predicted silhouettes,
if preds.ndim == 3, (self.time_step, self.image_size, self.image_siz... | vis_preds_gts | python | iPERDance/iPERCore | iPERCore/tools/utils/visualizers/visdom_visualizer.py | https://github.com/iPERDance/iPERCore/blob/master/iPERCore/tools/utils/visualizers/visdom_visualizer.py | Apache-2.0 |
def download_from_url(url, dst):
"""
Args:
url (str): url to download file
dst (str): dst place to put the file
Returns:
"""
file_size = int(urlopen(url).info().get("Content-Length", -1))
if os.path.exists(dst):
first_byte = os.path.getsize(dst)
else:
fi... |
Args:
url (str): url to download file
dst (str): dst place to put the file
Returns:
| download_from_url | python | iPERDance/iPERCore | scripts/train/download_utils.py | https://github.com/iPERDance/iPERCore/blob/master/scripts/train/download_utils.py | Apache-2.0 |
def crawl_videos(url_txt_file):
"""
Args:
url_txt_file (str): the txt file contains all video urls.
Returns:
"""
global FashionVideo_video_dir
video_urls = []
with open(url_txt_file, "r") as reader:
# TODO, convert this to multi-thread or multi-process?
for vid_u... |
Args:
url_txt_file (str): the txt file contains all video urls.
Returns:
| crawl_videos | python | iPERDance/iPERCore | scripts/train/prepare_FashionVideo_dataset.py | https://github.com/iPERDance/iPERCore/blob/master/scripts/train/prepare_FashionVideo_dataset.py | Apache-2.0 |
def render_mask(smpl, render, cams, poses, shapes, offsets,
img_dir, image_names, parse_out_dir, visual_path):
"""
Args:
smpl (SMPL):
render (SMPLRenderer):
cams:
poses:
shapes:
offsets:
img_dir:
image_names:
parse_out_dir:... |
Args:
smpl (SMPL):
render (SMPLRenderer):
cams:
poses:
shapes:
offsets:
img_dir:
image_names:
parse_out_dir:
visual_path:
Returns:
| render_mask | python | iPERDance/iPERCore | scripts/train/prepare_motionSynthetic_dataset.py | https://github.com/iPERDance/iPERCore/blob/master/scripts/train/prepare_motionSynthetic_dataset.py | Apache-2.0 |
def per_instance_func(smpl, render, process_info):
"""
Args:
smpl (SMPL):
render (SMPLRenderer):
process_info (ProcessInfo):
Returns:
"""
global MotionSynthetic_video_dir, MotionSynthetic_poses_dir
# 1. dump video into frames and write indexes information into proces... |
Args:
smpl (SMPL):
render (SMPLRenderer):
process_info (ProcessInfo):
Returns:
| per_instance_func | python | iPERDance/iPERCore | scripts/train/prepare_motionSynthetic_dataset.py | https://github.com/iPERDance/iPERCore/blob/master/scripts/train/prepare_motionSynthetic_dataset.py | Apache-2.0 |
def cloth_link_animate_visual(links_ids, cams, pose, shape, ref_smpl_path):
"""
Args:
links_ids:
cams:
pose:
shape:
ref_smpl_path (str):
Returns:
"""
global smpl, visualizer, render, device, texs
cams = torch.tensor(cams).float().to(device)
pose = ... |
Args:
links_ids:
cams:
pose:
shape:
ref_smpl_path (str):
Returns:
| cloth_link_animate_visual | python | iPERDance/iPERCore | tests/test_human_digitalizer/test_deformers.py | https://github.com/iPERDance/iPERCore/blob/master/tests/test_human_digitalizer/test_deformers.py | Apache-2.0 |
def test_02_parse_ref_only_path(self):
"""
test the ref_input with only path case.
Returns:
"""
ref_input = "/path1|/path2"
ref_meta_gt = [
meta_info.RefMetaInputInfo(path="/path1", name="path1"),
meta_info.RefMetaInputInfo(path="/path2", name=... |
test the ref_input with only path case.
Returns:
| test_02_parse_ref_only_path | python | iPERDance/iPERCore | tests/test_services/test_metainfo.py | https://github.com/iPERDance/iPERCore/blob/master/tests/test_services/test_metainfo.py | Apache-2.0 |
def build(force):
""" Builds the distribution files: wheels and source. """
dist_path = Path(DIST_PATH)
if dist_path.exists() and list(dist_path.glob('*')):
if force or click.confirm('{} is not empty - delete contents?'.format(dist_path)):
dist_path.rename(DIST_PATH_DELETE)
s... | Builds the distribution files: wheels and source. | build | python | O365/python-o365 | release.py | https://github.com/O365/python-o365/blob/master/release.py | Apache-2.0 |
def upload(ctx, release, rebuild):
""" Uploads distribuition files to pypi or pypitest. """
dist_path = Path(DIST_PATH)
if rebuild is False:
if not dist_path.exists() or not list(dist_path.glob('*')):
print("No distribution files found. Please run 'build' command first")
retu... | Uploads distribuition files to pypi or pypitest. | upload | python | O365/python-o365 | release.py | https://github.com/O365/python-o365/blob/master/release.py | Apache-2.0 |
def test(annotate, coverage, v, vv):
""" Runs tests and optionally creates annotated files of coverage. """
args = ['python3', '-m', 'pytest', 'tests/']
if coverage:
args.append('--cov=O365')
if annotate:
args.append('--cov-report')
args.append('annotate')
if ... | Runs tests and optionally creates annotated files of coverage. | test | python | O365/python-o365 | release.py | https://github.com/O365/python-o365/blob/master/release.py | Apache-2.0 |
def list_releases():
""" Lists all releases published on pypi. """
releases = _get_releases()
if releases is None:
print('Package "{}" not found on Pypi.org'.format(PYPI_PACKAGE_NAME))
elif not releases:
print('No releases found for {}'.format(PYPI_PACKAGE_NAME))
else:
for ... | Lists all releases published on pypi. | list_releases | python | O365/python-o365 | release.py | https://github.com/O365/python-o365/blob/master/release.py | Apache-2.0 |
def contribution_breakdown():
""" Displays a table of the contributors and to what extent we have them to thank."""
args = ['git', 'blame']
counts = {}
line_format = '{0:30}\t{1:>10}\t{2:>10}%'
files = subprocess.check_output(['git', 'ls-files']).decode("utf-8").split('\n')
for f in files[:-1]:... | Displays a table of the contributors and to what extent we have them to thank. | contribution_breakdown | python | O365/python-o365 | release.py | https://github.com/O365/python-o365/blob/master/release.py | Apache-2.0 |
def create_jwt_assertion(private_key, tenant_id, thumbprint, client_id):
"""
Create a JWT assertion, used to obtain an auth token.
@param private_key: Private key in PEM format from the certificate that was registered as credentials for the
application.
@param tenant_id: The directory tenant the ... |
Create a JWT assertion, used to obtain an auth token.
@param private_key: Private key in PEM format from the certificate that was registered as credentials for the
application.
@param tenant_id: The directory tenant the application plans to operate against, in GUID or domain-name format.
@param ... | create_jwt_assertion | python | O365/python-o365 | examples/jwt_assertion.py | https://github.com/O365/python-o365/blob/master/examples/jwt_assertion.py | Apache-2.0 |
def decode_jwt_assertion(jwt_assertion, public_key, tenant_id):
"""
Decode a JWT assertion, the opposite to 'create_jwt_assertion'.
@param jwt_assertion: The JWT assertion obtained to be decoded.
@param public_key: Public key in PEM format from the certificate that was registered as credentials for the... |
Decode a JWT assertion, the opposite to 'create_jwt_assertion'.
@param jwt_assertion: The JWT assertion obtained to be decoded.
@param public_key: Public key in PEM format from the certificate that was registered as credentials for the
application.
@param tenant_id: The directory tenant the appli... | decode_jwt_assertion | python | O365/python-o365 | examples/jwt_assertion.py | https://github.com/O365/python-o365/blob/master/examples/jwt_assertion.py | Apache-2.0 |
def _check_refresh_flag(self) -> bool:
""" Returns the token if the flag is True or None otherwise"""
try:
doc = self.doc_ref.get()
except Exception as e:
log.error(f"Flag (collection: {self.collection}, doc_id: {self.doc_id}) "
f"could not be retrie... | Returns the token if the flag is True or None otherwise | _check_refresh_flag | python | O365/python-o365 | examples/token_backends.py | https://github.com/O365/python-o365/blob/master/examples/token_backends.py | Apache-2.0 |
def save_token(self, force=False):
"""We must overwrite this method to update also the 'refresh_flag_field_name' to True"""
if not self._cache:
return False
if force is False and self._has_state_changed is False:
return True
try:
# set token will ove... | We must overwrite this method to update also the 'refresh_flag_field_name' to True | save_token | python | O365/python-o365 | examples/token_backends.py | https://github.com/O365/python-o365/blob/master/examples/token_backends.py | Apache-2.0 |
def should_refresh_token(self, con: Optional[Connection] = None, username: Optional[str] = None):
"""
Method for refreshing the token when there are concurrently running
O365 instances. Determines if we need to call the MS server and refresh
the token and its file, or if another Connect... |
Method for refreshing the token when there are concurrently running
O365 instances. Determines if we need to call the MS server and refresh
the token and its file, or if another Connection instance has already
updated it, and we should just load that updated token from the file.
... | should_refresh_token | python | O365/python-o365 | examples/token_backends.py | https://github.com/O365/python-o365/blob/master/examples/token_backends.py | Apache-2.0 |
def __init__(self, credentials: Tuple[str, str], *,
username: Optional[str] = None,
protocol: Optional[Protocol] = None,
main_resource: Optional[str] = None, **kwargs):
""" Creates an object which is used to access resources related to the specified credentials... | Creates an object which is used to access resources related to the specified credentials.
:param credentials: a tuple containing the client_id and client_secret
:param username: the username to be used by this account
:param protocol: the protocol to be used in this account
:param main... | __init__ | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def is_authenticated(self) -> bool:
"""
Checks whether the library has the authentication data and that is not expired for the current username.
This will try to load the token from the backend if not already loaded.
Return True if authenticated, False otherwise.
"""
if s... |
Checks whether the library has the authentication data and that is not expired for the current username.
This will try to load the token from the backend if not already loaded.
Return True if authenticated, False otherwise.
| is_authenticated | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def authenticate(self, *, requested_scopes: Optional[list] = None, redirect_uri: Optional[str] = None,
handle_consent: Callable = consent_input_token, **kwargs) -> bool:
""" Performs the console authentication flow resulting in a stored token.
It uses the credentials passed on insta... | Performs the console authentication flow resulting in a stored token.
It uses the credentials passed on instantiation.
Returns True if succeeded otherwise False.
:param list[str] requested_scopes: list of protocol user scopes to be converted
by the protocol or scope helpers or raw sco... | authenticate | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def get_authorization_url(self,
requested_scopes: List[str],
redirect_uri: Optional[str] = None,
**kwargs) -> Tuple[str, dict]:
""" Initializes the oauth authorization flow, getting the
authorization url that the u... | Initializes the oauth authorization flow, getting the
authorization url that the user must approve.
:param list[str] requested_scopes: list of scopes to request access for
:param str redirect_uri: redirect url configured in registered app
:param kwargs: allow to pass unused params in c... | get_authorization_url | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def request_token(self, authorization_url: Optional[str], *,
flow: dict = None,
requested_scopes: Optional[List[str]] = None,
store_token: bool = True,
**kwargs) -> bool:
""" Authenticates for the specified url and gets the ... | Authenticates for the specified url and gets the oauth token data. Saves the
token in the backend if store_token is True. This will replace any other tokens stored
for the same username and scopes requested.
If the token data is successfully requested, then this method will try to set the usern... | request_token | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def get_authenticated_usernames(self) -> list[str]:
""" Returns a list of usernames that are authenticated and have a valid access token or a refresh token."""
usernames = []
tb = self.con.token_backend
for account in self.con.token_backend.get_all_accounts():
username = acco... | Returns a list of usernames that are authenticated and have a valid access token or a refresh token. | get_authenticated_usernames | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def get_current_user_data(self):
""" Returns the current user data from the active directory """
if self.con.auth_flow_type in ('authorization', 'public'):
directory = self.directory(resource=ME_RESOURCE)
return directory.get_current_user()
else:
return None | Returns the current user data from the active directory | get_current_user_data | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def new_message(self, resource: Optional[str] = None):
""" Creates a new message to be sent or stored
:param str resource: Custom resource to be used in this message
(Defaults to parent main_resource)
:return: New empty message
:rtype: Message
"""
from .message ... | Creates a new message to be sent or stored
:param str resource: Custom resource to be used in this message
(Defaults to parent main_resource)
:return: New empty message
:rtype: Message
| new_message | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def mailbox(self, resource: Optional[str] = None):
""" Get an instance to the mailbox for the specified account resource
:param resource: Custom resource to be used in this mailbox
(Defaults to parent main_resource)
:return: a representation of account mailbox
:rtype: O365.mail... | Get an instance to the mailbox for the specified account resource
:param resource: Custom resource to be used in this mailbox
(Defaults to parent main_resource)
:return: a representation of account mailbox
:rtype: O365.mailbox.MailBox
| mailbox | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def address_book(self, *, resource: Optional[str] = None, address_book: str = 'personal'):
""" Get an instance to the specified address book for the
specified account resource
:param resource: Custom resource to be used in this address book
(Defaults to parent main_resource)
:p... | Get an instance to the specified address book for the
specified account resource
:param resource: Custom resource to be used in this address book
(Defaults to parent main_resource)
:param address_book: Choose from 'Personal' or 'Directory'
:return: a representation of the spec... | address_book | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def schedule(self, *, resource: Optional[str] = None):
""" Get an instance to work with calendar events for the
specified account resource
:param resource: Custom resource to be used in this schedule object
(Defaults to parent main_resource)
:return: a representation of calenda... | Get an instance to work with calendar events for the
specified account resource
:param resource: Custom resource to be used in this schedule object
(Defaults to parent main_resource)
:return: a representation of calendar events
:rtype: Schedule
| schedule | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def storage(self, *, resource: Optional[str] = None):
""" Get an instance to handle file storage (OneDrive / Sharepoint)
for the specified account resource
:param resource: Custom resource to be used in this drive object
(Defaults to parent main_resource)
:return: a representat... | Get an instance to handle file storage (OneDrive / Sharepoint)
for the specified account resource
:param resource: Custom resource to be used in this drive object
(Defaults to parent main_resource)
:return: a representation of OneDrive File Storage
:rtype: Storage
:rai... | storage | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def sharepoint(self, *, resource: str = ''):
""" Get an instance to read information from Sharepoint sites for the
specified account resource
:param resource: Custom resource to be used in this sharepoint
object (Defaults to parent main_resource)
:return: a representation of Sh... | Get an instance to read information from Sharepoint sites for the
specified account resource
:param resource: Custom resource to be used in this sharepoint
object (Defaults to parent main_resource)
:return: a representation of Sharepoint Sites
:rtype: Sharepoint
:raise... | sharepoint | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def planner(self, *, resource: str = ''):
""" Get an instance to read information from Microsoft planner """
if not isinstance(self.protocol, MSGraphProtocol):
# TODO: Custom protocol accessing OneDrive/Sharepoint Api fails here
raise RuntimeError(
'planner api o... | Get an instance to read information from Microsoft planner | planner | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def tasks(self, *, resource: str = ''):
""" Get an instance to read information from Microsoft ToDo """
from .tasks import ToDo
return ToDo(parent=self, main_resource=resource) | Get an instance to read information from Microsoft ToDo | tasks | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def teams(self, *, resource: str = ''):
""" Get an instance to read information from Microsoft Teams """
if not isinstance(self.protocol, MSGraphProtocol):
raise RuntimeError(
'teams api only works on Microsoft Graph API')
from .teams import Teams
return Tea... | Get an instance to read information from Microsoft Teams | teams | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def outlook_categories(self, *, resource: str = ''):
""" Returns a Categories object to handle the available Outlook Categories """
from .category import Categories
return Categories(parent=self, main_resource=resource) | Returns a Categories object to handle the available Outlook Categories | outlook_categories | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def groups(self, *, resource: str = ''):
""" Get an instance to read information from Microsoft Groups """
if not isinstance(self.protocol, MSGraphProtocol):
raise RuntimeError(
'groups api only works on Microsoft Graph API')
from .groups import Groups
retur... | Get an instance to read information from Microsoft Groups | groups | python | O365/python-o365 | O365/account.py | https://github.com/O365/python-o365/blob/master/O365/account.py | Apache-2.0 |
def __init__(self, *, parent=None, con=None, **kwargs):
""" Create a contact API component
:param parent: parent account for this folder
:type parent: Account
:param Connection con: connection to use if no parent specified
:param Protocol protocol: protocol to use if no parent s... | Create a contact API component
:param parent: parent account for this folder
:type parent: Account
:param Connection con: connection to use if no parent specified
:param Protocol protocol: protocol to use if no parent specified
(kwargs)
:param str main_resource: use th... | __init__ | python | O365/python-o365 | O365/address_book.py | https://github.com/O365/python-o365/blob/master/O365/address_book.py | Apache-2.0 |
def main_email(self):
""" Primary(First) email id of the Contact
:rtype: str
"""
if not self.emails:
return None
return self.emails[0].address | Primary(First) email id of the Contact
:rtype: str
| main_email | python | O365/python-o365 | O365/address_book.py | https://github.com/O365/python-o365/blob/master/O365/address_book.py | Apache-2.0 |
def to_api_data(self, restrict_keys=None):
""" Returns a dictionary in cloud format
:param restrict_keys: a set of keys to restrict the returned data to.
"""
cc = self._cc # alias
data = {
cc('displayName'): self.__display_name,
cc('fileAs'): self.__fil... | Returns a dictionary in cloud format
:param restrict_keys: a set of keys to restrict the returned data to.
| to_api_data | python | O365/python-o365 | O365/address_book.py | https://github.com/O365/python-o365/blob/master/O365/address_book.py | Apache-2.0 |
def delete(self):
""" Deletes this contact
:return: Success or Failure
:rtype: bool
:raises RuntimeError: if contact is not yet saved to cloud
"""
if not self.object_id:
raise RuntimeError('Attempting to delete an unsaved Contact')
url = self.build_u... | Deletes this contact
:return: Success or Failure
:rtype: bool
:raises RuntimeError: if contact is not yet saved to cloud
| delete | python | O365/python-o365 | O365/address_book.py | https://github.com/O365/python-o365/blob/master/O365/address_book.py | Apache-2.0 |
def save(self):
""" Saves this contact to the cloud (create or update existing one
based on what values have changed)
:return: Saved or Not
:rtype: bool
"""
if self.object_id:
# Update Contact
if not self._track_changes:
return Tru... | Saves this contact to the cloud (create or update existing one
based on what values have changed)
:return: Saved or Not
:rtype: bool
| save | python | O365/python-o365 | O365/address_book.py | https://github.com/O365/python-o365/blob/master/O365/address_book.py | Apache-2.0 |
def new_message(self, recipient=None, *, recipient_type=RecipientType.TO):
""" This method returns a new draft Message instance with
contacts first email as a recipient
:param Recipient recipient: a Recipient instance where to send this
message. If None first email of this contact will... | This method returns a new draft Message instance with
contacts first email as a recipient
:param Recipient recipient: a Recipient instance where to send this
message. If None first email of this contact will be used
:param RecipientType recipient_type: section to add recipient into
... | new_message | python | O365/python-o365 | O365/address_book.py | https://github.com/O365/python-o365/blob/master/O365/address_book.py | Apache-2.0 |
def get_profile_photo(self, size=None):
"""Returns this contact profile photo
:param str size: 48x48, 64x64, 96x96, 120x120, 240x240,
360x360, 432x432, 504x504, and 648x648
"""
if size is None:
url = self.build_url(self._endpoints.get('photo').format(id=self.object_... | Returns this contact profile photo
:param str size: 48x48, 64x64, 96x96, 120x120, 240x240,
360x360, 432x432, 504x504, and 648x648
| get_profile_photo | python | O365/python-o365 | O365/address_book.py | https://github.com/O365/python-o365/blob/master/O365/address_book.py | Apache-2.0 |
def update_profile_photo(self, photo):
""" Updates this contact profile photo
:param bytes photo: the photo data in bytes
"""
url = self.build_url(self._endpoints.get('photo').format(id=self.object_id))
response = self.con.patch(url, data=photo, headers={'Content-type': 'image/j... | Updates this contact profile photo
:param bytes photo: the photo data in bytes
| update_profile_photo | python | O365/python-o365 | O365/address_book.py | https://github.com/O365/python-o365/blob/master/O365/address_book.py | Apache-2.0 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.