Create custom ros message instead of using json strings.
This commit is contained in:
@ -7,6 +7,8 @@
|
||||
<maintainer email="root@todo.todo">root</maintainer>
|
||||
<license>TODO: License declaration</license>
|
||||
|
||||
<exec_depend>rpt_msgs</exec_depend>
|
||||
|
||||
<test_depend>ament_copyright</test_depend>
|
||||
<test_depend>ament_flake8</test_depend>
|
||||
<test_depend>ament_pep257</test_depend>
|
||||
|
||||
@ -1,4 +1,3 @@
|
||||
import json
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
@ -10,8 +9,8 @@ import rclpy
|
||||
from cv_bridge import CvBridge
|
||||
from rclpy.qos import QoSHistoryPolicy, QoSProfile, QoSReliabilityPolicy
|
||||
from sensor_msgs.msg import Image
|
||||
from std_msgs.msg import String
|
||||
|
||||
from rpt_msgs.msg import Pose
|
||||
from skelda import utils_view
|
||||
|
||||
# ==================================================================================================
|
||||
@ -70,8 +69,9 @@ def callback_poses(pose_data):
|
||||
if last_input_image is None:
|
||||
return
|
||||
|
||||
# Convert pose data from json string
|
||||
poses = json.loads(pose_data.data)
|
||||
# Extract pose data
|
||||
joint_names = pose_data.joint_names
|
||||
bodies2D = np.array(pose_data.bodies_flat).reshape(pose_data.bodies_shape).tolist()
|
||||
|
||||
# Collect inputs
|
||||
images_2d = []
|
||||
@ -83,12 +83,11 @@ def callback_poses(pose_data):
|
||||
timestamps.append(ts)
|
||||
|
||||
# Visualize 2D poses
|
||||
bodies2D = poses["bodies2D"]
|
||||
colors = plt.cm.hsv(np.linspace(0, 1, len(bodies2D), endpoint=False)).tolist()
|
||||
colors = [[int(c[0] * 255), int(c[1] * 255), int(c[2] * 255)] for c in colors]
|
||||
for i, body in enumerate(bodies2D):
|
||||
color = list(reversed(colors[i]))
|
||||
img = utils_view.draw_body_in_image(img, body, poses["joints"], color)
|
||||
img = utils_view.draw_body_in_image(img, body, joint_names, color)
|
||||
|
||||
# Publish image with poses
|
||||
publish(img)
|
||||
@ -131,7 +130,7 @@ def main():
|
||||
qos_profile,
|
||||
)
|
||||
_ = node.create_subscription(
|
||||
String,
|
||||
Pose,
|
||||
pose_input_topic,
|
||||
callback_poses,
|
||||
qos_profile,
|
||||
|
||||
Reference in New Issue
Block a user