def __init__(self, node_name='naoqi_camera'):
NaoqiNode.__init__(self, node_name)
self.camProxy = self.get_proxy("ALVideoDevice")
if self.camProxy is None:
exit(1)
self.nameId = None
self.camera_infos = {}
def returnNone():
return None
self.config = defaultdict(returnNone)
# ROS publishers
self.pub_img_ = rospy.Publisher('~image_raw', Image, queue_size=5)
self.pub_info_ = rospy.Publisher('~camera_info', CameraInfo, queue_size=5)
# initialize the parameter server
self.srv = Server(NaoqiCameraConfig, self.reconfigure)
# initial load from param server
self.init_config()
# initially load configurations
self.reconfigure(self.config, 0)
python类CameraInfo()的实例源码
def __init__(self):
rospy.loginfo("Zarj eyes initialization begin")
self.bridge = CvBridge()
self.sub_left = None
self.sub_right = None
self.sub_cloud = None
self.processors = []
self.disabled = False
self.left_image = None
self.right_image = None
self.cloud = None
self.p_left = None
self.cloud_image_count = 0
self.info_sub_l = rospy.Subscriber(
"/multisense/camera/left/camera_info", CameraInfo, self.info_left)
rospy.loginfo("Zarj eyes initialization finished")
def make_camera_msg(cam):
camera_info_msg = CameraInfo()
width, height = cam[0], cam[1]
fx, fy = cam[2], cam[3]
cx, cy = cam[4], cam[5]
camera_info_msg.width = width
camera_info_msg.height = height
camera_info_msg.K = [fx, 0, cx,
0, fy, cy,
0, 0, 1]
camera_info_msg.D = [0, 0, 0, 0]
camera_info_msg.P = [fx, 0, cx, 0,
0, fy, cy, 0,
0, 0, 1, 0]
return camera_info_msg
detect_crazyflie.py 文件源码
项目:ROS-Robotics-By-Example
作者: PacktPublishing
项目源码
文件源码
阅读 27
收藏 0
点赞 0
评论 0
def __init__(self):
# initialize ROS node and transform publisher
rospy.init_node('crazyflie_detector', anonymous=True)
self.pub_tf = tf.TransformBroadcaster()
self.rate = rospy.Rate(50.0) # publish transform at 50 Hz
# initialize values for crazyflie location on Kinect v2 image
self.cf_u = 0 # u is pixels left(0) to right(+)
self.cf_v = 0 # v is pixels top(0) to bottom(+)
self.cf_d = 0 # d is distance camera(0) to crazyflie(+) from depth image
self.last_d = 0 # last non-zero depth measurement
# crazyflie orientation to Kinect v2 image (Euler)
self.r = -1.5708
self.p = 0
self.y = -3.1415
# Convert image from a ROS image message to a CV image
self.bridge = CvBridge()
cv2.namedWindow("KinectV2", 1)
# Wait for the camera_info topic to become available
rospy.wait_for_message('/kinect2/qhd/camera_info', CameraInfo)
# Subscribe to Kinect v2 sd camera_info to get image frame height and width
rospy.Subscriber('/kinect2/qhd/camera_info', CameraInfo, self.camera_data, queue_size=1)
# Subscribe to registered color and depth images
rospy.Subscriber('/kinect2/qhd/image_color_rect', Image, self.image_callback, queue_size=1)
rospy.Subscriber('/kinect2/qhd/image_depth_rect', Image, self.depth_callback, queue_size=1)
self.rate.sleep() # suspend until next cycle
# This callback function sets parameters regarding the camera.
def start(self):
""" Start the sensor """
# initialize subscribers
self._pointcloud_sub = rospy.Subscriber('/%s/depth/points' %(self.frame), PointCloud2, self._pointcloud_callback)
self._camera_info_sub = rospy.Subscriber('/%s/left/camera_info' %(self.frame), CameraInfo, self._camera_info_callback)
while self._camera_intr is None:
time.sleep(0.1)
self._running = True
def rosmsg(self):
""":obj:`sensor_msgs.CamerInfo` : Returns ROS CamerInfo msg
"""
msg_header = Header()
msg_header.frame_id = self._frame
msg_roi = RegionOfInterest()
msg_roi.x_offset = 0
msg_roi.y_offset = 0
msg_roi.height = 0
msg_roi.width = 0
msg_roi.do_rectify = 0
msg = CameraInfo()
msg.header = msg_header
msg.height = self._height
msg.width = self._width
msg.distortion_model = 'plumb_bob'
msg.D = [0.0, 0.0, 0.0, 0.0, 0.0]
msg.K = [self._fx, 0.0, self._cx, 0.0, self._fy, self._cy, 0.0, 0.0, 1.0]
msg.R = [1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0]
msg.P = [self._fx, 0.0, self._cx, 0.0, 0.0, self._fx, self._cy, 0.0, 0.0, 0.0, 1.0, 0.0]
msg.binning_x = 0
msg.binning_y = 0
msg.roi = msg_roi
return msg
def __init__(self):
# initialize ROS node and transform publisher
rospy.init_node('crazyflie_detector', anonymous=True)
self.pub_tf = tf.TransformBroadcaster()
self.rate = rospy.Rate(50.0) # publish transform at 50 Hz
# initialize values for crazyflie location on Kinect v2 image
self.cf_u = 0 # u is pixels left(0) to right(+)
self.cf_v = 0 # v is pixels top(0) to bottom(+)
self.cf_d = 0 # d is distance camera(0) to crazyflie(+) from depth image
self.last_d = 0 # last non-zero depth measurement
# crazyflie orientation to Kinect v2 image (Euler)
self.r = -1.5708
self.p = 0
self.y = -3.1415
# Convert image from a ROS image message to a CV image
self.bridge = CvBridge()
cv2.namedWindow("KinectV2", 1)
# Wait for the camera_info topic to become available
rospy.wait_for_message('/kinect2/qhd/camera_info', CameraInfo)
# Subscribe to Kinect v2 sd camera_info to get image frame height and width
rospy.Subscriber('/kinect2/qhd/camera_info', CameraInfo, self.camera_data, queue_size=1)
# Subscribe to registered color and depth images
rospy.Subscriber('/kinect2/qhd/image_color_rect', Image, self.image_callback, queue_size=1)
rospy.Subscriber('/kinect2/qhd/image_depth_rect', Image, self.depth_callback, queue_size=1)
self.rate.sleep() # suspend until next cycle
# This callback function sets parameters regarding the camera.