def pose_rotation(meta):
deg = random.uniform(-40.0, 40.0)
img = meta.img
center = (img.shape[1] * 0.5, img.shape[0] * 0.5)
rot_m = cv2.getRotationMatrix2D((center[0] - 0.5, center[1] - 0.5), deg, 1)
ret = cv2.warpAffine(img, rot_m, img.shape[1::-1], flags=cv2.INTER_AREA, borderMode=cv2.BORDER_CONSTANT)
if img.ndim == 3 and ret.ndim == 2:
ret = ret[:, :, np.newaxis]
neww, newh = RotationAndCropValid.largest_rotated_rect(ret.shape[1], ret.shape[0], deg)
neww = min(neww, ret.shape[1])
newh = min(newh, ret.shape[0])
newx = int(center[0] - neww * 0.5)
newy = int(center[1] - newh * 0.5)
# print(ret.shape, deg, newx, newy, neww, newh)
img = ret[newy:newy + newh, newx:newx + neww]
# adjust meta data
adjust_joint_list = []
for joint in meta.joint_list:
adjust_joint = []
for point in joint:
if point[0] < -100 or point[1] < -100:
adjust_joint.append((-1000, -1000))
continue
# if point[0] <= 0 or point[1] <= 0:
# adjust_joint.append((-1, -1))
# continue
x, y = _rotate_coord((meta.width, meta.height), (newx, newy), point, deg)
adjust_joint.append((x, y))
adjust_joint_list.append(adjust_joint)
meta.joint_list = adjust_joint_list
meta.width, meta.height = neww, newh
meta.img = img
return meta
评论列表
文章目录