def text_detect(img, MAX_HORIZONTAL_GAP=30, MIN_V_OVERLAPS=0.6, MIN_SIZE_SIM=0.6, TEXT_PROPOSALS_MIN_SCORE=0.7, TEXT_PROPOSALS_NMS_THRESH=0.3, TEXT_LINE_NMS_THRESH=0.3, MIN_RATIO=1.0, LINE_MIN_SCORE=0.8, TEXT_PROPOSALS_WIDTH=5, MIN_NUM_PROPOSALS=1, textmodel='darknet_detect'): if textmodel == 'darknet_detect': boxes, scores = darknet_detect.text_detect(np.array(img)) else: boxes, scores = opencv_dnn_detect.text_detect(np.array(img)) boxes = np.array(boxes, dtype=np.float32) scores = np.array(scores, dtype=np.float32) textdetector = TextDetector(MAX_HORIZONTAL_GAP, MIN_V_OVERLAPS, MIN_SIZE_SIM) shape = img.size[::-1] boxes = textdetector.detect(boxes, scores[:, np.newaxis], shape, TEXT_PROPOSALS_MIN_SCORE, TEXT_PROPOSALS_NMS_THRESH, TEXT_LINE_NMS_THRESH, MIN_RATIO, LINE_MIN_SCORE, TEXT_PROPOSALS_WIDTH, MIN_NUM_PROPOSALS) text_recs, tmp = get_boxes(np.array(img), boxes) newBox = [] rx = 1 ry = 1 for box in text_recs: x1, y1 = (box[0], box[1]) x2, y2 = (box[2], box[3]) x3, y3 = (box[6], box[7]) x4, y4 = (box[4], box[5]) newBox.append([ x1 * rx, y1 * ry, x2 * rx, y2 * ry, x3 * rx, y3 * ry, x4 * rx, y4 * ry ]) return newBox, tmp
def text_detect(img, MAX_HORIZONTAL_GAP=70, MIN_V_OVERLAPS=0.6, MIN_SIZE_SIM=0.6, TEXT_PROPOSALS_MIN_SCORE=0.15, TEXT_PROPOSALS_NMS_THRESH=0.3): # 文本框 boxes, scores = detect.text_detect(np.array(img), thresh=TEXT_PROPOSALS_MIN_SCORE) # 耗时的地方 boxes = np.array(boxes, dtype=np.float32) scores = np.array(scores, dtype=np.float32) textdetector = TextDetector(MAX_HORIZONTAL_GAP, MIN_V_OVERLAPS, MIN_SIZE_SIM) shape = img.size[::-1] # 对textNet检测出来的框进行进一步的过滤,nms boxes = textdetector.detect(boxes, scores[:, np.newaxis], # 变为列 shape, TEXT_PROPOSALS_NMS_THRESH, ) # 画框结束 text_recs, tmp = draw_boxes(im=np.array(img), bboxes=boxes) return text_recs, tmp