Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to subcribe 2 image topics with 1 node in same time ?

Hi buddy,

My name is Toan. I am a newbie in ROS. Now, i'm using Kinect Camera and trying to subcribe 2 image topics with 1 node. But seem like my code is wrong something. If i try to subcribe 1 node with 1 topic is fine. In details, i make case 1 or case 2 is comment , it's work for 1 node 1 topic.

What should i do now ?

This is my code:

#!/usr/bin/env python
import sys
import rospy
import numpy as np
import math
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
import cv2
#------Start of Class
class image_converter:
    def __init__(self):
        self.bridge = CvBridge()
        self.image_sub = rospy.Subscriber("/kinect/rgb",Image,self.callback_rgb)      #Case 1
        self.image_sub = rospy.Subscriber("/kinect/depth",Image,self.callback_depth)  #Case 2

    def callback_rgb(self,data):
        cv_image_rgb = self.bridge.imgmsg_to_cv2(data, "bgr8")
        cv2.imshow("RGB_Sub", cv_image_rgb)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            rospy.signal_shutdown('Quit')
            cv2.destroyAllWindows()

    def callback_depth(self, data):
        cv_image_depth = self.bridge.imgmsg_to_cv2(data, "bgr8")
        cv2.imshow("Depth_Sub", cv_image_depth)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            rospy.signal_shutdown('Quit')
            cv2.destroyAllWindows()



def main():
    img_cvt = image_converter()
    rospy.init_node('image_converter', anonymous=True)
    try:
        rospy.spin()
    except KeyboardInterrupt:
        print("Shutting down")
if __name__ == '__main__':
    main()

Error:

(RGB_Sub:9479): Gtk-WARNING **: gtk_disable_setlocale() must be called before gtk_init()
[xcb] Unknown request in queue while dequeuing
[xcb] Most likely this is a multi-threaded client and XInitThreads has not been called
[xcb] Aborting, sorry about that.
python: ../../src/xcb_io.c:179: dequeue_pending_request: Assertion `!xcb_xlib_unknown_req_in_deq' failed.
Aborted (core dumped)