Using two "heterogeneous" subscribers
Hi all, I am using ROS Noetic. My goal is to use two subscribers, one to get bounding boxes from Yolo and the other is to get the image from the camera. For that, I am using message_filters, specifically, the ApproximateTimeSynchronizer policy. The problem is that the callback does not work. The program is the following:
#!/usr/bin/env python3.6
import rospy
import math
import numpy as np
import roslib
import sys
import message_filters
from cv_bridge import CvBridge, CvBridgeError
from std_msgs.msg import Header
from sensor_msgs.msg import Image, CameraInfo
import matplotlib.image as mpimg
import cv2
import glob
from perspective.msg import BoundingBoxes, BoundingBox
class listener():
def __init__(self):
print("camera 1")
self.bridge= CvBridge()
self.image_sub = message_filters.Subscriber('/CAM_0/image_raw', Image)
self.image_bounding_sub= message_filters.Subscriber('/darknet_ros/bounding_boxes', BoundingBoxes)
self.ts = message_filters.ApproximateTimeSynchronizer([ self.image_bounding_sub, self.image_sub], queue_size=100, slop=0.1, allow_headerless=True)
self.ts.registerCallback(self.callback)
#rospy.spin()
print("camera 2")
def callback(self,data,imageraw):
print("callback")
for i in range(0,len(data.bounding_boxes)-1):
#print("id", data.bounding_boxes[i].id)
#print("xmax", data.bounding_boxes[i].xmax)
if data.bounding_boxes[i].xmax < 1100 and data.bounding_boxes[i].xmax > 177:
print("In ROI", data.bounding_boxes[i].xmax)
cv_image = self.bridge.imgmsg_to_cv2(imageraw,"bgr8")
def main():
rospy.init_node('perspective', anonymous=True)
#sum()
listener()
print("main")
rospy.spin()
if __name__ == '__main__':
print("start")
main()
When I make the two subscribers with the same type (Bounding Box or camera), it works. Does anyone, please, have an idea to fix this problem? thank you.
Try this out https://github.com/lucasw/topic_state...
And see if you see both topics commingled in the output (and look to see if they are within 0.1s of each other).
I'll soon modify that script to optionally do exact and approximate time syncing also, which would be an even better test for you.