[UE4]角度和弧度

  1. 1角度 = 一个圆周的1/360
  2. 1弧度 = 长度为半径的弧,其所对的圆心角

转载于:https://www.cnblogs.com/timy/p/9217475.html

Mediapipe中的骨骼旋转角度是以弧度为单位的,而UE5中的骨骼旋转角度是以欧拉角(Yaw, Pitch, Roll)为单位的。因此,需要将弧度转换为欧拉角。 以下是将Mediapipe中的骨骼旋转角度转换为UE5中的骨骼旋转角度的示例代码: ```python import math # 定义一个角度弧度的函数 def deg2rad(degrees): return degrees * math.pi / 180 # 定义一个弧度角度的函数 def rad2deg(radians): return radians * 180 / math.pi # 定义一个将Mediapipe骨骼旋转角度转换为UE5骨骼旋转角度的函数 def mediapipe_rotation_to_ue_rotation(rotation): # 将弧度转换为欧拉角 pitch = rad2deg(rotation.pitch) yaw = rad2deg(rotation.yaw) roll = rad2deg(rotation.roll) # 将欧拉角转换为UE5骨骼旋转角度 ue_pitch = -pitch ue_yaw = yaw - 90 ue_roll = -roll return (ue_yaw, ue_pitch, ue_roll) ``` 在上述代码中,`deg2rad()`函数将角度转换为弧度,`rad2deg()`函数则将弧度转换为角度。`mediapipe_rotation_to_ue_rotation()`函数将Mediapipe中的骨骼旋转角度转换为UE5中的骨骼旋转角度,其中`rotation`是Mediapipe中的旋转角度。将欧拉角中的pitch取负数是因为UE5的pitch方向与Mediapipe相反,将yaw减去90度是因为UE5的坐标系与Mediapipe不同。 使用示例: ```python import mediapipe as mp mp_hands = mp.solutions.hands # 使用MediaPipe获取手部关键点坐标和旋转角度 with mp_hands.Hands(static_image_mode=True, max_num_hands=1, min_detection_confidence=0.5) as hands: image = cv2.imread('image.jpg') results = hands.process(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) if results.multi_hand_landmarks: for hand_landmarks in results.multi_hand_landmarks: # 获取旋转角度并转换为UE5骨骼旋转角度 ue_rotation = mediapipe_rotation_to_ue_rotation(hand_landmarks.pose_rotation) ``` 在上述代码中,`hand_landmarks.pose_rotation`是Mediapipe中的旋转角度,`mediapipe_rotation_to_ue_rotation()`函数将其转换为UE5中的骨骼旋转角度
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值