예제 #1
0
def seg_horozontal(label, img):
    gray_img = to_gray(img)
    text_array = get_horizontal_seg_array(gray_img)
    size = len(text_array)
    if len(label) != size:
        return
    tmp_img = img[:, 0:int((text_array[1][-1] + text_array[2][0]) / 2), :]
    cv2.imwrite(def_path + label[:2] + '-' + str(uuid.uuid4()) + '.jpg', tmp_img)
    tmp_img = img[:, int((text_array[1][-1] + text_array[2][0]) / 2):, :]
    cv2.imwrite(def_path + label[2:] + '-' + str(uuid.uuid4()) + '.jpg', tmp_img)
예제 #2
0
def seg_vertical(label, img):
    gray_img = to_gray(img)
    text_array = get_vertical_seg_array(gray_img)
    size = len(text_array)
    if len(label) != size:
        return
    tmp_img = img[0:int((text_array[0][-1] + text_array[1][0]) / 2), :, :]
    cv2.imwrite(def_path + label[:1] + '-' + str(uuid.uuid4()) + '.jpg', tmp_img)
    tmp_img = img[int((text_array[0][-1] + text_array[1][0]) / 2):, :, :]
    cv2.imwrite(def_path + label[1:] + '-' + str(uuid.uuid4()) + '.jpg', tmp_img)
예제 #3
0
def seg_vertical(label, img):
    gray_img = to_gray(img)
    text_array = get_vertical_seg_array(gray_img)
    size = len(text_array)
    if len(label) != size:
        return
    for index in range(size):
        area = text_array[index]
        if index == 0:
            next_area = text_array[index + 1]
            tmp_img = img[0:int((area[-1] + next_area[0]) / 2), :]

        elif index == size - 1:
            tmp_img = img[area[0]:, :]
        else:
            next_area = text_array[index + 1]
            last_area = text_array[index - 1]
            tmp_img = img[int((last_area[-1] + area[0]) /
                              2):int((area[-1] + next_area[0]) / 2), :]
        cv2.imwrite(def_path + label[index] + '-' + str(uuid.uuid4()) + '.jpg',
                    tmp_img)