Last active
December 6, 2018 05:04
-
-
Save initmaks/5806218362dcb08e878f165268ead04e to your computer and use it in GitHub Desktop.
Capturing image from the color and depth ros topics of realsense camera
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# Capturing image from the color and depth ros topics of realsense camera | |
# Adapted from http://wiki.ros.org/cv_bridge/Tutorials/ConvertingBetweenROSImagesAndOpenCVImagesPython | |
import rospy | |
import cv2 | |
from sensor_msgs.msg import Image | |
from cv_bridge import CvBridge | |
class image_converter: | |
def __init__(self): | |
self.bridge = CvBridge() | |
self.color_sub = rospy.Subscriber("/realsense/camera/color/image_raw",Image,self.callback) | |
self.depth_sub = rospy.Subscriber("/realsense/camera/depth/image_raw",Image,self.callback) | |
def callback(self,data): | |
try: | |
cv_image = self.bridge.imgmsg_to_cv2(data, "bgr8") | |
except: | |
cv_image = self.bridge.imgmsg_to_cv2(data) | |
print(type(cv_image)) # numpy | |
print(cv_image.shape) | |
def main(args): | |
ic = image_converter() | |
rospy.init_node('image_converter', anonymous=True) | |
try: | |
rospy.spin() | |
except KeyboardInterrupt: | |
print("Shutting down") | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment