line_detector package

The line_detector package provides the tools for extracting colored line segments from an image and a ROS node that implements that. It has been designed to be a part of the lane localization pipeline. Consists of the ROS node nodes.LineDetectorNode and the line_detector library.

LineDetectorNode

class LineDetectorNode(node_name)

The LineDetectorNode is responsible for detecting the line white, yellow and red line segment in an image and is used for lane localization.

Upon receiving an image, this node reduces its resolution, cuts off the top part so that only the road-containing part of the image is left, extracts the white, red, and yellow segments and publishes them. The main functionality of this node is implemented in the line_detector.LineDetector class.

The performance of this node can be very sensitive to its configuration parameters. Therefore, it also provides a number of debug topics which can be used for fine-tuning these parameters. These configuration parameters can be changed dynamically while the node is running via rosparam set commands.

Parameters

node_name (str) – a unique, descriptive name for the node that ROS will use

Configuration:

~line_detector_parameters (dict): A dictionary with the parameters for the detector. The full list can be found in line_detector.LineDetector. ~colors (dict): A dictionary of colors and color ranges to be detected in the image. The keys (color names) should match the ones in the Segment message definition, otherwise an exception will be thrown! See the config directory in the node code for the default ranges. ~img_size (list of int): The desired downsized resolution of the image. Lower resolution would result in faster detection but lower performance, default is [120,160] ~top_cutoff (int): The number of rows to be removed from the top of the image _after_ resizing, default is 40

Subscriber:

~camera_node/image/compressed (sensor_msgs.msg.CompressedImage): The camera images ~anti_instagram_node/thresholds(duckietown_msgs.msg.AntiInstagramThresholds): The thresholds to do color correction

Publishers:

~segment_list (duckietown_msgs.msg.SegmentList): A list of the detected segments. Each segment is an duckietown_msgs.msg.Segment message ~debug/segments/compressed (sensor_msgs.msg.CompressedImage): Debug topic with the segments drawn on the input image ~debug/edges/compressed (sensor_msgs.msg.CompressedImage): Debug topic with the Canny edges drawn on the input image ~debug/maps/compressed (sensor_msgs.msg.CompressedImage): Debug topic with the regions falling in each color range drawn on the input image ~debug/ranges_HS (sensor_msgs.msg.Image): Debug topic with a histogram of the colors in the input image and the color ranges, Hue-Saturation projection ~debug/ranges_SV (sensor_msgs.msg.Image): Debug topic with a histogram of the colors in the input image and the color ranges, Saturation-Value projection ~debug/ranges_HV (sensor_msgs.msg.Image): Debug topic with a histogram of the colors in the input image and the color ranges, Hue-Value projection

Included libraries

line_detector

The line_detector library packages classes and tools for handling line section extraction from images. The main functionality is in the LineDetector class. Detections is the output data class for the results of a call to LineDetector, and ColorRange is used to specify the colour ranges in which LineDetector is looking for line segments.

There are two plotting utilities also included: plotMaps() and plotSegments()

class Detections(lines, normals, centers, map)

This is a data class that can be used to store the results of the line detection procedure performed by LineDetector.

class ColorRange(low, high)

The Color Range class holds one or multiple color ranges. It can easily be generated with the fromDict() class method and extends the OpenCV’s inRange method to work with multiple color ranges.

All colours must be given in HSV space.

Parameters
  • low (numpy array) – An Nx3 array with the low ends of N colour ranges.

  • high (numpy array) – An Nx3 array with the high ends of N colour ranges.

class LineDetector(canny_thresholds=[80, 200], canny_aperture_size=3, dilation_kernel_size=3, hough_threshold=2, hough_min_line_length=3, hough_max_line_gap=1)

The Line Detector can be used to extract line segments from a particular color range in an image. It combines edge detection, color filtering, and line segment extraction.

This class was created for the goal of extracting the white, yellow, and red lines in the Duckiebot’s camera stream as part of the lane localization pipeline. It is setup in a way that allows efficient detection of line segments in different color ranges.

In order to process an image, first the setImage() method must be called. In makes an internal copy of the image, converts it to HSV color space, which is much better for color segmentation, and applies Canny edge detection.

Then, to do the actual line segment extraction, a call to detectLines() with a ColorRange object must be made. Multiple such calls with different colour ranges can be made and these will reuse the precomputed HSV image and Canny edges.

Parameters
  • canny_thresholds (list of int) – a list with two entries that specify the thresholds for the hysteresis procedure, details here, default is [80, 200]

  • canny_aperture_size (int) – aperture size for a Sobel operator, details here, default is 3

  • dilation_kernel_size (int) – kernel size for the dilation operation which fills in the gaps in the color filter result, default is 3

  • hough_threshold (int) – Accumulator threshold parameter. Only those lines are returned that get enough votes, details here, default is 2

  • hough_min_line_length (int) – Minimum line length. Line segments shorter than that are rejected, details here, default is 3

  • hough_max_line_gap (int) – Maximum allowed gap between points on the same line to link them, details here, default is 1

plotMaps(image, detections)

Draws a set of color filter maps (the part of the images falling in a given color range) on an image.

Parameters
  • image (numpy array) – an image

  • detections (dict) – a dictionary that has keys ColorRange and values Detection

Returns

the image with the line segments drawn on top of it.

Return type

numpy array

plotSegments(image, detections)

Draws a set of line segment detections on an image.

Parameters
  • image (numpy array) – an image

  • detections (dict) – a dictionary that has keys ColorRange and values Detection

Returns

the image with the line segments drawn on top of it.

Return type

numpy array