Subscriber python CameraInfo and Image
Hello i am new to ros and python. Need little help in how to subscribe to CameraInfo and Image of format sensor_msgs.msg and use its data for further image processing. Here are few lines of code that i am starting with:
from sensor_msgs.msg import CameraInfo, Image
from cv_bridge import CvBridge, CvBridgeError
import cv2
if __name__ == '__main__':
rospy.init_node('node_name')
while ~rospy.is_shutdown():
sub_cam_info = rospy.Subscriber('/camera/rgb/raw_camera_info', CameraInfo)
sub_rgb = rospy.Subscriber('/camera/rgb/raw_image_color', Image)
From here i want to extract header and data information from 'sub_cam_info' and 'sub_rgb'. Something like this:
camera_info_K = sub_cam_info.K
camera_info_dist_model = sub_cam_info.distortion_model
rgb_image = CvBridge().imgmsg_to_cv2(sub_rgb, encoding="rgb8")
And then use this data for image undistortion:-
rgb_undist = cv2.undistort(rgb_img.data, camera_info_K, camera_info_dist_model)
Mainly i need help in second part i.e. extraction of parameters from CameraInfo and Image msgs. However if someone can help me to sort out body of this whole code! I am already through making up my own CameraInfo and rgb messages, using them for undistortion and publishing on ROS by but now i want to get them from another ROS module and work with them.
Thanks