Example #1
0
def main():
    img = read_image('2.jpg') / 255
    img[np.where(img > 0.6)] = 1
    img[np.where(img <= 0.6)] = 0
    connected_domains = get_connected_domains_list(img)
    for index, domain in enumerate(connected_domains):
        write_image('cont' + str(index) + '.jpg', domain * 255)
Example #2
0
def main():
    img = read_image('1.jpg')
    shape = img.shape
    # img = cv2.resize(img, (int(shape[1] / 2), int(shape[0] / 2)))
    color_extractor = ColorExtractor(img)
    res = color_extractor.extract_color()
    write_image('2.jpg', res * 255)
Example #3
0
def main():
    pixel = read_image('txt.jpg') / 255
    bbox = BboxGeneratorV2(pixel, is_corrected=True).gen_bboxes()
    for box in bbox:
        img = read_image('txt.jpg')
        area = get_text_area_from_bbox(img, box)
        write_image('area.jpg', area)
Example #4
0
def main():
    original_pixel = cv2.imread('pxl.jpg')[:, :, 0] / 255
    bbox_gen = ObliqueBBOXGenerator(original_pixel)
    oblique_bbox = bbox_gen.get_oblique_bbox()
    img = read_image('imgs/1.jpg')
    areas = bbox_gen.get_transparent_text_area(img, oblique_bbox)
    for area in areas:
        write_image('ar.jpg', area)
def save_image(image_str, i, file_name):
    if enlarge_radio == 1:
        image_path = TRAINING_DATA_DIR + file_name.replace('.json',
                                                           '') + '.jpg'
    else:
        image_path = TRAINING_DATA_DIR + file_name.replace('.json', '') + \
                     str(enlarge_radio).replace('.', '_') + '.jpg'
    fh = open(image_path, "wb")
    fh.write(base64.b64decode(image_str))
    fh.close()
    img = read_image(image_path)
    shape = img.shape
    img = cv2.resize(
        img, (int(shape[1] * enlarge_radio), int(shape[0] * enlarge_radio)))
    write_image(image_path, img)
Example #6
0
def main():
    # img = to_gray(img)
    # mean_value = img.mean()
    # print(mean_value)

    # paths = get_all_files_under_directory('E:/qianfen_area')
    # for path in paths:
    #     img = read_image(path)
    #     img = enlighten_image_np(111, img)
    #     _, name = os.path.split(path)
    #     write_image('E:/new_area/' + name, img)
    """"""
    img = read_image('1.jpg')

    img = lpls_enlighten(img)
    write_image('2.jpg', img)
def main():
    txt_and_image_paths = 'D:/label_result_2020_3_10/label_result/箱门中文字识别/txt'
    des_line_dir = 'D:/label_result_2020_3_10/label_result/箱门中文字识别/line/'
    paths = get_all_file_from_dir(txt_and_image_paths)
    try:
        for i, p in enumerate(paths):
            if '.jpg' not in p:
                continue
            img_name = os.path.split(p)[1].replace('.jpg', '')
            img = read_image(p)
            txt_path = p.replace('.jpg', '.txt')
            points, is_error = get_points(txt_path)
            if is_error:
                print(p)
            draw_image = get_detect_result(points, img)
            write_image(des_line_dir + img_name + '.jpg', draw_image)
    except Exception as e:
        print(e)
Example #8
0
def char_to_image(char):
    """
    char
    """
    des_dir = combine_file_path('resource/char') + '/'
    for font in FONT_OBJECTS:
        size = font.getsize(char)
        scene_text = Image.new('RGBA', size)
        draw = ImageDraw.Draw(scene_text)
        draw.text((0, 0), char, font=font)
        scene_text = np.array(scene_text)
        start_index = 0
        for i in range(30):
            if scene_text[i, :, :].max() == 0:
                start_index = i
            else:
                break
        new_area = scene_text[start_index:, :, :]
        write_image(des_dir + char + '_' + get_uuid_str() + '.jpg',
                    255 - new_area)
Example #9
0
 def _corrected_bbox(bg, bbox):
     """
     corrected bbox
     """
     distance1 = get_distance(bbox[0], bbox[1])
     distance2 = get_distance(bbox[1], bbox[2])
     if distance2 == 0 or distance1 == 0:
         return None
     if distance1 > distance2:
         line1, line2 = [bbox[0], bbox[3]], [bbox[1], bbox[2]]
         ver_line1 = approaching_horizontal_point0(bg, line1)
         ver_line2 = approaching_horizontal_point2(bg, line2)
         hor_line1 = bbox[0], bbox[1]
         hor_line2 = bbox[2], bbox[3]
         tmp_bg1 = draw_line_from_points(ver_line1, bg, line_pixel=1)
         tmp_bg2 = draw_line_from_points(ver_line2, bg, line_pixel=1)
         tmp_bg3 = draw_line_from_points(hor_line1, bg, line_pixel=1)
         tmp_bg4 = draw_line_from_points(hor_line2, bg, line_pixel=1)
         bg = bg + tmp_bg1 + tmp_bg2 + tmp_bg3 + tmp_bg4
         write_image('tmp_bg.jpg', bg * 255)
         pt1 = cross_point(ver_line1, hor_line1)
         pt2 = cross_point(ver_line1, hor_line2)
         pt3 = cross_point(ver_line2, hor_line1)
         pt4 = cross_point(ver_line2, hor_line2)
     else:
         line1, line2 = [bbox[0], bbox[1]], [bbox[2], bbox[3]]
         hor_line1 = approaching_vertical_point0(bg, line1)
         hor_line2 = approaching_vertical_point2(bg, line2)
         ver_line1 = bbox[0], bbox[3]
         ver_line2 = bbox[1], bbox[2]
         pt1 = cross_point(ver_line1, hor_line1)
         pt2 = cross_point(ver_line1, hor_line2)
         pt3 = cross_point(ver_line2, hor_line1)
         pt4 = cross_point(ver_line2, hor_line2)
     points = resort_points([pt1, pt2, pt3, pt4])
     return points
Example #10
0
 def __corrected_bbox_second_time(self, bg, bbox):
     """
     corrected second time
     """
     center_point = (bbox[0][0] + bbox[2][0]) / 2, (bbox[0][1] +
                                                    bbox[2][1]) / 2
     des_line = np.zeros_like(bg)
     bbox[0], bbox[1] = self.get_new_corrected_point(bg,
                                                     bbox[0],
                                                     bbox[1],
                                                     direction='down')
     bbox[1], bbox[2] = self.get_new_corrected_point(bg,
                                                     bbox[1],
                                                     bbox[2],
                                                     direction='left')
     bbox[2], bbox[3] = self.get_new_corrected_point(bg,
                                                     bbox[2],
                                                     bbox[3],
                                                     direction='up')
     bbox[3], bbox[1] = self.get_new_corrected_point(bg,
                                                     bbox[3],
                                                     bbox[0],
                                                     direction='right')
     des_line = draw_line_from_points([bbox[0], bbox[1]],
                                      des_line,
                                      line_pixel=1)
     des_line = draw_line_from_points([bbox[1], bbox[2]],
                                      des_line,
                                      line_pixel=1)
     des_line = draw_line_from_points([bbox[2], bbox[3]],
                                      des_line,
                                      line_pixel=1)
     des_line = draw_line_from_points([bbox[3], bbox[0]],
                                      des_line,
                                      line_pixel=1)
     write_image('des_line.jpg', des_line * 255)
Example #11
0
def approaching_horizontal_point2(bg, line1):
    """

    """
    center_point = (line1[0][0] + line1[1][0]) / 2 + 5, (line1[0][1] +
                                                         line1[1][1]) / 2
    pt1, pt2 = line1
    original_pt1, original_pt2 = copy.deepcopy(pt1), copy.deepcopy(pt2)
    original_pt1 = original_pt1[0] + 2, original_pt1[1]
    original_pt2 = original_pt2[0] + 2, original_pt2[1]
    pt1, pt2 = original_pt1, center_point
    while True:
        pt1, pt2 = translation_line_first_side(pt1, pt2, direction='left')
        tmp_bg = np.zeros_like(bg)
        tmp_bg = draw_line_from_points([pt1, pt2], tmp_bg, line_pixel=1)
        tmp_bg = tmp_bg + bg
        write_image('tmp_bg.jpg', tmp_bg * 255)
        max_value = np.max(tmp_bg)
        if max_value > 1:
            location = np.where(tmp_bg > 1)
            first_location, last_location = _sort_location(location)
            first_point = first_location
            break
    pt1, pt2 = center_point, original_pt2
    while True:
        pt1, pt2 = translation_line_second_side(pt1, pt2, direction='left')
        tmp_bg = np.zeros_like(bg)
        tmp_bg = draw_line_from_points([pt1, pt2], tmp_bg, line_pixel=1)
        tmp_bg = tmp_bg + bg
        write_image('tmp_bg.jpg', tmp_bg * 255)
        max_value = np.max(tmp_bg)
        if max_value > 1:
            location = np.where(tmp_bg > 1)
            first_location, last_location = _sort_location(location)
            second_point = first_location
            break
    pt1, pt2 = first_point, second_point
    while True:
        pt1, pt2 = translation_line(pt1, pt2, direction='right')
        tmp_bg = np.zeros_like(bg)
        tmp_bg = draw_line_from_points([pt1, pt2], tmp_bg, line_pixel=1)
        tmp_bg = tmp_bg + bg
        write_image('tmp_bg.jpg', tmp_bg * 255)
        max_value = np.max(tmp_bg)
        if max_value <= 1:
            return pt1, pt2
Example #12
0
def main():
    points = [[642, 592], [724, 658], [724, 692], [652, 628]]
    img = read_image('imgs/1.jpg')
    res = draw_points(points, img)
    write_image('imgs/ll.jpg', res)
Example #13
0
def main():
    mask = read_image('text.jpg') / 255
    gap = read_image('gap.jpg') / 255
    new_mask = mask * gap * 255
    write_image('new_mask.jpg', new_mask)
Example #14
0
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name:     tmp
   Description :
   Author :       'li'
   date:          2020/8/11
-------------------------------------------------
   Change Activity:
                   2020/8/11:
-------------------------------------------------
"""
import numpy as np
import cv2

from llib.cv_utility.image_opt_utility import write_image

file_name = "1.jpg"
img = cv2.imread(file_name)

# gray = np.float32(gray)
# rocg = Recognise.Recognise()
image = np.power(img / 255.0, 0.7)
# image = rocg.gamma_rectify(gray, 0.4)
write_image('33.jpg', image * 255)
Example #15
0
# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name:     get_all_file_path
   Description :
   Author :       'li'
   date:          2020/1/18
-------------------------------------------------
   Change Activity:
                   2020/1/18:
-------------------------------------------------
"""
import os

from llib.cv_utility.image_opt_utility import read_image, write_image
from utility.file_path_utility import get_all_files_under_directory

img_dir = 'J:/BaiduNetdiskDownload/0506'
des_path = 'J:/BaiduNetdiskDownload/plate_recognize/img/'
paths = get_all_files_under_directory(img_dir)
for path in paths:
    _, name = os.path.split(path)
    image = read_image(path)
    write_image(des_path + name, image)
Example #16
0
def main():
    training_data = gen_random_words()
    for img, label in training_data:
        write_image(label + '.jpg', img)
Example #17
0
    def get_new_corrected_point(bg, pt1, pt2, direction='down'):
        """
        get new corrected points
        """
        original_pt1, original_pt2 = copy.deepcopy(pt1), copy.deepcopy(pt2)
        is_move_points = False

        while True:
            last_pt1, last_pt2 = copy.deepcopy(pt1), copy.deepcopy(pt2)
            pt1, pt2 = translation_line(pt1, pt2, direction=direction)
            tmp_bg = np.zeros_like(bg)
            tmp_bg = draw_line_from_points([pt1, pt2], tmp_bg, line_pixel=1)
            tmp_bg = tmp_bg + bg
            max_value = np.max(tmp_bg)
            if max_value <= 1:
                is_move_points = True
            else:
                break
        write_image('tmp_bg.jpg', tmp_bg * 255)
        if is_move_points:
            pt1, pt2 = last_pt1, last_pt2
            original_pt1, original_pt2 = copy.deepcopy(pt1), copy.deepcopy(pt2)
        """first side"""
        while True:
            last_pt1, last_pt2 = copy.deepcopy(original_pt1), copy.deepcopy(
                original_pt2)
            pt1, pt2 = translation_line_first_side(pt1,
                                                   pt2,
                                                   direction=direction)
            tmp_bg = np.zeros_like(bg)
            tmp_bg = draw_line_from_points([pt1, pt2], tmp_bg, line_pixel=1)
            tmp_bg = tmp_bg + bg
            max_value = np.max(tmp_bg)
            if max_value <= 1:
                is_move_points = True
            else:
                break
        write_image('tmp_bg.jpg', tmp_bg * 255)
        final_pt1, final_pt2 = None, None
        if is_move_points:
            final_pt1 = last_pt1
        """second side"""
        while True:
            last_pt1, last_pt2 = copy.deepcopy(original_pt1), copy.deepcopy(
                original_pt2)
            pt1, pt2 = translation_line_second_side(pt1,
                                                    pt2,
                                                    direction=direction)
            tmp_bg = np.zeros_like(bg)
            tmp_bg = draw_line_from_points([pt1, pt2], tmp_bg, line_pixel=1)
            tmp_bg = tmp_bg + bg
            max_value = np.max(tmp_bg)
            if max_value <= 1:
                is_move_points = True
            else:
                break
        if is_move_points:
            final_pt2 = last_pt2
        write_image('tmp_bg.jpg', tmp_bg * 255)
        if is_move_points:
            tmp_bg = draw_line_from_points([final_pt1, final_pt2],
                                           tmp_bg,
                                           line_pixel=1)
            tmp_bg = tmp_bg + bg
            write_image('tmp_bg.jpg', tmp_bg * 255)
            return final_pt1, final_pt2
        return original_pt1, original_pt2