36 from collections
import defaultdict
38 from sensor_msgs.msg
import Image, CameraInfo
40 import camera_info_manager
41 from sensor_msgs.msg._CameraInfo
import CameraInfo
43 from naoqi
import ALProxy
45 from cv_bridge
import CvBridge, CvBridgeError
54 NaoqiNode.__init__(self,
'nao_depth')
66 self.
pub_img_ = rospy.Publisher(
'~image_raw', Image)
67 self.
pub_cimg_ = rospy.Publisher(
'~image_color', Image)
68 self.
pub_info_ = rospy.Publisher(
'~camera_info', CameraInfo)
75 self.camProxy.unsubscribeAllInstances(
"rospy_gvm")
78 self.
frame_id = rospy.get_param(
"~frame_id",
"/CameraDepth_frame")
79 resolution = rospy.get_param(
"~resolution", 1)
80 framerate = rospy.get_param(
"~fps", 15)
81 color_space= rospy.get_param(
"~color_space", 17)
82 self.
nameId = self.camProxy.subscribeCamera(
"rospy_gvm", kDepthCamera, resolution, color_space, framerate)
83 rospy.loginfo(
'Using camera: depth camera. Subscriber name is %s .' % (self.
nameId))
91 while not rospy.is_shutdown():
92 if self.pub_img_.get_num_connections() == 0:
96 image = self.camProxy.getImageRemote(self.
nameId)
101 #Images received from NAO have 102 if self.config['use_ros_time']: 103 img.header.stamp = rospy.Time.now() 105 img.header.stamp = rospy.Time(image[4] + image[5]*1e-6) 107 img.header.stamp = rospy.Time.now()
109 img.height = image[1]
112 if image[3] == kDepthColorSpace:
115 rospy.logerr(
"Received unknown encoding: {0}".format(image[3]))
116 img.encoding = encoding
117 img.step = img.width * nbLayers
120 self.pub_img_.publish(img)
123 infomsg = CameraInfo()
124 infomsg.header = img.header
126 ratio_x = float(640)/float(img.width)
127 ratio_y = float(480)/float(img.height)
128 infomsg.width = img.width
129 infomsg.height = img.height
131 infomsg.K = [ 525, 0, 3.1950000000000000e+02,
132 0, 525, 2.3950000000000000e+02,
134 infomsg.P = [ 525, 0, 3.1950000000000000e+02, 0,
135 0, 525, 2.3950000000000000e+02, 0,
139 infomsg.K[i] = infomsg.K[i] / ratio_x
140 infomsg.K[3+i] = infomsg.K[3+i] / ratio_y
141 infomsg.P[i] = infomsg.P[i] / ratio_x
142 infomsg.P[4+i] = infomsg.P[4+i] / ratio_y
145 infomsg.binning_x = 0
146 infomsg.binning_y = 0
147 infomsg.distortion_model =
"" 148 self.pub_info_.publish(infomsg)
153 colorimg = np.zeros((img.height,img.width,3), np.uint8)
155 cimg = self.bridge.cv2_to_imgmsg(colorimg,
"bgr8")
156 cimg.header.stamp = img.header.stamp
157 cimg.header.frame_id = img.header.frame_id
158 self.pub_cimg_.publish(cimg)
159 except CvBridgeError, e:
165 self.camProxy.unsubscribe(self.
nameId)
167 if __name__ ==
"__main__":
171 except RuntimeError
as e:
172 rospy.logerr(
'Something went wrong: %s' % str(e) )
173 rospy.loginfo(
'Camera stopped')
def get_proxy(self, name, warn=True)