Ejemplo n.º 1
0
def train():
    mask_model = MaskModel()
    mask_model.build()
    input_images = mask_model.input_images
    output = mask_model.output
    output_shape = output.shape.dims[3].value
    output = mask_model.conv_layer(output,
                                   1,
                                   output_shape,
                                   1,
                                   1,
                                   name='tmp_output')
    output = tf.squeeze(output, axis=0)
    output = tf.sigmoid(output)
    # out_put = tf.sigmoid(output)
    saver = tf.train.Saver()
    with tf.Session(config=tf.ConfigProto(allow_soft_placement=True)) as sess:
        saver.restore(sess=sess, save_path='./model/model')
        image_path = 'C:/Users\lr\Desktop/21\H10420180821041413/RIGHT_6.jpg'
        image = cv2.imread(image_path)
        image = input_images_preprocess(image)
        image = resize_image(image)[0]
        image_shape = image.shape
        image = np.reshape(image,
                           [1, image_shape[0], image_shape[1], image_shape[2]])
        feed_dict = {input_images: image}
        loss_result = sess.run(output, feed_dict=feed_dict)
        loss_result = loss_result * 255
        image_result = loss_result.astype(np.int)
        save_img(image_result, 'result.jpg')
        pass
Ejemplo n.º 2
0
def clip_label_image(annotation_info, image_map):
    """
    clip text area
    :param annotation_info:
    :param image_map:
    :return:
    """
    for info in annotation_info:
        name = info['image_name']
        if 'region' not in info.keys():
            continue
        region = info['region']
        if region is None or len(region) == 0:
            continue
        image_path = IMAGE_PATH + name
        original_image = cv2.imread(image_path)
        for r in region:
            try:
                label = r['label']
                print(label)
                p1 = r['p1']
                p2 = r['p2']
                text_area = original_image[int(p1[0]):int(p2[0]), int(p1[1]):int(p2[1]), :]
                path = TEXT_AREA_DIR_PATH + label + '-' + str(uuid.uuid4()) + '.jpg'
                save_img(text_area, path)
                print(label)
            except Exception as e:
                print(e)
Ejemplo n.º 3
0
def main():
    all_image_path = get_all_file_from_dir(HORIZONTAL_PATH)
    index = 0
    for path in all_image_path:
        index += 1
        if index % 1000 == 0:
            print(index)
        new_img = get_resize_image(path)
        new_img = np.rot90(new_img)
        save_img(new_img, path)
Ejemplo n.º 4
0
def main():
    all_image_path = get_all_file_from_dir(HORIZONTAL_PATH)
    length = len(all_image_path)
    index = 0
    for path in all_image_path:
        index += 1
        if index % 100 == 0:
            print(str(index * 1.0 / length))
        new_img = get_resize_image(path)
        # print(path)
        save_img(new_img, path)
Ejemplo n.º 5
0
def save_orig_char(im, char):
    """
    保存生成的原始图片
    :param im:
    :param char:
    :return:
    """
    dir_path = GENERATE_ORIG_CHAR_DIE_PATH + char + '/'
    create_dir(dir_path)

    path = dir_path + str(uuid.uuid4()) + '.jpg'
    save_img(im, path)
Ejemplo n.º 6
0
def merge_image_template(bg_path, template_path_list):
    """
    合成文本模板和图片
    :param bg_path:
    :param template_path_list:
    :return:
    """
    bg = cv2.imread(bg_path)
    bg_shape = bg.shape
    text_area = []  # [[[h_start,h_end],[w_start,w_end]]。。。。。]
    region = []
    for template_path in template_path_list:
        text_img = cv2.imread(template_path)
        text_img = resize_text_img(text_img)
        text_shape = text_img.shape
        point = get_available_point(bg_shape, text_area, text_shape)
        text_area.append([[point[0], point[0] + text_shape[0]],
                          [point[1], point[1] + text_shape[1]]])
        text_color = np.array(get_random_text_color())
        select_bg = bg[point[0]:point[0] + text_shape[0],
                       point[1]:point[1] + text_shape[1], :]
        location = np.where(text_img > 120)
        for i in range(len(location[0])):
            select_bg[location[0][i], location[1][i], :] = text_color
        start_point = [int(point[0]), int(point[1])]
        end_point = [
            int(text_shape[0] + point[0]),
            int(point[1] + text_shape[1])
        ]

        info = {"info": template_path, "p1": start_point, "p2": end_point}
        region.append(info)
    """保存相关图片和信息"""
    image_size = int(bg_shape[0]), int(bg_shape[1])
    file_name = str(uuid.uuid4())
    training_data_dir = GENERATE_DIE_PATH + '/training_data/'
    image_info = {
        'image_size': image_size,
        'region': region,
        'image_name': file_name + '.jpg'
    }
    save_image_path = training_data_dir + file_name + '.jpg'
    save_json_path = training_data_dir + file_name + '.json'
    save_img(bg, save_image_path)
    with open(save_json_path, 'w') as f:
        r = json.dumps(image_info)
        f.write(r)
Ejemplo n.º 7
0
def main():
    for i in range(1000000):
        try:
            print(i)
            text_img, label = gen_template_text_image()
            background = gen_background()
            if i % 3 == 0:
                background[text_img > 150] = np.random.choice(range(0, 30),
                                                              1)[0]
            else:
                background[text_img > 150] = np.random.choice(
                    range(200, 255), 1)[0]
            path = GENERATE_DIE_PATH + '/data/' + label + '-' + str(
                uuid.uuid4()) + '.jpg'
            save_img(background, path)
        except Exception as e:
            print(e)
Ejemplo n.º 8
0
def save_text_image(arr_list):
    """
    保存文字区域图片
    :param arr_list:
    :return:
    """
    i = 0
    for content in arr_list:
        try:
            image_path = content['image_path']
            info = content['info']
            text_lines = info['text_lines']
            if len(text_lines) > 0:
                for area in text_lines:
                    img = cv2.imread(image_path)
                    text_area = get_text_area(img, area)
                    save_img(text_area, TEXT_AREA + str(i) + '.jpg')
                    i += 1
        except Exception as e:
            print(e)