Getting error as - "ERROR: Unable to communicate with master!" [closed]

asked 2013-09-03 20:20:20 -0500

Brijendra Singh gravatar image

updated 2014-04-20 14:06:45 -0500

ngrennan gravatar image

Hi,

I am trying to capture images (python code) from the "/camera/rgb/image_color" topic on which images are published from kinect and saving them locally. But call back of subscriber stops and doesn't even get called up after 1-2 times calling up. So could capture image only once but stops later. I want python code to capture image from some topic and store them locally. Please suggest what should I use webcam or kinect and how.

Code is as follows-

import roslib
roslib.load_manifest('beginner_tutorials')
import sys
import rospy
import cv
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError

class image_converter:

  def __init__(self):
    #self.image_pub = rospy.Publisher("image_topic_2",Image)
    print "1"
    cv.NamedWindow("Image window", 1)
    self.bridge = CvBridge()
    self.image_sub = rospy.Subscriber("/camera/rgb/image_color",Image,self.callback)

  def callback(self,data):
    print "2"

    try:
      cv_image = self.bridge.imgmsg_to_cv(data, "bgr8")
    except CvBridgeError, e:
      print e

    #(cols,rows) = cv.GetSize(cv_image)
    #if cols > 60 and rows > 60 :
     # cv.Circle(cv_image, (50,50), 10, 255)

    cv.SaveImage("foo.png", cv_image)
    #cv.ShowImage("Image window", cv_image)
    #cv.WaitKey(3)


    try:
    pass
      #self.image_pub.publish(self.bridge.cv_to_imgmsg(cv_image, "bgr8"))
    except CvBridgeError, e:
      print e

def main(args):
  #app = wx.App()
  ic = image_converter()
  rospy.init_node('image_converter', anonymous=True)
  try:
    rospy.spin()
  except KeyboardInterrupt:
    print "Shutting down"
  cv.DestroyAllWindows()

if __name__ == '__main__':
    main(sys.argv)
edit retag flag offensive reopen merge delete

Closed for the following reason question is not relevant or outdated by tfoote
close date 2016-08-08 01:40:22.526325

Comments

1

Did you run `roscore` to start master?

FranciscoD gravatar image FranciscoD  ( 2013-09-03 23:24:08 -0500 )edit

Thanks alot for responding No, in Robo machine I tried these commands, roslaunch turtlebot_bringup minimal.launch rosrun turtlebot_dashboard turtlebot_dashboard roslaunch openni_launch openni.launch so I don't think it requres roscore to be started. Please let me know if there is some error in code.

Brijendra Singh gravatar image Brijendra Singh  ( 2013-09-04 06:50:38 -0500 )edit

No clue about the code. Since you're using roslaunch, roscore will be running. It's another issue then.

FranciscoD gravatar image FranciscoD  ( 2013-09-04 20:43:20 -0500 )edit