I am trying to read left and right camera images from a vehicle to do some image processing. I am unsure of how to use the same callback function to process each image. I have seen examples where the data type was different, but not where both are of the same type, such as images. In this example, separate callbacks were used.
Here is my current attempt:
import rospy
import cv2
import os
from cv_bridge import CvBridge, CvBridgeError
from sensor_msgs.msg import Image
import message_filters
def read_cameras():
imageL = rospy.Subscriber("/camera/left/image_raw", Image, image_callback)
imageR = rospy.Subscriber("/camera/right/image_raw", Image, image_callback)
# Synch images here ?
ts = message_filters.ApproximateTimeSynchronizer([imageL, imageR], 10)
rospy.spin()
def image_callback(imageL, imageR):
br = CvBridge()
rospy.loginfo("receiving frame")
imageLeft = br.imgmsg_to_cv2(imageL)
imageRight = br.imgmsg_to_cv2(imageR)
# Do some fancy computations on each image
if __name__ == '__main__':
try:
read_cameras()
except rospy.ROSInterruptException:
pass
Additionaly, even after reading the documentation on approximate time synchronization, I still don't understand the parameters I need to input. Each camera should be outputting images at 24fps.