# @Author  : lightXu
# @File    : mark_box.py
# @Time    : 2018/11/21 0021 下午 16:16
import time
import re
import cv2
import xml.etree.cElementTree as ET

from segment.sheet_resolve.tools.brain_api import get_ocr_text_and_coordinate
from segment.sheet_resolve.tools import utils


def solve_line(solve_img):
    # ocr_region = solve_img[0:int(0.15 * y), :]
    ocr_region = solve_img[0:250, :]

    t11 = time.time()
    word_result_list = get_ocr_text_and_coordinate(ocr_region)
    t22 = time.time()
    print('mark ocr time cost: ', t22-t11)

    if len(word_result_list) < 1:
        return 999
    else:
        words_str = str([ele['words'] for ele in word_result_list])
        number = 999
        number_model = re.compile("\d+[.、:：]\D")
        number_list = number_model.findall(words_str)
        if len(number_list) > 0:
            number = int(re.sub('[\D]', '', number_list[0]))

        return number
