add pub image-RGB
This commit is contained in:
BIN
test/__pycache__/test_cam.cpython-38.pyc
Normal file
BIN
test/__pycache__/test_cam.cpython-38.pyc
Normal file
Binary file not shown.
@@ -19,6 +19,12 @@ def main():
|
|||||||
queue_size=1
|
queue_size=1
|
||||||
)
|
)
|
||||||
|
|
||||||
|
color_pub = rospy.Publisher(
|
||||||
|
"/camera/color/image_raw",
|
||||||
|
Image,
|
||||||
|
queue_size=1
|
||||||
|
)
|
||||||
|
|
||||||
info_pub = rospy.Publisher(
|
info_pub = rospy.Publisher(
|
||||||
"/camera/depth/camera_info",
|
"/camera/depth/camera_info",
|
||||||
CameraInfo,
|
CameraInfo,
|
||||||
@@ -40,6 +46,13 @@ def main():
|
|||||||
rs.format.z16,
|
rs.format.z16,
|
||||||
fps
|
fps
|
||||||
)
|
)
|
||||||
|
config.enable_stream(
|
||||||
|
rs.stream.color,
|
||||||
|
640,
|
||||||
|
480,
|
||||||
|
rs.format.rgb8,
|
||||||
|
fps
|
||||||
|
)
|
||||||
|
|
||||||
profile = pipeline.start(config)
|
profile = pipeline.start(config)
|
||||||
|
|
||||||
@@ -55,17 +68,23 @@ def main():
|
|||||||
|
|
||||||
frames = pipeline.wait_for_frames()
|
frames = pipeline.wait_for_frames()
|
||||||
depth = frames.get_depth_frame()
|
depth = frames.get_depth_frame()
|
||||||
|
color = frames.get_color_frame()
|
||||||
|
|
||||||
if not depth:
|
if not depth or not color:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
depth_image = np.asanyarray(depth.get_data())
|
depth_image = np.asanyarray(depth.get_data())
|
||||||
|
color_image = np.asanyarray(color.get_data())
|
||||||
|
|
||||||
# Image message
|
# Image message
|
||||||
img_msg = bridge.cv2_to_imgmsg(depth_image, encoding="16UC1")
|
img_msg = bridge.cv2_to_imgmsg(depth_image, encoding="16UC1")
|
||||||
img_msg.header.stamp = rospy.Time.now()
|
img_msg.header.stamp = rospy.Time.now()
|
||||||
img_msg.header.frame_id = "camera_depth_optical_frame"
|
img_msg.header.frame_id = "camera_depth_optical_frame"
|
||||||
|
|
||||||
|
color_msg = bridge.cv2_to_imgmsg(color_image, encoding="rgb8")
|
||||||
|
color_msg.header.stamp = img_msg.header.stamp
|
||||||
|
color_msg.header.frame_id = "camera_color_optical_frame"
|
||||||
|
|
||||||
# CameraInfo message
|
# CameraInfo message
|
||||||
info_msg = CameraInfo()
|
info_msg = CameraInfo()
|
||||||
info_msg.header = img_msg.header
|
info_msg.header = img_msg.header
|
||||||
@@ -100,6 +119,7 @@ def main():
|
|||||||
]
|
]
|
||||||
|
|
||||||
depth_pub.publish(img_msg)
|
depth_pub.publish(img_msg)
|
||||||
|
color_pub.publish(color_msg)
|
||||||
info_pub.publish(info_msg)
|
info_pub.publish(info_msg)
|
||||||
|
|
||||||
rate.sleep()
|
rate.sleep()
|
||||||
@@ -108,4 +128,4 @@ def main():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|||||||
Reference in New Issue
Block a user