Created
February 12, 2020 13:52
-
-
Save alexkutsan/f8f254d117fed7beaa1eee6456597ac6 to your computer and use it in GitHub Desktop.
listener.py
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
import rospy | |
from std_msgs.msg import String | |
from std_msgs.msg import String | |
from sensor_msgs.msg import CompressedImage | |
import numpy as np | |
import cv2 | |
from cv_bridge import CvBridge | |
def callback(data): | |
#rospy.loginfo(rospy.get_caller_id() + 'I heard ') | |
#print(type(data)) | |
#c = np.fromstring(bytes(data), np.uint8) | |
np_arr = np.fromstring(data.data, np.uint8) | |
#br = CvBridge() | |
#im2 = br.imgmsg_to_cv2(msg) | |
#print(c, len(c)) | |
image = cv2.imdecode(np_arr, cv2.IMREAD_COLOR) | |
resized = cv2.resize(image, (640,480)) | |
cv2.imshow('LGSVL End-to-End Lane Following', resized) | |
cv2.waitKey(1) | |
def callback2(data): | |
rospy.loginfo(rospy.get_caller_id() + 'I heard ', data) | |
def listener(): | |
# In ROS, nodes are uniquely named. If two nodes with the same | |
# name are launched, the previous one is kicked off. The | |
# anonymous=True flag means that rospy will choose a unique | |
# name for our 'listener' node so that multiple listeners can | |
# run simultaneously. | |
rospy.init_node('listener', anonymous=True) | |
subscriber = rospy.Subscriber('/simulator/camera_node/image/compressed', CompressedImage, callback) | |
subscriber = rospy.Subscriber('/odom', String, callback2) | |
# spin() simply keeps python from exiting until this node is stopped | |
rospy.spin() | |
if __name__ == '__main__': | |
listener() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment