Sign in to follow this  
Homagni Saha

Getting images from both cameras in sawyer

Recommended Posts

Hello,
I was recently trying to follow along the code for displaying two camera images from the sawyer one-handed robot.
Here:
http://sdk.rethinkrobotics.com/intera/Camera_Image_Display_Example


Now the camera interface in sawyer does not allow to have two cameras on, but I need it !, so I did :
(after installing sawyer gazebo from here :http://sdk.rethinkrobotics.com/intera/Gazebo_Tutorial)

    import argparse
    import numpy as np
    import cv2
    from cv_bridge import CvBridge, CvBridgeError
    import rospy
    import intera_interface
    from sensor_msgs.msg import Image
    import message_filters
    def img_callback(image_hand,image_head):
        bridge1 = CvBridge()
        bridge2 = CvBridge()
        try:
          cv_image1 = bridge1.imgmsg_to_cv2(image_hand, "mono8")
        except CvBridgeError as e:
          print(e)
        cv2.imshow("Hand Image window", cv_image1)
        cur_image_hand=cv2.resize(cv_image1, (80, 80))
        cv2.waitKey(3)
        try:
          cv_image2 = bridge2.imgmsg_to_cv2(image_head, "bgr8")
        except CvBridgeError as e:
          print(e)
        cv2.imshow("Head Image window", cv_image2)
        gray_image = cv2.cvtColor(cv_image2, cv2.COLOR_BGR2GRAY)
        cur_image_head=cv2.resize(gray_image, (80, 80))
        #rospy.spin()
        cv2.waitKey(3)
    def main():
        rospy.init_node('image_converter', anonymous=True)
        image_sub_hand = message_filters.Subscriber("/io/internal_camera/right_hand_camera/image_rect",Image) 
        image_sub_head = message_filters.Subscriber("/io/internal_camera/head_camera/image_rect_color",Image)
        #ts = message_filters.TimeSynchronizer([self.image_sub_hand, self.image_sub_head], 10)
        ts = message_filters.TimeSynchronizer([image_sub_hand, image_sub_head], 10)
        ts.registerCallback(img_callback)
        rospy.spin()

    if __name__ == '__main__':
        main()

This code starts with both the images showing nicely together in two seperate windows for a few seconds, but after that both the cv windows blacken out and images are not updated anymore .
Please suggest what to do, and provide me the best solution that allows me to access these two topics at any time using python code.
 

Share this post


Link to post
Share on other sites

I dont remeber where I found it, may even be from this forum, but I have a script that allows both cameras to work simultaneously. I've not done much with it myself but it worked in Rviz. Hope this helps you out.

both_cam.py

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this