예제 #1
0
파일: pipline.py 프로젝트: wwzzhh063/ocr
def add_bracket(label):                         #加到修改错误项的前面
    if '=' not in label or label=='':
        return label,'problem'
    else:
        left = label.split('=')[0]
        right = label.split('=')[1]

    if right == '' or left == '':
        return label,'problem'

    error_list = []

    if '(' in left and ')' not in left:
        left_num = re.split('[+,-,*,/,(]',left)
        for num in left_num:
            left_temp = left.replace(num,num+')')
            try:
                label_temp = left_temp + '=' + right
                state = eval_label(label_temp)
                if state == 'right':
                    return left_temp, state
                elif state == 'error':
                    error_list.append(label_temp)
            except:
                pass


    elif ')' in left and '(' not in left:
        error_list = []
        left_num = re.split('[+,-,*,/,(]', left)
        for num in left_num:
            left_temp = left.replace(num, '(' + num)
            try:
                label_temp = left_temp+'='+right
                state = eval_label(label_temp)
                if state == 'right':
                    return left_temp,state
                elif state == 'error':
                    error_list.append(left_temp)
            except:
                pass

    else:
        return label,'problem'

    if len(error_list) != 0 :

        num = 0
        label = error_list[0]
        for error in error_list:
            num_temp = correct_problem(error)
            if num_temp > num:
                num = num_temp
                label = error

        return label,'error'

    else:
        return label,'problem'
예제 #2
0
    def check_label(self):
        '''
        检查匹配的算式中是否含有problem的算式
        检查未匹配的算式中是否含有手写且不是中文的框
        :return:
        '''

        for bbox in self.row_pairs:
            state = eval_label(bbox.label)

            if state == 'problem':
                self.revise_label(bbox)
                if bbox.state == 'problem':
                    self.problem_label.append(bbox)
            elif state == 'error':
                bbox.state = state
                self.error_label.append(bbox)

            else:
                bbox.state = state
                self.right_label.append(bbox)

        for bbox in self.print_after_row_connect:
            if no_chinese(bbox.label) and bbox.type == 'print':
                self.problem_label.append(bbox)

        self.all_box = self.error_label + self.right_label
예제 #3
0
파일: pipline.py 프로젝트: wwzzhh063/ocr
def pro_problem_to_right(label):
    if len(re.split('[+,-,×,÷,(,)]', label)[0]) > 3:
        label = label[1:]
    num = 0;
    num = correct_problem(label)
    if num > 0:
        return label
    if correct_problem(label[1:]) > num and eval_label(label[1:])!='problem':
        num = correct_problem(label[1:])
        label = label[1:]
    if correct_problem(label[0:len(label) - 1]) > num and eval_label(label[0:len(label) - 1])!='problem':
        num = correct_problem(label[0:len(label) - 1])
        label = label[0:len(label) - 1]
    if correct_problem(label[1:len(label) - 1]) > num and eval_label(label[1:len(label) - 1])!='problem':
        num = correct_problem(label[1:len(label) - 1])
        label = label[1:len(label) - 1]

    return label
예제 #4
0
 def revise_label(self, bbox):
     '''
     修改标注一些可能出现的问题
     :return:
     '''
     label = bbox.label
     if label.count('=') > 1:
         label = '='.join([label.split('=')[0], label.split('=')[-1]])
         bbox.label = label
         bbox.output = label
         bbox.state = eval_label(label)
예제 #5
0
def json_to_result(json,img):
    all_result = json['questionImgs']
    json_result = Json_Result()
    for q_result in all_result:
        label = q_result['questionContext']
        bbox = [q_result['leftX'],q_result['topY'],q_result['leftX']+q_result['questionWidth'],q_result['topY']+q_result['questionHeight']]
        result = Result(bbox,img,'')
        result.output = label_replace(label)
        result.state = eval_label(result.output)
        json_result.connect_result.append(result)

    return json_result
예제 #6
0
파일: pipline.py 프로젝트: wwzzhh063/ocr
def revise_result(result):

    # state, revise_output, output = delete_top_or_bottom(result)
    state = eval_label(result)   #-------------
    # revise_output = result
    output = result #-----------------------------
    # if state == 'right':
    #     output = revise_output
    #     return 'right',revise_output
    # if state == 'problem':
    #     output, state = add_bracket(output)
    #     if state == 'right':
    #         return 'right',output
    # if state == 'error':
    #     output = pro_problem_to_right(output)
    return state,output
예제 #7
0
파일: pipline.py 프로젝트: wwzzhh063/ocr
def correct_problem(label):
    num = 0
    label_list = label.split('*')
    label = list(set(label_list))
    label.sort(key=label_list.index)
    label = '*'.join(label)
    for i in range(len(label)):
        for j in '1234567890':
            label_ = label[:i]+j+label[i+1:]
            try:
                result = eval_label(label_)
            except:
                result = 'problem'
            if result=='right':
                num = num+1
    return num
예제 #8
0
파일: pipline.py 프로젝트: wwzzhh063/ocr
def delete_top_or_bottom(label):
    label_temp = label

    try:
        result = eval_label(label)
    except:
        result = 'problem'

    result_temp = result

    if result != 'right':
        label_temp = label[1:len(label)]
        try:
            result = eval_label(label_temp)
        except:
            pass
    if result != 'right':
        label_temp = label[2:len(label)]
        try:
            result = eval_label(label_temp)
        except:
            pass

    if result != 'right':
        label_temp = label[0:len(label)-1]
        try:
            result = eval_label(label_temp)
        except:
            pass

    if result != 'right':
        label_temp = label[1:len(label) - 1]
        try:
            result = eval_label(label_temp)
        except:
            pass

    if result != 'right':
        label_temp = label[2:len(label)-1]
        try:
            result = eval_label(label_temp)
        except:
            pass

    if result != 'right':                 #可能会把error变为problem
        result = result_temp


    return result,label_temp,label