def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.waypoints_2d = None self.waypoints_tree = None self.camera_image = None self.lights = [] self.bridge = CvBridge() # Load classifier with model from launch file. But we don't use this for simulator. self.light_classifier = TLClassifier(rospy.get_param('~model_file')) self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.class_count = 0 self.process_count = 0 ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' # Setup subscribers rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb, queue_size=2) rospy.Subscriber('/image_color', Image, self.image_cb, queue_size=1) rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb, queue_size=2) rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb, queue_size=8) # Setup publishers self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) self.sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) ''' /vehicle/traffic_lights helps you acquire an accurate ground truth data source for the traffic light classifier, providing the location and current color state of all traffic lights in the simulator. This state can be used to generate classified images or subbed into your solution to help you work on another single component of the node. This topic won't be available when testing your solution in real life so don't rely on it in the final submission. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) #self.dbg_img = rospy.Publisher('/dbg_img', Image, queue_size=1) # To view: rosrun image_view image_view image:=/dbg_img rospy.spin()
def __init__(self): rospy.init_node('tl_detector') config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) stop_line_positions = self.config['stop_line_positions'] self.wp_manager = WayPointsManager(stop_line_positions) self.pose = None self.camera_image = None sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.wp_manager.waypoints_cb) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) # Topic published by waypoint updater. To avoid redundant computations locally, obtain it by subscription. rospy.Subscriber('/vehicle_wp_idx', Int32, self.ego_curr_wp_idx) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.state_count = 0 self.tls = None self.light_wp_idx = -1 self.ego_wp_idx = -1 self.loop()
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.xycoords_orig_waypoints = None self.kdtree_orig_waypoints = None self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.bridge = CvBridge() self.light_classifier = TLClassifier() #classify a blank black image at first, since the first image takes too long to classify self.light_classifier.get_classification(np.zeros((600, 800, 3))) self.listener = tf.TransformListener() config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.camera_image = None sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb, queue_size=1) config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.stop_lights = [] for counter, stl in enumerate(self.config["stop_line_positions"]): self.stop_lights.append(StopLight("tl{0}".format(counter), np.array(stl))) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.bridge = CvBridge() self.count_predictions = 0 self.count_correct_predictions = 0 self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.waypoint_tree = None self.last_wp = -1 self.state_count = 0 self.light_classifier = TLClassifier() self.listener = tf.TransformListener() rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.tl_wps = [] # Initialize it before using it in /traffic_waypoint publisher self.light_classifier = TLClassifier() sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.bridge = CvBridge() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.tl_classes = ['RED', 'YELLOW', 'GREEN', 'UNKNOWN'] rospy.spin()
def __init__(self): self.initialized = False rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.waypoints_tree = None self.camera_image = None self.lights = [] self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 config_string = rospy.get_param("/traffic_light_config") threshold = rospy.get_param('~threshold', 0.2) hw_ratio = rospy.get_param('~hw_ratio', 1.5) self.sim_testing = bool(rospy.get_param("~sim_testing", True)) sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.light_image_bbox = rospy.Publisher('/image_color_bbox', Image, queue_size=1) self.bridge = CvBridge() self.light_classifier = TLClassifier(threshold, hw_ratio, self.sim_testing) self.listener = tf.TransformListener() self.initialized = True rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.waypoint_tree = None self.waypoints_2d = None self.camera_image = None self.lights = [] ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) rospy.Subscriber('/image_color', Image, self.image_cb) config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) if TEST_MODE_ENABLED: self.bridge, self.light_classifier = None, None rospy.logwarn( "Test Mode engaged! (light state will be retrieved directly)") else: self.bridge = CvBridge() self.light_classifier = TLClassifier() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 rospy.spin()
def __init__(self): Detector.__init__(self) self.bridge = CvBridge() self.light_classifier = TLClassifier() self.state = TrafficLight.UNKNOWN self.state_count = 0 self.dbw_enabled = False # the number of waypoints car brake but over the stopline self.brake_buffer = rospy.get_param('~brake_buffer', 5) rospy.Subscriber('/image_color', Image, self.image_cb, queue_size=1, buff_size=5760000) # subscribe the dbw_enabled to check car's position and orientation and set correct direction rospy.Subscriber('/vehicle/dbw_enabled', Bool, self.dbw_enabled_cb) self.upcoming_red_light_pub.publish(-1) rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.use_ground_truth = USE_GROUND_TRUTH # Traffic light classifier's thread and its task queue. self.image_processing = False self.queue = Queue() self.light_classifier = TLClassifier(self.queue, self.classified_cb) self.light_classifier.daemon = True self.light_classifier.start() self.config = yaml.load(rospy.get_param("/traffic_light_config")) self.cv_bridge = CvBridge() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.next_waypoint_ahead = None self.waypoints = None self.traffic_lights = RouteTrafficLights() # Subscribers. sub0 = rospy.Subscriber('/next_waypoint_ahead', Int32, self.wp_cb) sub1 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) sub2 = rospy.Subscriber('/image_color', Image, self.image_cb) ''' /vehicle/traffic_lights provides the location of the traffic light in 3D map space and helps to acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) # Publishers. self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) rospy.spin()
def get_light_state(self, light): """Determines the current color of the traffic light Args: light (TrafficLight): light to classify Returns: int: ID of traffic light color (specified in styx_msgs/TrafficLight) """ if (not self.has_image): self.prev_light_loc = None return False imag = self.bridge.imgmsg_to_cv2(self.camera_image, "bgr8") cv_image = cv2.cvtColor(imag, cv2.COLOR_BGR2RGB) #Get classification if self.light_classifier is None: self.light_classifier = TLClassifier() return self.light_classifier.get_classification(cv_image)
def __init__(self): rospy.init_node('tl_detector') config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.is_site = self.config["is_site"] rospy.loginfo("Is Site: {}".format(self.is_site)) self.pose, self.waypoints, self.camera_image, self.waypoints_2d, \ self.waypoints_tree = Helper.get_none_instances(5) self.lights = [] self.bridge = CvBridge() self.light_classifier = TLClassifier(self.is_site) self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.prev_light_loc = None self.has_image = False sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.loop_rate = 10 # in Hz. self.loop()
def __init__(self): rospy.init_node('tl_detector') self.debug_idx = 0 self.debug_camera_out = False self.pose = None self.base_lane = None self.waypoints_2d = None self.waypoint_tree = None self.camera_image = None self.lights = [] config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub4 = rospy.Subscriber('/image_color', Image, self.image_cb) sub5 = rospy.Subscriber('/debug_camera_out', Bool, self.debug_camera_out_cb) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.waypoint_tree = None self.has_image = False self.prev_img_time = 0.0 self.tlmap = ('Red', 'Yellow', 'Green') self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 # Create subscribers sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) # Get Traffic light config config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) # Publisher for upcoming red lights self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) if DEBUG_ON: rospy.logwarn('TrafficLight Detector Node initialized') self.loop()
def __init__(self): rospy.init_node('tl_detector') # Parameters config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) # Subscribers self.current_pose_sub = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) self.base_waypoints_sub = rospy.Subscriber('/base_waypoints', Lane, self.base_waypoints_cb) self.traffic_lights_sub = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) self.image_color_sub = rospy.Subscriber( '/image_color', Image, self.image_cb) #TODO: evaluate using image_raw instead # Publishers self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) # TL detector node variables self.current_pose = None self.base_waypoints = None self.base_waypoints_init = False self.base_waypoints_tree = None self.camera_image = None self.current_traffic_lights = [] self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.step()
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.waypoints_2D = None self.waypoint_tree = None sub1 = rospy.Subscriber( '/current_pose', PoseStamped, self.pose_cb) # can be used to determine the vehicle's location. sub2 = rospy.Subscriber( '/base_waypoints', Lane, self.waypoints_cb ) # provides the complete list of waypoints for the course. ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it.''' sub3 = rospy.Subscriber( '/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb ) #provides the (x, y, z) coordinates of all traffic lights. sub6 = rospy.Subscriber( '/image_color', Image, self.image_cb ) #which provides an image stream from the car's camera. These images are used to determine the color of upcoming traffic lights. config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher( '/traffic_waypoint', Int32, queue_size=1 ) # The node should publish the index of the waypoint for nearest upcoming red light's stop line self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.classify_count = 0 rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.position_array = [] self.site = rospy.get_param('~is_site') rospy.loginfo("TL Detector launched in site mode : (%s)", self.site) sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb, queue_size= STATE_COUNT_THRESHOLD) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb, queue_size= STATE_COUNT_THRESHOLD) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb, queue_size= STATE_COUNT_THRESHOLD) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb, queue_size = STATE_COUNT_THRESHOLD) config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size= STATE_COUNT_THRESHOLD) self.bridge = CvBridge() self.light_classifier = TLClassifier(self.site) self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.pose = None # vehicle position self.waypoints = None # track waypoint buffer self.camera_image = None # buffer for camera images self.lights = [] # buffer for traffic light informations on track self.waypoint_tree = None # space-partitioning data structure for quick comparision self.waypoints_2d = None # to extract only the position information of waypoint segements sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.base_waypoints = None self.waypoints_2d = None self.waypoint_tree = None self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.bridge = CvBridge() self.light_classifier = TLClassifier(rospy.get_param('~model_file')) self.listener = tf.TransformListener() config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb, queue_size=2) rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb, queue_size=2) rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb, queue_size=1) rospy.Subscriber('/image_color', Image, self.image_cb, queue_size=10) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) rospy.logwarn("tldetector init") rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.cnt = 0 self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.pose = None self.waypoints_2d = None self.waypoint_tree = None self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.is_site = self.config['is_site'] rospy.loginfo("Site: {}".format(self.is_site)) self.bridge = CvBridge() # Depending on site or simulation it uses different classifier if self.is_site: self.light_classifier = TLClassifierSite() else: self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.upcoming_traffic_light_pub = rospy.Publisher( '/traffic_waypoint2', TrafficLightWithState, queue_size=1) sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) rospy.spin()
def __init__(self): rospy.init_node('tl_detector') config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.is_carla = self.config['is_site'] rospy.logwarn("Is carla: {0}".format(self.is_carla)) print self.is_carla self.pose = None self.base_waypoints = None self.waypoints_2d = None self.waypoint_tree = None self.camera_image = None self.lights = [] sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.bridge = CvBridge() self.light_classifier = TLClassifier( self.is_carla) # whether using carla or simulator self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.dist2sl = None self.ros_spin()
def __init__(self, enable_classification=True): rospy.init_node('tl_detector') self.enable_classification = enable_classification self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.waypoints_2d = None self.waypoints_tree = None self.stopline_list = [] rospy.Subscriber('/current_pose', PoseStamped, self.pose_callback) rospy.Subscriber('/base_waypoints', Lane, self.waypoints_callback) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_callback) rospy.Subscriber('/image_color', Image, self.image_callback) config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.bridge = CvBridge() self.light_classifier = TLClassifier(self.config["is_site"]) self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0
def __init__(self): rospy.init_node('test_classifier') self.pose = None self.waypoints = None self.camera_image = None self.lights = None self.tl_classifier = TLClassifier() self.correct_pred = 0 rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) rospy.Subscriber('/image_color', Image, self.image_cb) self.bridge = CvBridge() self.image_id = 0 self.last_state = TrafficLight.UNKNOWN # Create directory to store images captured from simulator self.img_folder = '/home/student/workspace/system_integration/traffic_light_classifier/data/sim_images/' for folder_name in ["", "RED", "YELLOW", "GREEN", "UNKNOWN"]: directory_name = self.img_folder + folder_name if not os.path.exists(directory_name): os.makedirs(directory_name) rospy.spin()
def __init__(self): rospy.init_node("tl_detector") # tools self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() # internal state self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 # parameters config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) # publishers self.upcoming_red_light_pub = rospy.Publisher("/traffic_waypoint", Int32, queue_size=1) # subscribers self.pose = None self.waypoints = None self.waypoints_2d = None self.waypoint_tree = None self.camera_image = None self.lights = [] rospy.Subscriber("/current_pose", PoseStamped, self.pose_cb) rospy.Subscriber("/base_waypoints", Lane, self.waypoints_cb) rospy.Subscriber("/image_color", Image, self.image_cb) rospy.Subscriber("/vehicle/traffic_lights", TrafficLightArray, self.traffic_cb) rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.camera_image = None self.lights = [] rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' self.traffic_lights_sub = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) rospy.Subscriber('/image_color', Image, self.image_cb) self.upcoming_traffic_light_pub = rospy.Publisher('/traffic_waypoint', TrafficLight, queue_size=1) self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 self.traffic_lights_kdtree = None rospy.spin()
def f(instruction_conn, result_conn): from time import sleep bridge = CvBridge() light_classifier = TLClassifier() print('subprocess started') while instruction_conn.poll() is False: print('waiting on first') sleep(0.5) current_image = instruction_conn.recv() while True: print("Processing image: {0}", len(str(current_image.header.seq))) sleep(2) print("Finished Processing image: {0}", len(str(current_image.header.seq))) current_image = None current_best = None while instruction_conn.poll(): if current_image is not None: print("Skipping: {0}", len(str(current_image.header.seq))) current_image = instruction_conn.recv() classification = get_classification(light_classifier, bridge, current_image) result_conn.send(classification)
def get_light_state(self, light): """Determines the current color of the traffic light Args: light (TrafficLight): light to classify Returns: int: ID of traffic light color (specified in styx_msgs/TrafficLight) """ if self.is_site: model_path = rospy.get_param("model_path") light_classifier = TLClassifier(model_path) if (not self.has_image): self.prev_light_loc = None return False cv_image = self.bridge.imgmsg_to_cv2(self.camera_image, "bgr8") #Get classification return light_classifier.get_classification(cv_image) else: return light.state
def __init__(self): rospy.init_node('tl_detector') self.pose = None self.waypoints = None self.camera_image = None self.lights = [] self.intersection_info = None config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Intersection, queue_size=1) self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.intersection = None self.last_intersection = None self.state_count = 0 self.previous_light_wp = -1 self.previous_light_detection = -1 sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb) sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb) sub6 = rospy.Subscriber('/image_color', Image, self.image_cb) rospy.spin()
def __init__(self): # ============== ROS specific stuff rospy.init_node('tl_detector') rospy.Subscriber('/current_pose', PoseStamped, self.cb_pose) rospy.Subscriber('/base_waypoints', Lane, self.cb_waypoints) rospy.Subscriber('/idx_closest_waypoint', std_msgs.msg.Int32, self.cb_waypoint_next) rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.cb_traffic_lights) rospy.Subscriber('/image_color', Image, self.cb_image) self.pub_idx_wp_to_stop = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) # ========== other stuff # waypoints and egopose self.pose = None self.waypoints_2d = None self.waypoints_tree = None # traffic lights / stop lines config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.lights = None self.idx_light_next = 0 # image classification self.cv_bridge = CvBridge() self.img_cnt = 0 self.img_t_last = time.time() self.classifier = TLClassifier(filename_pb="model.pb") self.img_queue = [] # start looping rospy.spin()
def __init__(self): rospy.init_node('tl_detector') self.count = 0 self.pose = None self.waypoints = None self.waypoint_tree = None self.final_waypoints = None self.final_waypoints_2d = None self.final_waypoint_tree = None self.light_tree = None self.waypoints_2d = None self.lights_waypoints_2d = None self.traffic_light_idxs = [] self.stop_line_idxs = [] self.camera_image = None self.has_image = False self.lights = [] self.IMAGECAPTURE = False self.image_dir = "images/" self.currentNextLight = None self.foundStopLinesIdxs = False self.foundLightIdxs = False self.distToClosestLight = 0 #self.distToClosestLight self.CAMERA_RANGE = 80 rospy.loginfo("Starting TL") sub1 = rospy.Subscriber('/current_pose', PoseStamped, self.pose_cb, queue_size=1) sub2 = rospy.Subscriber('/base_waypoints', Lane, self.waypoints_cb, queue_size=1) # sub3 = rospy.Subscriber('/final_waypoints', Lane, self.final_waypoints_cb, queue_size=1) ''' /vehicle/traffic_lights provides you with the location of the traffic light in 3D map space and helps you acquire an accurate ground truth data source for the traffic light classifier by sending the current color state of all traffic lights in the simulator. When testing on the vehicle, the color state will not be available. You'll need to rely on the position of the light and the camera image to predict it. ''' sub3 = rospy.Subscriber('/vehicle/traffic_lights', TrafficLightArray, self.traffic_cb, queue_size=1) # self.sub6 = rospy.Subscriber('/image_color', Image, self.image_cb, queue_size=1, buff_size=5000000) config_string = rospy.get_param("/traffic_light_config") self.config = yaml.load(config_string) self.upcoming_red_light_pub = rospy.Publisher('/traffic_waypoint', Int32, queue_size=1) self.bridge = CvBridge() self.light_classifier = TLClassifier() self.listener = tf.TransformListener() self.state = TrafficLight.UNKNOWN self.last_state = TrafficLight.UNKNOWN self.last_wp = -1 self.state_count = 0 # get rid of the spin to try to improve latency # rospy.spin() self.loop()