コード例 #1
0
    def __init__(self):
        self.node_name = "Line Detector"
 
        self.image_size = rospy.get_param('~img_size')
        self.top_cutoff = rospy.get_param('~top_cutoff')
        
        self.bridge = CvBridge()
        self.detector = LineDetector()

        self.detector.hsv_white1 = np.array(rospy.get_param('~hsv_white1'))
        self.detector.hsv_white2 = np.array(rospy.get_param('~hsv_white2'))
        self.detector.hsv_yellow1 = np.array(rospy.get_param('~hsv_yellow1'))
        self.detector.hsv_yellow2 = np.array(rospy.get_param('~hsv_yellow2'))
        self.detector.hsv_red1 = np.array(rospy.get_param('~hsv_red1'))
        self.detector.hsv_red2 = np.array(rospy.get_param('~hsv_red2'))
        self.detector.hsv_red3 = np.array(rospy.get_param('~hsv_red3'))
        self.detector.hsv_red4 = np.array(rospy.get_param('~hsv_red4'))

        self.detector.dilation_kernel_size = rospy.get_param('~dilation_kernel_size')
        self.detector.canny_thresholds = rospy.get_param('~canny_thresholds')
        self.detector.hough_min_line_length = rospy.get_param('~hough_min_line_length')
        self.detector.hough_max_line_gap    = rospy.get_param('~hough_max_line_gap')
        self.detector.hough_threshold = rospy.get_param('~hough_threshold')
       
        self.sub_image = rospy.Subscriber("~image", CompressedImage, self.processImage)
        self.pub_lines = rospy.Publisher("~segment_list", SegmentList, queue_size=1)
        self.pub_image = rospy.Publisher("~image_with_lines", Image, queue_size=1)
コード例 #2
0
    def __init__(self):
        self.node_name = "Line Detector"

        # Thread lock
        self.thread_lock = threading.Lock()

        # Constructor of line detector
        self.bridge = CvBridge()
        self.detector = LineDetector()
        self.wb = WhiteBalance()
        self.flag_wb_ref = False

        # Parameters
        self.flag_wb = rospy.get_param('~white_balance')

        self.image_size = rospy.get_param('~img_size')
        self.top_cutoff = rospy.get_param('~top_cutoff')

        self.detector.hsv_white1 = np.array(rospy.get_param('~hsv_white1'))
        self.detector.hsv_white2 = np.array(rospy.get_param('~hsv_white2'))
        self.detector.hsv_yellow1 = np.array(rospy.get_param('~hsv_yellow1'))
        self.detector.hsv_yellow2 = np.array(rospy.get_param('~hsv_yellow2'))
        self.detector.hsv_red1 = np.array(rospy.get_param('~hsv_red1'))
        self.detector.hsv_red2 = np.array(rospy.get_param('~hsv_red2'))
        self.detector.hsv_red3 = np.array(rospy.get_param('~hsv_red3'))
        self.detector.hsv_red4 = np.array(rospy.get_param('~hsv_red4'))

        self.detector.dilation_kernel_size = rospy.get_param(
            '~dilation_kernel_size')
        self.detector.canny_thresholds = rospy.get_param('~canny_thresholds')
        self.detector.hough_min_line_length = rospy.get_param(
            '~hough_min_line_length')
        self.detector.hough_max_line_gap = rospy.get_param(
            '~hough_max_line_gap')
        self.detector.hough_threshold = rospy.get_param('~hough_threshold')

        # Publishers
        self.pub_lines = rospy.Publisher("~segment_list",
                                         SegmentList,
                                         queue_size=1)
        self.pub_image = rospy.Publisher("~image_with_lines",
                                         Image,
                                         queue_size=1)

        # Verbose option
        self.verbose = rospy.get_param('~verbose')
        if self.verbose:
            self.toc_pre = rospy.get_time()

        # Subscribers
        self.sub_image = rospy.Subscriber("~image",
                                          CompressedImage,
                                          self.cbImage,
                                          queue_size=1)
        rospy.loginfo("[%s] Initialized." % (self.node_name))
コード例 #3
0
def main():
    line_finder = LineDetector(**settings)
    if args.file_.split('.')[-1] == 'jpg':
        img = mpimg.imread(args.path + args.file_)
        output_img = line_finder.forward(img)
        plt.imshow(output_img)
        plt.show()
    elif args.file_.split('.')[-1] == 'mp4':
        white_output = 'test_videos_output/output_video.mp4'
        clip1 = VideoFileClip(args.path + args.file_).subclip(0, args.subclip)
        white_clip = clip1.fl_image(line_finder.forward)
        white_clip.write_videofile(white_output, audio=False)
    else:
        print('Error {}: Not supported type.'.format(
            args.file_.split('.')[-1]))
        quit()
コード例 #4
0
    def __init__(self):
        self.node_name = rospy.get_name()
        rospy.loginfo("[%s] Initializing......" % (self.node_name))

        self.bridge = CvBridge()
        self.cv_image = None
        self.detector = LineDetector()
        self.visualization = True
        self.size = (320, 240)
        self.pid_enabled = False
        self.base_speed = 50
        # self.car = CarDriver()
        # self.config_file = os.path.dirname(os.path.abspath(__file__)) + "/default.yaml"
        self.image_msg = None
        self.lost_count = 0
        self.line_msg = GetLineDetectionResponse()
        self.pub_detections = rospy.Publisher("~image_color",
                                              CompressedImage,
                                              queue_size=1)
        self.pub_line_detection = rospy.Publisher("~line_detection",
                                                  LineDetection,
                                                  queue_size=1)

        self.detect_line_srv = rospy.Service('~detect_line', GetLineDetection,
                                             self.cbGetLineDetection)
        self.set_color_srv = rospy.Service('~set_color_threshold',
                                           SetColorThreshold,
                                           self.cbSetColorThreshold)
        self.get_color_srv = rospy.Service('~get_color_threshold',
                                           GetColorThreshold,
                                           self.cbGetColorThreshold)
        self.set_color_list_srv = rospy.Service('~get_color_list', GetStrings,
                                                self.cbGetColorList)
        # self.pid_set_enable_srv = rospy.Service('~pid_set_enable', SetInt32, self.cbPidSetEnable)
        # self.sub_image = rospy.Subscriber("~image_raw", Image, self.cbImg ,queue_size=1)
        self.sub_image = rospy.Subscriber("~image_raw/compressed",
                                          CompressedImage,
                                          self.cbImg,
                                          queue_size=1)

        # rospy.loginfo("[%s] wait_for_service : camera_get_frame..." % (self.node_name))
        # rospy.wait_for_service('~camera_get_frame')
        # self.get_frame = rospy.ServiceProxy('~camera_get_frame', GetFrame)
        rospy.loginfo("[%s] Initialized." % (self.node_name))
コード例 #5
0
ファイル: line-follower.py プロジェクト: iseikr/line-follower
# Note for vz:
# vz < 0 => ascend
# vz > 0 => descend

# UP = -0.5
# DOWN = 0.5

UP = 0
DOWN = 0

PRECISION = 3
YAW_CONTROL = True
ABS_MAX_TURNING_ANGLE = 75

ld = LineDetector(PRECISION)

arm_and_takeoff(1.5)

print("!!!!!!!!!!! MOVING START !!!!!!!!!")

while True:
    # getTurnDir returns
    dir = ld.getTurnDir()
    print("getTurnDir returns %d" % dir)

    # If there is no line, land the vehicle
    if dir == (PRECISION + 1):
        break

    # If YAW_CONTROL is true, it is possible to trace curves.
コード例 #6
0
    def __init__(self, node_name):
        # Initialize the DTROS parent class
        super(LineDetectorNode, self).__init__(node_name=node_name,
                                               node_type=NodeType.PERCEPTION)

        # Define parameters
        self._line_detector_parameters = rospy.get_param(
            "~line_detector_parameters", None)
        self._colors = rospy.get_param("~colors", None)
        self._img_size = rospy.get_param("~img_size", None)
        self._top_cutoff = rospy.get_param("~top_cutoff", None)

        self.bridge = CvBridge()

        # The thresholds to be used for AntiInstagram color correction
        self.ai_thresholds_received = False
        self.anti_instagram_thresholds = dict()
        self.ai = AntiInstagram()

        # This holds the colormaps for the debug/ranges images after they are computed once
        self.colormaps = dict()

        # Create a new LineDetector object with the parameters from the Parameter Server / config file
        self.detector = LineDetector(**self._line_detector_parameters)
        # Update the color ranges objects
        self.color_ranges = {
            color: ColorRange.fromDict(d)
            for color, d in list(self._colors.items())
        }

        # Publishers
        self.pub_lines = rospy.Publisher("~segment_list",
                                         SegmentList,
                                         queue_size=1,
                                         dt_topic_type=TopicType.PERCEPTION)
        self.pub_d_segments = rospy.Publisher("~debug/segments/compressed",
                                              CompressedImage,
                                              queue_size=1,
                                              dt_topic_type=TopicType.DEBUG)
        self.pub_d_edges = rospy.Publisher("~debug/edges/compressed",
                                           CompressedImage,
                                           queue_size=1,
                                           dt_topic_type=TopicType.DEBUG)
        self.pub_d_maps = rospy.Publisher("~debug/maps/compressed",
                                          CompressedImage,
                                          queue_size=1,
                                          dt_topic_type=TopicType.DEBUG)
        # these are not compressed because compression adds undesired blur
        self.pub_d_ranges_HS = rospy.Publisher("~debug/ranges_HS",
                                               Image,
                                               queue_size=1,
                                               dt_topic_type=TopicType.DEBUG)
        self.pub_d_ranges_SV = rospy.Publisher("~debug/ranges_SV",
                                               Image,
                                               queue_size=1,
                                               dt_topic_type=TopicType.DEBUG)
        self.pub_d_ranges_HV = rospy.Publisher("~debug/ranges_HV",
                                               Image,
                                               queue_size=1,
                                               dt_topic_type=TopicType.DEBUG)

        # Subscribers
        self.sub_image = rospy.Subscriber("~image/compressed",
                                          CompressedImage,
                                          self.image_cb,
                                          buff_size=10000000,
                                          queue_size=1)

        self.sub_thresholds = rospy.Subscriber("~thresholds",
                                               AntiInstagramThresholds,
                                               self.thresholds_cb,
                                               queue_size=1)
コード例 #7
0
        if self.cv_image is None:
            print('image msg received')
        self.cv_image = self.bridge.imgmsg_to_cv2(image_msg,
                                                  desired_encoding="bgr8")

    def getImage(self):
        return self.cv_image


# print(__name__)
if __name__ == '__main__':
    import cv2
    import time
    from line_detector import LineDetector

    detector = LineDetector()

    subscriber = RosImageSubscriber()
    count = 1
    start = time.time()
    while True:
        # image_frame = subscriber.get_frame(GetFrameRequest())
        # cv_image = subscriber.bridge.imgmsg_to_cv2(image_frame.image, desired_encoding="bgr8")
        cv_image = subscriber.cv_image
        rect_image = cv_image

        detection, image_color = detector.detect_hsv(rect_image,
                                                     detector.colors[u'黄色'])
        count = count + 1
        if (count > 100):
            end = time.time()
コード例 #8
0
 def __init__(self):
     self.line_detector = LineDetector()
     self.thresh_image = None