Skip to content

Instantly share code, notes, and snippets.

@potix2
Created November 17, 2016 09:17
Show Gist options
  • Save potix2/b434f66077a4f64c30e0d66be973680f to your computer and use it in GitHub Desktop.
Save potix2/b434f66077a4f64c30e0d66be973680f to your computer and use it in GitHub Desktop.
rostopic list | grep kinect2
/kinect2/bond
/kinect2/hd/camera_info
/kinect2/hd/image_color
/kinect2/hd/image_color/compressed
/kinect2/hd/image_color_rect
/kinect2/hd/image_color_rect/compressed
/kinect2/hd/image_depth_rect
/kinect2/hd/image_depth_rect/compressed
/kinect2/hd/image_mono
/kinect2/hd/image_mono/compressed
/kinect2/hd/image_mono_rect
/kinect2/hd/image_mono_rect/compressed
/kinect2/hd/points
/kinect2/qhd/camera_info
/kinect2/qhd/image_color
/kinect2/qhd/image_color/compressed
/kinect2/qhd/image_color_rect
/kinect2/qhd/image_color_rect/compressed
/kinect2/qhd/image_depth_rect
/kinect2/qhd/image_depth_rect/compressed
/kinect2/qhd/image_mono
/kinect2/qhd/image_mono/compressed
/kinect2/qhd/image_mono_rect
/kinect2/qhd/image_mono_rect/compressed
/kinect2/qhd/points
/kinect2/sd/camera_info
/kinect2/sd/image_color_rect
/kinect2/sd/image_color_rect/compressed
/kinect2/sd/image_depth
/kinect2/sd/image_depth/compressed
/kinect2/sd/image_depth_rect
/kinect2/sd/image_depth_rect/compressed
/kinect2/sd/image_ir
/kinect2/sd/image_ir/compressed
/kinect2/sd/image_ir_rect
/kinect2/sd/image_ir_rect/compressed
/kinect2/sd/points
(anaconda-2.1.0) potix2@ros% rostopic info /kinect2/sd/image_color_rect [~/catkin_ws] {}
Type: sensor_msgs/Image
Publishers:
* /kinect2 (http://ros:42318/)
Subscribers: None
(anaconda-2.1.0) potix2@ros%
#!/usr/bin/env python
"""
Script to retrieve sensor images from kinect
"""
import roslib
import rospy
import cv2
import sys
from std_msgs.msg import String
from sensor_msgs.msg import Image
from cv_bridge import CvBridge, CvBridgeError
class image_converter:
def __init__(self):
# subscribe to kinect image messages
self.sub = rospy.Subscriber("kinect2/qhd/image_color", Image, self.image_callback, queue_size=1)
self.bridge = CvBridge()
def image_callback(self,data):
try:
cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8")
except CvBridgeError as e:
print(e)
cv2.imshow("Image window", cv_image)
cv2.waitKey(3)
def main(args):
ic = image_converter()
rospy.init_node('kinect_tracker')
try:
rospy.spin()
except KeyboardInterrupt:
print("Shutting down")
cv2.destroyAllWindows()
if __name__ == '__main__':
main(sys.argv)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment