Go to the documentation of this file.00001
00002
00003 import roslib
00004 roslib.load_manifest('jsk_pr2_startup')
00005 import sys,subprocess,traceback
00006 import rospy
00007 import cv
00008 from sensor_msgs.msg import Image
00009 from sensor_msgs.msg import CameraInfo
00010 from cv_bridge import CvBridge, CvBridgeError
00011
00012 class image_converter:
00013
00014 def __init__(self):
00015 self.bridge = CvBridge()
00016 self.image_sub = None
00017
00018 def callback(self,data):
00019 self.image_sub.unregister()
00020
00021 try:
00022 cv_image = self.bridge.imgmsg_to_cv(data, "bgr8")
00023 except CvBridgeError, e:
00024 print e
00025
00026 rospy.loginfo("sum of pixels is %d at %s", max(cv.Sum(cv_image)), data.header.stamp.secs)
00027 if max(cv.Sum(cv_image)) == 0 :
00028 rospy.logerr("Restart openni_node1")
00029 retcode = -1
00030 try:
00031 retcode = subprocess.call('rosnode kill /openni/driver', shell=True)
00032 except Exception, e:
00033 rospy.logerr('Unable to kill kinect node, caught exception:\n%s', traceback.format_exc())
00034
00035 def process(self):
00036 if self.image_sub == None or self.image_sub.impl == None:
00037 self.image_sub = rospy.Subscriber("/openni/rgb/image_color",Image,self.callback,None,1)
00038
00039
00040 def main(args):
00041 ic = image_converter()
00042 rospy.init_node('check_openni_node', anonymous=True)
00043 while not rospy.is_shutdown():
00044 ic.process()
00045 rospy.sleep(3)
00046
00047
00048 if __name__ == '__main__':
00049 main(sys.argv)