import cv2 import time import math import os import numpy as np import tensorflow as tf import json import detect_text_east.lib_east.locality_aware_nms as nms_locality import detect_text_east.lib_east.lanms as lanms import detect_text_east.lib_east.model as model from detect_text_east.lib_east.icdar import restore_rectangle from config.CONFIG import Config cfg = Config() def resize_label(bboxes, gt_height, d_height, bias=0): bboxes_new = [] scale = gt_height / d_height for bbox in bboxes: bbox = [int(b * scale + bias) for b in bbox] bboxes_new.append(bbox) return bboxes_new def save_corners_json(file_path, corners, new=True): if not new: f_in = open(file_path, 'r') components = json.load(f_in) else:
import json import cv2 import numpy as np from os.path import join as pjoin import os import time from random import randint as rint from utils.util_merge import * from config.CONFIG import Config from utils.Element import Element C = Config() def reclassify_text_by_ocr(org, compos, texts): compos_new = [] for i, compo in enumerate(compos): # broad = draw_bounding_box(org, [compo], show=True) new_compo = None text_area = 0 for j, text in enumerate(texts): # get the intersected area inter = compo.calc_intersection_area(text) if inter == 0: continue # calculate IoU ioa = inter / compo.area iob = inter / text.area iou = inter / (compo.area + text.area - inter) # print('ioa:%.3f, iob:%.3f, iou:%.3f' %(ioa, iob, iou))
import cv2 import numpy as np import tensorflow as tf from tensorflow.python.platform import gfile sys.path.append(os.getcwd()) from lib_ctpn.fast_rcnn.config import cfg, cfg_from_file from lib_ctpn.fast_rcnn.test import _get_blobs from lib_ctpn.text_connector.detectors import TextDetector from lib_ctpn.text_connector.text_connect_cfg import Config as TextLineCfg from lib_ctpn.rpn_msr.proposal_layer_tf import proposal_layer import lib_ip.ip_preprocessing as pre from config.CONFIG import Config UI2CODECfg = Config() def resize_im(im, scale, max_scale=None): f = float(scale) / min(im.shape[0], im.shape[1]) if max_scale != None and f * max(im.shape[0], im.shape[1]) > max_scale: f = float(max_scale) / max(im.shape[0], im.shape[1]) return cv2.resize(im, None, None, fx=f, fy=f, interpolation=cv2.INTER_LINEAR), f def draw_boxes(img, boxes, scale, output_path_label, output_path_img):