def get_car_coordinates(car_detector, image, config, draw=False, path=True):

    car_detector_height = car_detector.net_info['height']
    car_image_loader = prep_image(image, car_detector_height, path=path)
    car_results = detect_car(car_image_loader, car_detector, config, draw=draw)
    car_results = list(
        filter(lambda result: result[2] in config.car_labels, car_results))
    if car_results:
        return car_results, car_image_loader[1]
    return None, None
def detect_cars(image_path, draw=False):
    """
    Detect car from an image
    :param draw:
    :param image_path: string -- path to the image
    :return: list or None -- car coordinates or None
    """
    car_image_loader = prep_image(image_path, car_detector_height, path=True)
    car_results = detection(car_image_loader, car_detector, flags, draw=draw, detector='cars')
    car_results = list(filter(lambda result: result[2] in CAR_LABELS, car_results))
    if not car_results == 0:
        return car_results, car_image_loader[1]
    return None, None
def detect_character_default(_alpr_coordinates, _image, draw=False):
    """
    Detect alpr from image and car coordinates
    :param draw:
    :param _alpr_coordinates: list -- e.g [(x0, y0), (x1, y1), 2]
    :param _image: numpy array -- image array
    :return: list or None -- alpr_coordinates or None if not found
    """
    top_left, bottom_right = _alpr_coordinates[0][0:2]
    cropped_image = _image[top_left[1]:bottom_right[1], top_left[0]: bottom_right[0]]
    alpr_image_loader = prep_image(cropped_image, character_detector_height, path=False)
    character_coordinates = detection(alpr_image_loader, character_detector, flags, draw=draw, detector='characters')
    if not character_coordinates == 0:
        return character_coordinates, cropped_image
    return None, None
Exemplo n.º 4
0
def load_images(args, path=None):
    """
    Load images and create output folder
    :param path:
    :param args: program parameters
    :return: image
    """
    # Detection phase
    if path:
        image = path
    else:
        image = os.path.join(os.getcwd(), args.image)
    image_resolution = int(args.resolution)
    if not os.path.exists(args.out_folder):
        os.makedirs(args.out_folder)

    return prep_image(image, image_resolution)
def get_character_coordinates(characters_detector,
                              _alpr_coordinates,
                              alpr_image,
                              config,
                              draw=False):
    characters_detector_height = characters_detector.net_info['height']

    alpr_image_loader = prep_image(alpr_image,
                                   characters_detector_height,
                                   path=False)
    character_coordinates = detect_character(alpr_image_loader,
                                             characters_detector,
                                             config=config,
                                             draw=draw)
    if not character_coordinates == 0:
        return character_coordinates, alpr_image
    return None, None
def get_alpr_coordinates(alpr_detector,
                         _car_coordinates,
                         car_image,
                         config,
                         draw=False,
                         first=True):

    alpr_detector_height = alpr_detector.net_info['height']
    alpr_image_loader = prep_image(car_image, alpr_detector_height, path=False)
    alpr_coordinates = detect_alpr(alpr_image_loader,
                                   alpr_detector,
                                   config,
                                   draw=draw)
    if alpr_coordinates:
        if first:
            return alpr_coordinates[0], car_image
        return alpr_coordinates, car_image
    return None, None
Exemplo n.º 7
0
def detect_alpr_default(_car_coordinates, _image, draw=True):
    """
    Detect alpr from image and car coordinates
    :param draw:
    :param _car_coordinates: list -- e.g [(x0, y0), (x1, y1), 2]
    :param _image: numpy array -- image array
    :return: list or None -- alpr_coordinates or None if not found
    """
    top_left, bottom_right = _car_coordinates[0:2]
    cropped_image = _image[top_left[1]:bottom_right[1],
                           top_left[0]:bottom_right[0]]
    alpr_image_loader = prep_image(cropped_image,
                                   alpr_detector_height,
                                   path=False)
    alpr_coordinates = detection(alpr_image_loader,
                                 alpr_detector,
                                 flags,
                                 draw=draw,
                                 detector='alpr')
    if not alpr_coordinates == 0:
        alpr_coordinates = normalize_alpr(_car_coordinates, alpr_coordinates)
        return alpr_coordinates
    return None
Exemplo n.º 8
0
def single_image(_image_path):
    image_loader = prep_image(_image_path, height, path=True)
    results = detection(image_loader, car_detector, flags, draw=False)
    if not results == 0:
        return list(filter(lambda result: result[2] in CAR_LABELS, results))
    return None