Пример #1
0
def preprocess_plate_without_croping(img_orig):
    """
    some preparation to find False/True plate (it works)
    """
    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(3, 3))
    im = clahe.apply(cv2.cvtColor(img_orig, cv2.COLOR_BGR2GRAY))

    img_thresh = half_thresh(im)
    img_thresh = kray_fill(img_thresh, full_filling=True)

    list_of_psb_chr, number_of_chars, _ = DetectChars.find_psbl_chr(
        img_thresh, [70, 3, 15, 0.1, 1.5])
    if number_of_chars > 7:
        img_thresh = replace_last_first_symb(img_thresh, list_of_psb_chr,
                                             number_of_chars)
        img_thresh = del_blue(img_orig, list_of_psb_chr, img_thresh)

    list_of_psb_chr, _, _ = DetectChars.find_psbl_chr(img_thresh,
                                                      [70, 3, 15, 0.1, 1.5])

    img_thresh = draw_top_line(list_of_psb_chr, img_thresh)
    img_thresh = draw_btm_line(list_of_psb_chr, img_thresh)

    list_of_psb_chr, number_of_chars, none_char = DetectChars.find_psbl_chr(
        img_thresh, [70, 3, 15, 0.1, 1.5])
    if number_of_chars >= 2:
        img_thresh = separate_sticked(img_thresh, list_of_psb_chr, none_char)

    _, _, none_char = DetectChars.find_psbl_chr(img_thresh,
                                                [100, 4, 15, 0.15, 1])
    img_thresh = matching_broken_chars(img_thresh, none_char)

    return img_thresh
Пример #2
0
def prepare_to_hist_clcl(im):
    """
    preparations  to left-right edge filling by histogram value
    """
    img_thresh = half_thresh(im)
    img_thresh = kray_fill(img_thresh, full_left_right=False)

    list_of_psb_chr, nmbr_of_chrs, none_chars = DetectChars.find_psbl_chr(
        img_thresh, [70, 3, 15, 0.1, 1.5])
    if nmbr_of_chrs > 2:
        img_thresh = separate_sticked(img_thresh, list_of_psb_chr, none_chars)
    list_of_psb_chr, _, _ = DetectChars.find_psbl_chr(img_thresh,
                                                      [70, 3, 15, 0.1, 1.5])
    return list_of_psb_chr
Пример #3
0
def find_most_likely_plts(list_of_psb_plates, number_chars_to_be_valid,
                          explore_btm, psbl_char_params, explr_area):
    """
    the idea of function is do some tests to find the most truthful plate
    in falsePlates, preprocess_for_scene delete more than 20% of plate's image on one of edges
    """
    dif_list = []
    for image in list_of_psb_plates:

        image = image.img_plate
        image = Preprocess.preprocess_plate_without_croping(image)

        list_of_psb_chars, number_of_chars, _ = DetectChars.find_psbl_chr(
            image, psbl_char_params, explr_area)

        if number_of_chars < number_chars_to_be_valid:  # plates with small nmbr of symbols is untruth
            dif_list.append(1000)  # add some value bigger than psbl differ
            continue

        if explore_btm:
            dif_list = explore_btms(list_of_psb_chars, dif_list)
        else:
            dif_list.append(0)

    return dif_list
Пример #4
0
def preprocess_for_plate(img_orig):
    img_bl = cv2.cvtColor(img_orig, cv2.COLOR_BGR2GRAY)
    img_grayscale = copy.deepcopy(img_bl)
    clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(3, 3))
    img_clashed = clahe.apply(img_bl)

    # find chars on image
    #######################################################################
    list_of_psb_chr = prepare_to_hist_clcl(img_clashed)
    img_thresh, img_grayscale = histogram_kray_fill(img_clashed, img_grayscale,
                                                    list_of_psb_chr)

    img_thresh = half_thresh(img_thresh)
    img_thresh = kray_fill(img_thresh)

    list_of_psb_chr, _, _ = DetectChars.find_psbl_chr(img_thresh,
                                                      [70, 3, 15, 0.1, 1.5])
    img_tmp = img_thresh.copy()
    img_tmp = draw_top_line(list_of_psb_chr, img_tmp)
    img_tmp = draw_btm_line(list_of_psb_chr, img_tmp)

    list_of_psb_chr, number_of_chars, _ = DetectChars.find_psbl_chr(
        img_tmp, [70, 3, 15, 0.1, 1.5])
    if number_of_chars > 7:
        img_thresh = replace_last_first_symb(img_thresh, list_of_psb_chr,
                                             number_of_chars)
        img_thresh = del_blue(img_orig, list_of_psb_chr, img_thresh)

    list_of_psb_chr, _, _ = DetectChars.find_psbl_chr(img_thresh,
                                                      [70, 3, 15, 0.1, 1.5])
    img_thresh = draw_top_line(list_of_psb_chr, img_thresh)
    img_thresh = draw_btm_line(list_of_psb_chr, img_thresh)

    list_of_psb_chr, nmbr_of_chrs, none_chars = DetectChars.find_psbl_chr(
        img_thresh, [70, 3, 15, 0.1, 1.5])
    if nmbr_of_chrs >= 2:
        img_thresh = separate_sticked(img_thresh, list_of_psb_chr, none_chars)

    _, _, none_chars = DetectChars.find_psbl_chr(img_thresh,
                                                 [100, 4, 15, 0.15, 1])
    img_thresh = matching_broken_chars(img_thresh, none_chars)
    ##################################################################

    # do two new image from grayscale, to further finding symbols and to recognize chars
    #######################################################################
    list_of_psb_chr, _, _ = DetectChars.find_psbl_chr(img_thresh,
                                                      [70, 3, 15, 0.1, 1.7])
    height, width = img_thresh.shape
    img_thresh = np.zeros((height, width), np.uint8)
    img_for_rcgnz = np.zeros((height, width), np.uint8)

    for i in list_of_psb_chr:
        x1 = np.max([i.pos_x - 2, 0])
        y2 = np.min([i.pos_y + i.height + 1, height - 1])
        x2 = np.min([i.pos_x + i.width + 2, width - 1])
        y1 = np.max([i.pos_y - 1, 0])

        roi = img_grayscale[:, x1:x2]

        _, img_for_rcgnz[y1:y2, x1:x2] = cv2.threshold(
            roi[y1:y2, :], 2, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)
        _, img_thresh[y1:y2, x1:x2] = cv2.threshold(
            roi[y1:y2, :], 2, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)

    list_of_psb_chr, number_of_chars, _ = DetectChars.find_psbl_chr(
        img_tmp, [70, 3, 15, 0.1, 1.5])
    if number_of_chars > 7:
        img_thresh = replace_last_first_symb(img_thresh, list_of_psb_chr,
                                             number_of_chars)
        img_thresh = del_blue(img_orig, list_of_psb_chr, img_thresh)

    list_of_psb_chr, nmbr_of_chrs, none_chars = DetectChars.find_psbl_chr(
        img_thresh, [70, 3, 15, 0.1, 1.5])
    if nmbr_of_chrs > 0:
        img_thresh = rotate(img_thresh, list_of_psb_chr)
        img_for_rcgnz = rotate(img_for_rcgnz, list_of_psb_chr)

    _, img_thresh = cv2.threshold(img_thresh, 200, 255, cv2.THRESH_BINARY)

    list_of_psb_chr, nmbr_of_chrs, none_chars = DetectChars.find_psbl_chr(
        img_thresh, [70, 3, 15, 0.1, 1.5])

    img_thresh = draw_top_line(list_of_psb_chr, img_thresh)
    img_thresh = draw_btm_line(list_of_psb_chr, img_thresh)

    list_of_psb_chr, nmbr_of_chrs, none_chars = DetectChars.find_psbl_chr(
        img_thresh, [100, 4, 15, 0.15, 1])
    if nmbr_of_chrs >= 2:
        img_thresh = separate_sticked(img_thresh, list_of_psb_chr, none_chars)

    list_of_psb_chr, nmbr_of_chrs, none_chars = DetectChars.find_psbl_chr(
        img_thresh, [100, 4, 15, 0.15, 1])
    img_thresh = matching_broken_chars(img_thresh, none_chars)

    kernel = np.ones((3, 3), np.uint8)
    img_for_rcgnz = cv2.erode(img_for_rcgnz, kernel)

    return img_grayscale, img_thresh, img_for_rcgnz