|
@@ -1,24 +1,26 @@
|
|
# -*- coding: utf-8 -*-
|
|
# -*- coding: utf-8 -*-
|
|
-# @Time : 2020/5/28 0022 17:02
|
|
|
|
|
|
+# @Time : 2020/6/15 0015 10:10
|
|
# @Author : LF
|
|
# @Author : LF
|
|
-# @FileName: sheet_points_total.py
|
|
|
|
|
|
+# @FileName: sheet_point_total.py
|
|
# @Software: PyCharm
|
|
# @Software: PyCharm
|
|
-# local_baidu_OCR
|
|
|
|
|
|
+
|
|
|
|
|
|
import requests
|
|
import requests
|
|
import base64
|
|
import base64
|
|
from urllib import parse, request
|
|
from urllib import parse, request
|
|
import cv2
|
|
import cv2
|
|
import re
|
|
import re
|
|
-
|
|
|
|
|
|
+from threading import Thread
|
|
|
|
+import copy
|
|
|
|
+from collections import OrderedDict
|
|
from PIL import Image
|
|
from PIL import Image
|
|
from segment.sheet_resolve.tools.brain_api import get_ocr_text_and_coordinate_in_google_format
|
|
from segment.sheet_resolve.tools.brain_api import get_ocr_text_and_coordinate_in_google_format
|
|
from segment.sheet_resolve.analysis.sheet.ocr_key_words import key_words
|
|
from segment.sheet_resolve.analysis.sheet.ocr_key_words import key_words
|
|
|
|
|
|
-# try:
|
|
|
|
-# import tr
|
|
|
|
-# except Exception:
|
|
|
|
-# pass
|
|
|
|
|
|
+try:
|
|
|
|
+ import tr.tr as tr
|
|
|
|
+except Exception:
|
|
|
|
+ pass
|
|
|
|
|
|
OCR_ACCURACY = 'accurate'
|
|
OCR_ACCURACY = 'accurate'
|
|
|
|
|
|
@@ -260,6 +262,64 @@ def model_type_score(all_type_score_one, choice_box, cloze_box, solve_box,compos
|
|
|
|
|
|
return test_result1
|
|
return test_result1
|
|
|
|
|
|
|
|
+def module_type_score(all_type_score_one, choice_box, cloze_box, solve_box, composition_box): # 每个模块内包含的type_score
|
|
|
|
+ '''
|
|
|
|
+ :param all_type_score_one: 模型得到的单个type_score的坐标位置
|
|
|
|
+ :param choice_box: 模型得到的选择题坐标位置
|
|
|
|
+ :param cloze_box: 模型得到的填空题坐标位置
|
|
|
|
+ :param solve_box: 模型得到的解答题坐标位置
|
|
|
|
+ :return:
|
|
|
|
+ '''
|
|
|
|
+
|
|
|
|
+ N_choice = len(choice_box)
|
|
|
|
+ N_cloze = len(cloze_box)
|
|
|
|
+ N_solve = len(solve_box)
|
|
|
|
+ N_composition = len(composition_box)
|
|
|
|
+ choice_type_score = {}
|
|
|
|
+ cloze_type_score = {}
|
|
|
|
+ solve_type_score = {}
|
|
|
|
+ composition_type_score = {}
|
|
|
|
+ test_result1 = {}
|
|
|
|
+ temp_dis = 100000
|
|
|
|
+ for j in range(N_choice):
|
|
|
|
+ if (list(all_type_score_one)[0] and list(all_type_score_one)[2]) in range(choice_box[j][0] - 100, choice_box[j][2] + 50) and (list(all_type_score_one)[1] and list(all_type_score_one)[3]) in range(choice_box[j][1] - 150, choice_box[j][3] - 50):
|
|
|
|
+ choice_type_score = {'bounding_box': choice_box[j],
|
|
|
|
+ 'label': 'choice',
|
|
|
|
+ 'type_box': all_type_score_one}
|
|
|
|
+ break
|
|
|
|
+ for j in range(N_cloze):
|
|
|
|
+ if (list(all_type_score_one)[0] and list(all_type_score_one)[2]) in range(cloze_box[j][0] - 100, cloze_box[j][2] + 50) and (list(all_type_score_one)[1] and list(all_type_score_one)[3]) in range(cloze_box[j][1] - 100, cloze_box[j][3] - 50):
|
|
|
|
+ cloze_type_score = {'bounding_box': cloze_box[j],
|
|
|
|
+ 'label': 'cloze',
|
|
|
|
+ 'type_box': all_type_score_one}
|
|
|
|
+ break
|
|
|
|
+ for j in range(N_solve):
|
|
|
|
+ if (list(all_type_score_one)[0] and list(all_type_score_one)[2]) in range(solve_box[j][0] - 50, solve_box[j][2] + 50) and (list(all_type_score_one)[1] and list(all_type_score_one)[3]) in range(solve_box[j][1]-50, solve_box[j][3]):
|
|
|
|
+ solve_type_score = {'bounding_box': solve_box[j],
|
|
|
|
+ 'label': 'solve',
|
|
|
|
+ 'type_box': all_type_score_one}
|
|
|
|
+ break
|
|
|
|
+ for j in range(N_composition):
|
|
|
|
+ if (list(all_type_score_one)[0] and list(all_type_score_one)[2]) in range(composition_box[j][0] - 100, composition_box[j][2] + 50) and (list(all_type_score_one)[1] and list(all_type_score_one)[3]) in range(composition_box[j][1] - 200, composition_box[j][3] - 50):
|
|
|
|
+ composition_type_score = {'bounding_box': composition_box[j],
|
|
|
|
+ 'label': 'composition',
|
|
|
|
+ 'type_box': all_type_score_one}
|
|
|
|
+ break
|
|
|
|
+ if choice_type_score != {}:
|
|
|
|
+ # 建立相互关联的关系。 即表示该type_score对应于选择题
|
|
|
|
+ test_result1 = choice_type_score
|
|
|
|
+ elif cloze_type_score != {}:
|
|
|
|
+ # 建立相互关联的关系。 即表示该type_score对应于填空题
|
|
|
|
+ test_result1 = cloze_type_score
|
|
|
|
+ elif solve_type_score != {}:
|
|
|
|
+ # 建立相互关联的关系。 即表示该type_score对应于解答题
|
|
|
|
+ test_result1 = solve_type_score
|
|
|
|
+ elif composition_type_score != {}:
|
|
|
|
+ test_result1 = composition_type_score
|
|
|
|
+ else:
|
|
|
|
+ test_result1 = -1
|
|
|
|
+ return test_result1
|
|
|
|
+
|
|
|
|
|
|
def ocr_key_words(rect, type_score_dict): # 将ocr识别得到的文字与模型得到的type_score对应
|
|
def ocr_key_words(rect, type_score_dict): # 将ocr识别得到的文字与模型得到的type_score对应
|
|
'''
|
|
'''
|
|
@@ -274,8 +334,7 @@ def ocr_key_words(rect, type_score_dict): # 将ocr识别得到的文字与模
|
|
ymax = type_score_dict['type_box'][3]
|
|
ymax = type_score_dict['type_box'][3]
|
|
words = []
|
|
words = []
|
|
for j in range(len_ocr):
|
|
for j in range(len_ocr):
|
|
- if rect['coordinates'][j][0] - xmin > -30 and rect['coordinates'][j][1] - ymin > -30 and rect['coordinates'][j][
|
|
|
|
- 2] - xmax < 30 and rect['coordinates'][j][3] - ymax < 30:
|
|
|
|
|
|
+ if rect['coordinates'][j][0] - xmin > -30 and rect['coordinates'][j][1] - ymin > -30 and rect['coordinates'][j][2] - xmax < 30 and rect['coordinates'][j][3] - ymax < 30:
|
|
word = rect['chars'][j]
|
|
word = rect['chars'][j]
|
|
words.append(word)
|
|
words.append(word)
|
|
type_score_dict['words'] = words
|
|
type_score_dict['words'] = words
|
|
@@ -284,8 +343,57 @@ def ocr_key_words(rect, type_score_dict): # 将ocr识别得到的文字与模
|
|
return type_score_dict_ocr
|
|
return type_score_dict_ocr
|
|
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+def big_block_score(img0,xmins_b,ymins_b,xmaxs_b,ymaxs_b):
|
|
|
|
+ res1 = get_ocr_text_and_coordinate_in_google_format(img0[ymins_b:ymaxs_b, xmins_b:xmaxs_b],ocr_accuracy=OCR_ACCURACY, language_type='CHN_ENG')
|
|
|
|
+ aa = []
|
|
|
|
+ type_score_dict_ocrs = {}
|
|
|
|
+ for ii in range(len(res1['coordinates'])):
|
|
|
|
+ xmin11 = res1['coordinates'][ii][0] + xmins_b
|
|
|
|
+ ymin11 = res1['coordinates'][ii][1] + ymins_b
|
|
|
|
+ xmax11 = res1['coordinates'][ii][2] + xmins_b
|
|
|
|
+ ymax11 = res1['coordinates'][ii][3] + ymins_b
|
|
|
|
+ aaa = (xmin11, ymin11, xmax11, ymax11)
|
|
|
|
+ aa.append(aaa)
|
|
|
|
+ res1['coordinates'] = aa
|
|
|
|
+ new_test = {}
|
|
|
|
+ coordinates = 0
|
|
|
|
+ if len(res1['words']) > 0:
|
|
|
|
+ type_score_dict_ocrs['words'] = res1['words'][0]
|
|
|
|
+ coordinates = res1['coordinates'][0]
|
|
|
|
+ new_test = key_words(type_score_dict_ocrs)
|
|
|
|
+ if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
+ if len(res1['words']) > 1:
|
|
|
|
+ type_score_dict_ocrs['words'] = res1['words'][1]
|
|
|
|
+ coordinates = res1['coordinates'][1]
|
|
|
|
+ new_test = key_words(type_score_dict_ocrs)
|
|
|
|
+ if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
+ if len(res1['words']) > 2:
|
|
|
|
+ type_score_dict_ocrs['words'] = res1['words'][2]
|
|
|
|
+ coordinates = res1['coordinates'][2]
|
|
|
|
+ new_test = key_words(type_score_dict_ocrs)
|
|
|
|
+ if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
+ if len(res1['words']) > 3:
|
|
|
|
+ type_score_dict_ocrs['words'] = res1['words'][3]
|
|
|
|
+ coordinates = res1['coordinates'][3]
|
|
|
|
+ new_test = key_words(type_score_dict_ocrs)
|
|
|
|
+ if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
+ if len(res1['words']) > 4:
|
|
|
|
+ type_score_dict_ocrs['words'] = res1['words'][4]
|
|
|
|
+ coordinates = res1['coordinates'][4]
|
|
|
|
+ new_test = key_words(type_score_dict_ocrs)
|
|
|
|
+ if new_test != {} and new_test['volume_structure'] != -1 and new_test['volume_structure'] != 1: # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
+ if int(new_test['volume_structure'][0]['volume_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
+ new_test['volume_structure'][0]['volume_total_score'] = int(
|
|
|
|
+ new_test['volume_structure'][0]['volume_total_score']) % 100
|
|
|
|
+ return new_test
|
|
|
|
+ elif new_test != {} and (new_test['volume_structure'] == -1 or new_test['volume_structure'] == 1) and new_test['Score_structure'] != -1: # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
+ if int(new_test['Score_structure'][0]['item_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
+ new_test['Score_structure'][0]['item_total_score'] = int(
|
|
|
|
+ new_test['Score_structure'][0]['item_total_score']) % 100
|
|
|
|
+ new_test['Score_structure'][0]['type_box'] = coordinates
|
|
|
|
+ return new_test
|
|
|
|
+ else:
|
|
|
|
+ return -1
|
|
|
|
|
|
def get_sheet_number_total(answer_sheet, res, img0):
|
|
def get_sheet_number_total(answer_sheet, res, img0):
|
|
|
|
|
|
@@ -311,13 +419,14 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
Score_last = []
|
|
Score_last = []
|
|
score_last_one = 0
|
|
score_last_one = 0
|
|
volume_last_one = 0
|
|
volume_last_one = 0
|
|
- model_box2 = []
|
|
|
|
composition_boxs = []
|
|
composition_boxs = []
|
|
- score2 = []
|
|
|
|
- num_redundance = 0
|
|
|
|
num_composition = 0
|
|
num_composition = 0
|
|
j_temp = []
|
|
j_temp = []
|
|
jj_temp =[]
|
|
jj_temp =[]
|
|
|
|
+ eles = []
|
|
|
|
+ yy_max = []
|
|
|
|
+ score_del = []
|
|
|
|
+ key_modules_classes = ['choice', 'cloze', 'solve', 'solve0', 'composition0', 'composition', 'correction', 'type_score']
|
|
|
|
|
|
for ele in answer_sheet["regions"]: # 从模型输出获取对应标签的边框信息
|
|
for ele in answer_sheet["regions"]: # 从模型输出获取对应标签的边框信息
|
|
if ele["class_name"] == 'choice':
|
|
if ele["class_name"] == 'choice':
|
|
@@ -359,18 +468,13 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
type_score_boxs.append(type_score_one)
|
|
type_score_boxs.append(type_score_one)
|
|
num_type_score = num_type_score + 1
|
|
num_type_score = num_type_score + 1
|
|
|
|
|
|
|
|
+
|
|
'''解析type_score与对应分割模块的分数'''
|
|
'''解析type_score与对应分割模块的分数'''
|
|
for i in range(len(type_score_boxs)):
|
|
for i in range(len(type_score_boxs)):
|
|
- test_result1 = model_type_score(type_score_boxs[i], choice_boxs, cloze_boxs, solve_boxs, composition_boxs)
|
|
|
|
|
|
+ test_result1 = module_type_score(type_score_boxs[i], choice_boxs, cloze_boxs, solve_boxs, composition_boxs)
|
|
if test_result1 != -1 and test_result1 != 0:
|
|
if test_result1 != -1 and test_result1 != 0:
|
|
- if type_score_boxs[i][0] - 5 > 0:
|
|
|
|
- xminss = type_score_boxs[i][0]-5
|
|
|
|
- else:
|
|
|
|
- xminss = type_score_boxs[i][0]
|
|
|
|
- if type_score_boxs[i][1] - 5 > 0:
|
|
|
|
- yminss = type_score_boxs[i][1] - 5
|
|
|
|
- else:
|
|
|
|
- yminss = type_score_boxs[i][1]
|
|
|
|
|
|
+ xminss = (type_score_boxs[i][0] - 5) if type_score_boxs[i][0] - 5 > 0 else type_score_boxs[i][0]
|
|
|
|
+ yminss = (type_score_boxs[i][1] - 5) if type_score_boxs[i][1] - 5 > 0 else type_score_boxs[i][1]
|
|
if type_score_boxs[i][2] + 5 < img_w:
|
|
if type_score_boxs[i][2] + 5 < img_w:
|
|
xmaxss = type_score_boxs[i][2] + 5
|
|
xmaxss = type_score_boxs[i][2] + 5
|
|
else:
|
|
else:
|
|
@@ -380,17 +484,28 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
else:
|
|
else:
|
|
ymaxss = type_score_boxs[i][3]
|
|
ymaxss = type_score_boxs[i][3]
|
|
test_result1['words'] = str()
|
|
test_result1['words'] = str()
|
|
- # try: # tr_OCR
|
|
|
|
- # image_src_type_score = image_src.crop((xminss, yminss, xmaxss, ymaxss))
|
|
|
|
- # type_score_dict_ocr = tr.run(image_src_type_score)
|
|
|
|
- # print('tr_OCR')
|
|
|
|
- # for t in range(len(type_score_dict_ocr)):
|
|
|
|
- # test_result1['words'] = test_result1['words'] + type_score_dict_ocr[t][1]
|
|
|
|
- # except Exception as e: # baidu_OCR
|
|
|
|
- # print('baidu_OCR')
|
|
|
|
- type_score_dict_ocr = get_ocr_text_and_coordinate_in_google_format(img0[yminss:ymaxss, xminss:xmaxss], ocr_accuracy=OCR_ACCURACY,language_type='CHN_ENG')
|
|
|
|
- for t in range(len(type_score_dict_ocr['words'])):
|
|
|
|
- test_result1['words'] = test_result1['words'] + type_score_dict_ocr['words'][t]
|
|
|
|
|
|
+ try: # tr_OCR
|
|
|
|
+ image_src_type_score = image_src.crop((xminss, yminss, xmaxss, ymaxss))
|
|
|
|
+ w_small = xmaxss - xminss
|
|
|
|
+ h_small = ymaxss - yminss
|
|
|
|
+ if h_small < 100 and w_small > 100:
|
|
|
|
+ image_src_type_score = Image.new(image_src.mode, (w_small, 100), (255))
|
|
|
|
+ image_src_type_score.paste(image_src, [0, 0, w_small, h_small])
|
|
|
|
+ elif w_small < 100 and h_small > 100:
|
|
|
|
+ image_src_type_score = Image.new(image_src.mode, (100, h_small), (255))
|
|
|
|
+ image_src_type_score.paste(image_src, [0, 0, w_small, h_small])
|
|
|
|
+ elif w_small < 100 and h_small < 100:
|
|
|
|
+ image_src_type_score = Image.new(image_src.mode, (100, 100), (255))
|
|
|
|
+ image_src_type_score.paste(image_src, [0, 0, w_small, h_small])
|
|
|
|
+ type_score_dict_ocr = tr.run(image_src_type_score)
|
|
|
|
+ print('tr_OCR')
|
|
|
|
+ for t in range(len(type_score_dict_ocr)):
|
|
|
|
+ test_result1['words'] = test_result1['words'] + type_score_dict_ocr[t][1]
|
|
|
|
+ except Exception as e: # baidu_OCR
|
|
|
|
+ print('baidu_OCR')
|
|
|
|
+ type_score_dict_ocr = get_ocr_text_and_coordinate_in_google_format(img0[yminss:ymaxss, xminss:xmaxss], ocr_accuracy=OCR_ACCURACY,language_type='CHN_ENG')
|
|
|
|
+ for t in range(len(type_score_dict_ocr['words'])):
|
|
|
|
+ test_result1['words'] = test_result1['words'] + type_score_dict_ocr['words'][t]
|
|
|
|
|
|
test = key_words(test_result1)
|
|
test = key_words(test_result1)
|
|
if test == {}:
|
|
if test == {}:
|
|
@@ -402,6 +517,7 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
add_ocr['score'] = -1
|
|
add_ocr['score'] = -1
|
|
add_ocr['number_score'] = -1
|
|
add_ocr['number_score'] = -1
|
|
add_ocr['counts'] = -1
|
|
add_ocr['counts'] = -1
|
|
|
|
+ add_ocr['type_score_box'] = type_score_boxs[i]
|
|
add_ocr['ocr'] = test_result1['words']
|
|
add_ocr['ocr'] = test_result1['words']
|
|
Score_last.append(add_ocr)
|
|
Score_last.append(add_ocr)
|
|
elif test['volume_structure'] == -1 and test['Score_structure'] == -1:
|
|
elif test['volume_structure'] == -1 and test['Score_structure'] == -1:
|
|
@@ -413,30 +529,45 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
add_ocr['score'] = -1
|
|
add_ocr['score'] = -1
|
|
add_ocr['number_score'] = -1
|
|
add_ocr['number_score'] = -1
|
|
add_ocr['counts'] = -1
|
|
add_ocr['counts'] = -1
|
|
|
|
+ add_ocr['type_score_box'] = type_score_boxs[i]
|
|
add_ocr['ocr'] = test_result1['words']
|
|
add_ocr['ocr'] = test_result1['words']
|
|
Score_last.append(add_ocr)
|
|
Score_last.append(add_ocr)
|
|
elif test != {}:
|
|
elif test != {}:
|
|
- if test['volume_structure'] != -1 and int(
|
|
|
|
|
|
+ if test['volume_structure'] != -1 and test['volume_structure'] != 1 and int(
|
|
test['volume_structure'][0]['volume_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
test['volume_structure'][0]['volume_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
test['volume_structure'][0]['volume_total_score'] = int(
|
|
test['volume_structure'][0]['volume_total_score'] = int(
|
|
test['volume_structure'][0]['volume_total_score']) % 100
|
|
test['volume_structure'][0]['volume_total_score']) % 100
|
|
- elif test['volume_structure'] == -1 and test['Score_structure'] != -1 and int(
|
|
|
|
|
|
+ elif (test['volume_structure'] == -1 or test['volume_structure'] == 1) and test['Score_structure'] != -1 and int(
|
|
test['Score_structure'][0]['item_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
test['Score_structure'][0]['item_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
test['Score_structure'][0]['item_total_score'] = int(
|
|
test['Score_structure'][0]['item_total_score'] = int(
|
|
test['Score_structure'][0]['item_total_score']) % 100
|
|
test['Score_structure'][0]['item_total_score']) % 100
|
|
all_test.append(test)
|
|
all_test.append(test)
|
|
|
|
+ else:
|
|
|
|
+ ### 添加返回值OCR结果
|
|
|
|
+ add_ocr = {}
|
|
|
|
+ add_ocr['model_box'] = test_result1['bounding_box']
|
|
|
|
+ add_ocr['label'] = test_result1['label']
|
|
|
|
+ add_ocr['number'] = -1
|
|
|
|
+ add_ocr['score'] = -1
|
|
|
|
+ add_ocr['number_score'] = -1
|
|
|
|
+ add_ocr['counts'] = -1
|
|
|
|
+ add_ocr['type_score_box'] = type_score_boxs[i]
|
|
|
|
+ add_ocr['ocr'] = test_result1['words']
|
|
|
|
+ Score_last.append(add_ocr)
|
|
|
|
+
|
|
|
|
|
|
''' 解析模型分割模块没有对应的type_score时的分数'''
|
|
''' 解析模型分割模块没有对应的type_score时的分数'''
|
|
for jjjj in range(len(all_test)):
|
|
for jjjj in range(len(all_test)):
|
|
if all_test[jjjj]['Score_structure'] != -1:
|
|
if all_test[jjjj]['Score_structure'] != -1:
|
|
label_1 = all_test[jjjj]['Score_structure'][0]['label']
|
|
label_1 = all_test[jjjj]['Score_structure'][0]['label']
|
|
- if label_1 == 'choice':
|
|
|
|
|
|
+ num_1 = all_test[jjjj]['Score_structure'][0]['item_N']
|
|
|
|
+ if label_1 == 'choice' :
|
|
if choice_boxs.count(all_test[jjjj]['Score_structure'][0]['bounding_box']):
|
|
if choice_boxs.count(all_test[jjjj]['Score_structure'][0]['bounding_box']):
|
|
choice_boxs.remove(all_test[jjjj]['Score_structure'][0]['bounding_box'])
|
|
choice_boxs.remove(all_test[jjjj]['Score_structure'][0]['bounding_box'])
|
|
elif label_1 == 'cloze':
|
|
elif label_1 == 'cloze':
|
|
if cloze_boxs.count(all_test[jjjj]['Score_structure'][0]['bounding_box']):
|
|
if cloze_boxs.count(all_test[jjjj]['Score_structure'][0]['bounding_box']):
|
|
cloze_boxs.remove(all_test[jjjj]['Score_structure'][0]['bounding_box'])
|
|
cloze_boxs.remove(all_test[jjjj]['Score_structure'][0]['bounding_box'])
|
|
- elif label_1 == 'solve':
|
|
|
|
|
|
+ elif label_1 == 'solve' and num_1 != 10000 and num_1 != -1:
|
|
if solve_boxs.count(all_test[jjjj]['Score_structure'][0]['bounding_box']):
|
|
if solve_boxs.count(all_test[jjjj]['Score_structure'][0]['bounding_box']):
|
|
solve_boxs.remove(all_test[jjjj]['Score_structure'][0]['bounding_box'])
|
|
solve_boxs.remove(all_test[jjjj]['Score_structure'][0]['bounding_box'])
|
|
elif label_1 == 'composition':
|
|
elif label_1 == 'composition':
|
|
@@ -444,61 +575,11 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
solve_boxs.remove(all_test[jjjj]['Score_structure'][0]['bounding_box'])
|
|
solve_boxs.remove(all_test[jjjj]['Score_structure'][0]['bounding_box'])
|
|
if choice_boxs != []: # 9月16号修改
|
|
if choice_boxs != []: # 9月16号修改
|
|
for ij in range(len(choice_boxs)):
|
|
for ij in range(len(choice_boxs)):
|
|
- if choice_boxs[ij][1] - 150 > 0:
|
|
|
|
- yminss = choice_boxs[ij][1] - 150
|
|
|
|
- else:
|
|
|
|
- yminss = choice_boxs[ij][1]
|
|
|
|
- if choice_boxs[ij][0] - 100 > 0:
|
|
|
|
- xminss = choice_boxs[ij][0] - 100
|
|
|
|
- else:
|
|
|
|
- xminss = choice_boxs[ij][0]
|
|
|
|
|
|
+ yminss = choice_boxs[ij][1] - 150 if choice_boxs[ij][1] - 150 > 0 else choice_boxs[ij][1]
|
|
|
|
+ xminss = choice_boxs[ij][0] - 100 if choice_boxs[ij][0] - 100 > 0 else choice_boxs[ij][0]
|
|
try:
|
|
try:
|
|
- res1 = get_ocr_text_and_coordinate_in_google_format(img0[yminss:choice_boxs[ij][3], xminss:choice_boxs[ij][2]], ocr_accuracy=OCR_ACCURACY,language_type='CHN_ENG')
|
|
|
|
- aa = []
|
|
|
|
- type_score_dict_ocrs = {}
|
|
|
|
- for ii in range(len(res1['coordinates'])):
|
|
|
|
- xmin11 = res1['coordinates'][ii][0] + choice_boxs[ij][0]
|
|
|
|
- ymin11 = res1['coordinates'][ii][1] + choice_boxs[ij][1]
|
|
|
|
- xmax11 = res1['coordinates'][ii][2] + choice_boxs[ij][0]
|
|
|
|
- ymax11 = res1['coordinates'][ii][3] + choice_boxs[ij][1]
|
|
|
|
- aaa = (xmin11, ymin11, xmax11, ymax11)
|
|
|
|
- aa.append(aaa)
|
|
|
|
- res1['coordinates'] = aa
|
|
|
|
- new_test = {}
|
|
|
|
- if len(res1['words']) > 0:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][0]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 1:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][1]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 2:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][2]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 3:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][3]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 4:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][4]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test != {} and new_test['volume_structure'] != -1 and (
|
|
|
|
- int(new_test['volume_structure'][0]['volume_total_score']) > 4 or int(
|
|
|
|
- new_test['volume_structure'][0]['volume_score']) > 4): # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
- if int(new_test['volume_structure'][0]['volume_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
- new_test['volume_structure'][0]['volume_total_score'] = int(
|
|
|
|
- new_test['volume_structure'][0]['volume_total_score']) % 100
|
|
|
|
- new_test['volume_structure'][0]['bounding_box'] = choice_boxs[ij]
|
|
|
|
- new_test['volume_structure'][0]['label'] = 'choice'
|
|
|
|
- all_test.append(new_test)
|
|
|
|
- elif new_test != {} and new_test['volume_structure'] == -1 and new_test['Score_structure'] != -1 and (
|
|
|
|
- int(new_test['Score_structure'][0]['item_total_score']) > 4 or int(
|
|
|
|
- new_test['Score_structure'][0]['item_score']) > 4): # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
- if int(new_test['Score_structure'][0]['item_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
- new_test['Score_structure'][0]['item_total_score'] = int(
|
|
|
|
- new_test['Score_structure'][0]['item_total_score']) % 100
|
|
|
|
|
|
+ new_test = big_block_score(img0, xminss, yminss, choice_boxs[ij][2], choice_boxs[ij][3])
|
|
|
|
+ if new_test != -1:
|
|
new_test['Score_structure'][0]['bounding_box'] = choice_boxs[ij]
|
|
new_test['Score_structure'][0]['bounding_box'] = choice_boxs[ij]
|
|
new_test['Score_structure'][0]['label'] = 'choice'
|
|
new_test['Score_structure'][0]['label'] = 'choice'
|
|
all_test.append(new_test)
|
|
all_test.append(new_test)
|
|
@@ -506,57 +587,11 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
print('choice_boxs_score_NULL_or_error')
|
|
print('choice_boxs_score_NULL_or_error')
|
|
if cloze_boxs != []:
|
|
if cloze_boxs != []:
|
|
for ij in range(len(cloze_boxs)):
|
|
for ij in range(len(cloze_boxs)):
|
|
- if cloze_boxs[ij][1] - 100 > 0:
|
|
|
|
- yminss = cloze_boxs[ij][1] - 100
|
|
|
|
- else:
|
|
|
|
- yminss = cloze_boxs[ij][1]
|
|
|
|
- if cloze_boxs[ij][0] - 100 > 0:
|
|
|
|
- xminss = cloze_boxs[ij][0] - 100
|
|
|
|
- else:
|
|
|
|
- xminss = cloze_boxs[ij][0]
|
|
|
|
|
|
+ yminss = cloze_boxs[ij][1] - 100 if cloze_boxs[ij][1] - 100 > 0 else cloze_boxs[ij][1]
|
|
|
|
+ xminss = cloze_boxs[ij][0] - 100 if cloze_boxs[ij][0] - 100 > 0 else cloze_boxs[ij][0]
|
|
try:
|
|
try:
|
|
- res1 = get_ocr_text_and_coordinate_in_google_format(img0[yminss:cloze_boxs[ij][3], xminss:cloze_boxs[ij][2]], ocr_accuracy=OCR_ACCURACY,language_type='CHN_ENG')
|
|
|
|
- aa = []
|
|
|
|
- type_score_dict_ocrs = {}
|
|
|
|
- for ii in range(len(res1['coordinates'])):
|
|
|
|
- xmin11 = res1['coordinates'][ii][0] + cloze_boxs[ij][0]
|
|
|
|
- ymin11 = res1['coordinates'][ii][1] + cloze_boxs[ij][1]
|
|
|
|
- xmax11 = res1['coordinates'][ii][2] + cloze_boxs[ij][0]
|
|
|
|
- ymax11 = res1['coordinates'][ii][3] + cloze_boxs[ij][1]
|
|
|
|
- aaa = (xmin11, ymin11, xmax11, ymax11)
|
|
|
|
- aa.append(aaa)
|
|
|
|
- res1['coordinates'] = aa
|
|
|
|
- new_test = {}
|
|
|
|
- if len(res1['words']) > 0:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][0]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 1:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][1]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 2:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][2]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 3:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][3]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 4:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][4]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test != {} and new_test['volume_structure'] != -1 and (int(new_test['volume_structure'][0]['volume_total_score']) > 4 or int(new_test['volume_structure'][0]['volume_score']) > 4): # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
- if int(new_test['volume_structure'][0]['volume_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
- new_test['volume_structure'][0]['volume_total_score'] = int(
|
|
|
|
- new_test['volume_structure'][0]['volume_total_score']) % 100
|
|
|
|
- new_test['volume_structure'][0]['bounding_box'] = cloze_boxs[ij]
|
|
|
|
- new_test['volume_structure'][0]['label'] = 'cloze'
|
|
|
|
- all_test.append(new_test)
|
|
|
|
- elif new_test != {} and new_test['volume_structure'] == -1 and new_test['Score_structure'] != -1 and (int(new_test['Score_structure'][0]['item_total_score']) > 4 or int(new_test['Score_structure'][0]['item_score']) > 4): # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
- if int(new_test['Score_structure'][0]['item_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
- new_test['Score_structure'][0]['item_total_score'] = int(
|
|
|
|
- new_test['Score_structure'][0]['item_total_score']) % 100
|
|
|
|
|
|
+ new_test = big_block_score(img0, xminss, yminss, cloze_boxs[ij][2], cloze_boxs[ij][3])
|
|
|
|
+ if new_test != -1:
|
|
new_test['Score_structure'][0]['bounding_box'] = cloze_boxs[ij]
|
|
new_test['Score_structure'][0]['bounding_box'] = cloze_boxs[ij]
|
|
new_test['Score_structure'][0]['label'] = 'cloze'
|
|
new_test['Score_structure'][0]['label'] = 'cloze'
|
|
all_test.append(new_test)
|
|
all_test.append(new_test)
|
|
@@ -564,51 +599,11 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
print('cloze_boxs_score_NULL_or_error')
|
|
print('cloze_boxs_score_NULL_or_error')
|
|
if solve_boxs != []:
|
|
if solve_boxs != []:
|
|
for ij in range(len(solve_boxs)):
|
|
for ij in range(len(solve_boxs)):
|
|
- yminss = solve_boxs[ij][1]
|
|
|
|
- xminss = solve_boxs[ij][0]
|
|
|
|
|
|
+ yminss = solve_boxs[ij][1] - 50 if solve_boxs[ij][1] - 50 > 0 else solve_boxs[ij][1]
|
|
|
|
+ xminss = solve_boxs[ij][0] - 50 if solve_boxs[ij][0] - 50 > 0 else solve_boxs[ij][0]
|
|
try:
|
|
try:
|
|
- res1 = get_ocr_text_and_coordinate_in_google_format(img0[yminss:solve_boxs[ij][3], xminss:solve_boxs[ij][2]], ocr_accuracy=OCR_ACCURACY,language_type='CHN_ENG')
|
|
|
|
- aa = []
|
|
|
|
- type_score_dict_ocrs = {}
|
|
|
|
- for ii in range(len(res1['coordinates'])):
|
|
|
|
- xmin11 = res1['coordinates'][ii][0] + solve_boxs[ij][0]
|
|
|
|
- ymin11 = res1['coordinates'][ii][1] + solve_boxs[ij][1]
|
|
|
|
- xmax11 = res1['coordinates'][ii][2] + solve_boxs[ij][0]
|
|
|
|
- ymax11 = res1['coordinates'][ii][3] + solve_boxs[ij][1]
|
|
|
|
- aaa = (xmin11, ymin11, xmax11, ymax11)
|
|
|
|
- aa.append(aaa)
|
|
|
|
- res1['coordinates'] = aa
|
|
|
|
- new_test = {}
|
|
|
|
- if len(res1['words']) > 0:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][0]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 1:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][1]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 2:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][2]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 3:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][3]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 4:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][4]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test != {} and new_test['volume_structure'] != -1 and int(new_test['volume_structure'][0]['volume_total_score']) > 5: # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
- if int(new_test['volume_structure'][0]['volume_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
- new_test['volume_structure'][0]['volume_total_score'] = int(new_test['volume_structure'][0]['volume_total_score']) % 100
|
|
|
|
- new_test['volume_structure'][0]['bounding_box'] = solve_boxs[ij]
|
|
|
|
- new_test['volume_structure'][0]['label'] = 'solve'
|
|
|
|
- all_test.append(new_test)
|
|
|
|
- elif new_test != {} and new_test['volume_structure'] == -1 and new_test[
|
|
|
|
- 'Score_structure'] != -1 and (
|
|
|
|
- int(new_test['Score_structure'][0]['item_total_score']) > 5 or int(new_test['Score_structure'][0]['item_total_score']) == -1): # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
- if int(new_test['Score_structure'][0]['item_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
- new_test['Score_structure'][0]['item_total_score'] = int(new_test['Score_structure'][0]['item_total_score']) % 100
|
|
|
|
|
|
+ new_test = big_block_score(img0, xminss, yminss, solve_boxs[ij][2], solve_boxs[ij][3])
|
|
|
|
+ if new_test != -1:
|
|
new_test['Score_structure'][0]['bounding_box'] = solve_boxs[ij]
|
|
new_test['Score_structure'][0]['bounding_box'] = solve_boxs[ij]
|
|
new_test['Score_structure'][0]['label'] = 'solve'
|
|
new_test['Score_structure'][0]['label'] = 'solve'
|
|
all_test.append(new_test)
|
|
all_test.append(new_test)
|
|
@@ -616,60 +611,11 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
print('solve_boxs_score_NULL_or_error')
|
|
print('solve_boxs_score_NULL_or_error')
|
|
if composition_boxs != []:
|
|
if composition_boxs != []:
|
|
for ij in range(len(composition_boxs)):
|
|
for ij in range(len(composition_boxs)):
|
|
- if composition_boxs[ij][1] - 250 > 0:
|
|
|
|
- yminss = composition_boxs[ij][1] - 250
|
|
|
|
- else:
|
|
|
|
- yminss = composition_boxs[ij][1]
|
|
|
|
- if composition_boxs[ij][0] - 100 > 0:
|
|
|
|
- xminss = composition_boxs[ij][0] - 100
|
|
|
|
- else:
|
|
|
|
- xminss = composition_boxs[ij][0]
|
|
|
|
|
|
+ yminss = composition_boxs[ij][1] - 240 if composition_boxs[ij][1] - 240 > 0 else composition_boxs[ij][1]
|
|
|
|
+ xminss = composition_boxs[ij][0] - 100 if composition_boxs[ij][0] - 100 > 0 else composition_boxs[ij][0]
|
|
try:
|
|
try:
|
|
- res1 = get_ocr_text_and_coordinate_in_google_format(img0[yminss:composition_boxs[ij][3], xminss:composition_boxs[ij][2]], ocr_accuracy=OCR_ACCURACY,language_type='CHN_ENG')
|
|
|
|
- aa = []
|
|
|
|
- type_score_dict_ocrs = {}
|
|
|
|
- for ii in range(len(res1['coordinates'])):
|
|
|
|
- xmin11 = res1['coordinates'][ii][0] + composition_boxs[ij][0]
|
|
|
|
- ymin11 = res1['coordinates'][ii][1] + composition_boxs[ij][1]
|
|
|
|
- xmax11 = res1['coordinates'][ii][2] + composition_boxs[ij][0]
|
|
|
|
- ymax11 = res1['coordinates'][ii][3] + composition_boxs[ij][1]
|
|
|
|
- aaa = (xmin11, ymin11, xmax11, ymax11)
|
|
|
|
- aa.append(aaa)
|
|
|
|
- res1['coordinates'] = aa
|
|
|
|
- new_test = {}
|
|
|
|
- if len(res1['words']) > 0:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][0]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 1:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][1]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 2:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][2]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 3:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][3]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test == {} or new_test['Score_structure'] == -1:
|
|
|
|
- if len(res1['words']) > 4:
|
|
|
|
- type_score_dict_ocrs['words'] = res1['words'][4]
|
|
|
|
- new_test = key_words(type_score_dict_ocrs)
|
|
|
|
- if new_test != {} and new_test['volume_structure'] != -1 and int(
|
|
|
|
- new_test['volume_structure'][0]['volume_total_score']) > 4: # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
- if int(new_test['volume_structure'][0]['volume_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
- new_test['volume_structure'][0]['volume_total_score'] = int(
|
|
|
|
- new_test['volume_structure'][0]['volume_total_score']) % 100
|
|
|
|
- new_test['volume_structure'][0]['bounding_box'] = composition_boxs[ij]
|
|
|
|
- new_test['volume_structure'][0]['label'] = 'composition'
|
|
|
|
- all_test.append(new_test)
|
|
|
|
- elif new_test != {} and new_test['volume_structure'] == -1 and new_test[
|
|
|
|
- 'Score_structure'] != -1 and int(
|
|
|
|
- new_test['Score_structure'][0]['item_total_score']) > 4: # 如果识别到分数,添加到输出信息;如果还没有识别到分数,默认没有分数
|
|
|
|
- if int(new_test['Score_structure'][0]['item_total_score']) > 200: # 暂定试卷分数都在200以内,超过200的表示识别错误
|
|
|
|
- new_test['Score_structure'][0]['item_total_score'] = int(
|
|
|
|
- new_test['Score_structure'][0]['item_total_score']) % 100
|
|
|
|
|
|
+ new_test = big_block_score(img0, xminss, yminss, composition_boxs[ij][2], composition_boxs[ij][3])
|
|
|
|
+ if new_test != -1:
|
|
new_test['Score_structure'][0]['bounding_box'] = composition_boxs[ij]
|
|
new_test['Score_structure'][0]['bounding_box'] = composition_boxs[ij]
|
|
new_test['Score_structure'][0]['label'] = 'composition'
|
|
new_test['Score_structure'][0]['label'] = 'composition'
|
|
all_test.append(new_test)
|
|
all_test.append(new_test)
|
|
@@ -682,7 +628,18 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
'number': dict(all_test[aaa])['Score_structure'][0]['item_N'],
|
|
'number': dict(all_test[aaa])['Score_structure'][0]['item_N'],
|
|
'score': dict(all_test[aaa])['Score_structure'][0]['item_total_score'],
|
|
'score': dict(all_test[aaa])['Score_structure'][0]['item_total_score'],
|
|
'number_score': dict(all_test[aaa])['Score_structure'][0]['item_score'],
|
|
'number_score': dict(all_test[aaa])['Score_structure'][0]['item_score'],
|
|
- 'counts': dict(all_test[aaa])['Score_structure'][0]['item_count']}
|
|
|
|
|
|
+ 'counts': dict(all_test[aaa])['Score_structure'][0]['item_count'],
|
|
|
|
+ 'type_score_box': dict(all_test[aaa])['Score_structure'][0]['type_box']}
|
|
|
|
+ Score_last.append(score_last_one)
|
|
|
|
+ continue
|
|
|
|
+ elif all_test[aaa]['Score_structure'] != -1 and all_test[aaa]['volume_structure'] == 1:
|
|
|
|
+ score_last_one = {'model_box': dict(all_test[aaa])['Score_structure'][0]['bounding_box'],
|
|
|
|
+ 'label': dict(all_test[aaa])['Score_structure'][0]['label'],
|
|
|
|
+ 'number': 10000,
|
|
|
|
+ 'score': dict(all_test[aaa])['Score_structure'][0]['item_total_score'],
|
|
|
|
+ 'number_score': dict(all_test[aaa])['Score_structure'][0]['item_score'],
|
|
|
|
+ 'counts': dict(all_test[aaa])['Score_structure'][0]['item_count'],
|
|
|
|
+ 'type_score_box': dict(all_test[aaa])['Score_structure'][0]['type_box']}
|
|
Score_last.append(score_last_one)
|
|
Score_last.append(score_last_one)
|
|
continue
|
|
continue
|
|
elif all_test[aaa]['Score_structure'] != -1 and all_test[aaa]['volume_structure'] != -1:
|
|
elif all_test[aaa]['Score_structure'] != -1 and all_test[aaa]['volume_structure'] != -1:
|
|
@@ -691,7 +648,8 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
'number': -1,
|
|
'number': -1,
|
|
'score': dict(all_test[aaa])['Score_structure'][0]['volume_total_score'],
|
|
'score': dict(all_test[aaa])['Score_structure'][0]['volume_total_score'],
|
|
'number_score': dict(all_test[aaa])['Score_structure'][0]['volume_score'],
|
|
'number_score': dict(all_test[aaa])['Score_structure'][0]['volume_score'],
|
|
- 'counts': dict(all_test[aaa])['Score_structure'][0]['volume_count']}
|
|
|
|
|
|
+ 'counts': dict(all_test[aaa])['Score_structure'][0]['volume_count'],
|
|
|
|
+ 'type_score_box': dict(all_test[aaa])['Score_structure'][0]['type_box']}
|
|
Score_last.append(score_last_one)
|
|
Score_last.append(score_last_one)
|
|
|
|
|
|
volume_last_one = {'volume_N': dict(all_test[aaa])['volume_structure'][0]['volume_N'],
|
|
volume_last_one = {'volume_N': dict(all_test[aaa])['volume_structure'][0]['volume_N'],
|
|
@@ -709,70 +667,202 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
'keyword_type': dict(all_test[aaa])['volume_structure'][0]['keyword_type']}
|
|
'keyword_type': dict(all_test[aaa])['volume_structure'][0]['keyword_type']}
|
|
volume_last.append(volume_last_one)
|
|
volume_last.append(volume_last_one)
|
|
continue
|
|
continue
|
|
- # Score_last = sorted(Score_last, key=lambda x: (
|
|
|
|
- # x['model_box'][0], x['model_box'][0] + x['model_box'][1], -x['score'])) # 按答题卡顺序输出
|
|
|
|
|
|
|
|
'''去重一个边框可能对应多个type_score的情况,英语单独解析'''
|
|
'''去重一个边框可能对应多个type_score的情况,英语单独解析'''
|
|
- len_Score_last = len(Score_last)
|
|
|
|
- if answer_sheet['subject'] == 'english':
|
|
|
|
- for i in range(len_Score_last):
|
|
|
|
- if Score_last[i]['label'] == 'cloze':
|
|
|
|
- if Score_last[i]['model_box'] in model_box2:
|
|
|
|
- index2 = model_box2.index(Score_last[i]['model_box'])
|
|
|
|
- score = Score_last[i]['score']
|
|
|
|
- if score < score2[index2] and score2[index2] < 20: # 去重,type_score多余的包含小题分数
|
|
|
|
- Score_last[i] = -1
|
|
|
|
- elif score < score2[index2] and score2[index2] > 20: # 去重,type_score多余的包含分卷分数
|
|
|
|
- Score_last[index2] = -1
|
|
|
|
- elif score > score2[index2] and score < 20: # 去重,type_score在不大于30分的情况下,暂定保留更大的分数
|
|
|
|
- Score_last[index2] = -1
|
|
|
|
- elif score > score2[index2] and score > 20: # 去重,type_score去除大于30分的重复分数
|
|
|
|
- Score_last[i] = -1
|
|
|
|
|
|
+ Score_last_Remove_Duplicates = OrderedDict()
|
|
|
|
+ for item in Score_last:
|
|
|
|
+ Score_last_Remove_Duplicates.setdefault(item['model_box'], {**item, })
|
|
|
|
+ Score_last_Remove_Duplicates = list(Score_last_Remove_Duplicates.values())
|
|
|
|
+ if len(Score_last_Remove_Duplicates) != len(Score_last):
|
|
|
|
+ len_Score_last = len(Score_last)
|
|
|
|
+ Score_last = sorted(Score_last, key=lambda x: (x['model_box'][0] + x['model_box'][1] + x['type_score_box'][0] + x['type_score_box'][1]),reverse=True)
|
|
|
|
+ if answer_sheet['subject'] == 'english': # 暂定英语只去除重复分数,不修改主观题边框
|
|
|
|
+ for i in range(len_Score_last-1, -1, -1):
|
|
|
|
+ if Score_last[i]['label'] == 'cloze':
|
|
|
|
+ model_box2 = []; score2 = []; num2 = []; type_score2 = []; temp22 = []
|
|
|
|
+ if Score_last[i]['model_box'] in model_box2:
|
|
|
|
+ index21 = model_box2.index(Score_last[i]['model_box'])
|
|
|
|
+ index2 = temp22[index21]
|
|
|
|
+ score = Score_last[i]['score']
|
|
|
|
+ if score < score2[index21] and score2[index21] < 20: # 去重,type_score多余的包含小题分数
|
|
|
|
+ Score_last[i] = -1
|
|
|
|
+ elif score < score2[index21] and score2[index21] > 20: # 去重,type_score多余的包含分卷分数
|
|
|
|
+ Score_last[index2] = -1
|
|
|
|
+ temp22[index21] = i
|
|
|
|
+ score2[index21] = Score_last[i]['score']
|
|
|
|
+ num2[index21] = Score_last[i]['number']
|
|
|
|
+ type_score2[index21] = Score_last[i]['type_score_box']
|
|
|
|
+ elif score > score2[index21] and score < 20: # 去重,type_score在不大于20分的情况下,暂定保留更大的分数
|
|
|
|
+ Score_last[index2] = -1
|
|
|
|
+ temp22[index21] = i
|
|
|
|
+ score2[index21] = Score_last[i]['score']
|
|
|
|
+ num2[index21] = Score_last[i]['number']
|
|
|
|
+ type_score2[index21] = Score_last[i]['type_score_box']
|
|
|
|
+ elif score > score2[index21] and score > 20: # 去重,type_score去除大于20分的重复分数
|
|
|
|
+ Score_last[i] = -1
|
|
|
|
+ else:
|
|
|
|
+ Score_last[i] = -1
|
|
else:
|
|
else:
|
|
- Score_last[i] = -1
|
|
|
|
|
|
+ model_box2.append(Score_last[i]['model_box'])
|
|
|
|
+ score2.append(Score_last[i]['score'])
|
|
|
|
+ num2.append(Score_last[i]['number'])
|
|
|
|
+ type_score2.append(Score_last[i]['type_score_box'])
|
|
|
|
+ temp22.append(i)
|
|
else:
|
|
else:
|
|
- model_box2.append(Score_last[i]['model_box'])
|
|
|
|
- score2.append(Score_last[i]['score'])
|
|
|
|
- else:
|
|
|
|
- if Score_last[i]['model_box'] in model_box2:
|
|
|
|
- index2 = model_box2.index(Score_last[i]['model_box'])
|
|
|
|
- score = Score_last[i]['score']
|
|
|
|
- if score < score2[index2]: # 去重,type_score多余的包含小题分数
|
|
|
|
- Score_last[i] = -1
|
|
|
|
- elif score > score2[index2]: # 去重,type_score在不大于30分的情况下,暂定保留更大的分数
|
|
|
|
- Score_last[index2] = -1
|
|
|
|
|
|
+ model_box2 = []; score2 = []; num2 = []; type_score2 = []; temp22 = []
|
|
|
|
+ if Score_last[i]['model_box'] in model_box2:
|
|
|
|
+ index21 = model_box2.index(Score_last[i]['model_box'])
|
|
|
|
+ index2 = temp22[index21]
|
|
|
|
+ score = Score_last[i]['score']
|
|
|
|
+ if score < score2[index21]: # 去重,暂定保留更大的分数
|
|
|
|
+ Score_last[i] = -1
|
|
|
|
+ elif score > score2[index21]: # 去重,暂定保留更大的分数
|
|
|
|
+ Score_last[index2] = -1
|
|
|
|
+ temp22[index21] = i
|
|
|
|
+ score2[index21] = Score_last[i]['score']
|
|
|
|
+ num2[index21] = Score_last[i]['number']
|
|
|
|
+ type_score2[index21] = Score_last[i]['type_score_box']
|
|
|
|
+ else:
|
|
|
|
+ Score_last[i] = -1
|
|
else:
|
|
else:
|
|
- Score_last[i] = -1
|
|
|
|
- else:
|
|
|
|
- model_box2.append(Score_last[i]['model_box'])
|
|
|
|
- score2.append(Score_last[i]['score'])
|
|
|
|
- else:
|
|
|
|
- for i in range(len_Score_last):
|
|
|
|
- if Score_last[i]['model_box'] in model_box2:
|
|
|
|
- index2 = model_box2.index(Score_last[i]['model_box'])
|
|
|
|
- score = Score_last[i]['score']
|
|
|
|
- if score < score2[index2] and score2[index2] < 30: # 去重,type_score多余的包含小题分数
|
|
|
|
- Score_last[i] = -1
|
|
|
|
- elif score < score2[index2] and score2[index2] > 30: # 去重,type_score多余的包含分卷分数
|
|
|
|
- Score_last[index2] = -1
|
|
|
|
- elif score > score2[index2] and score < 30: # 去重,type_score在不大于30分的情况下,暂定保留更大的分数
|
|
|
|
- Score_last[index2] = -1
|
|
|
|
- elif score > score2[index2] and score > 30: # 去重,type_score去除大于30分的重复分数
|
|
|
|
- Score_last[i] = -1
|
|
|
|
- else:
|
|
|
|
- Score_last[i] = -1
|
|
|
|
- else:
|
|
|
|
- model_box2.append(Score_last[i]['model_box'])
|
|
|
|
- score2.append(Score_last[i]['score'])
|
|
|
|
- while num_redundance < len_Score_last: # 去重一个边框可能对应多个type_score的情况
|
|
|
|
- if Score_last[num_redundance] == -1:
|
|
|
|
- del Score_last[num_redundance]
|
|
|
|
- len_Score_last = len_Score_last - 1
|
|
|
|
- else:
|
|
|
|
- num_redundance = num_redundance + 1
|
|
|
|
- # print(Score_last)
|
|
|
|
- # print(volume_last) # 分卷信息,暂不输出
|
|
|
|
- # print(answer_sheet['regions'])
|
|
|
|
|
|
+ model_box2.append(Score_last[i]['model_box'])
|
|
|
|
+ score2.append(Score_last[i]['score'])
|
|
|
|
+ num2.append(Score_last[i]['number'])
|
|
|
|
+ type_score2.append(Score_last[i]['type_score_box'])
|
|
|
|
+ temp22.append(i)
|
|
|
|
+ else: # 除去英语外的主观题边框修正
|
|
|
|
+ model_box2 = []; score2 = []; num2 = []; type_score2 = []; temp22 = []
|
|
|
|
+ for i in range(len_Score_last - 1, -1, -1): # 根据type_score切分
|
|
|
|
+ if Score_last[i]['label'] == 'solve' or Score_last[i]['label'] == 'solve0':
|
|
|
|
+ if Score_last[i]['model_box'] in model_box2 and type(Score_last[i]['number']) is not list:
|
|
|
|
+ index21 = model_box2.index(Score_last[i]['model_box'])
|
|
|
|
+ index2 = temp22[index21]
|
|
|
|
+ score = Score_last[i]['score']
|
|
|
|
+ num = Score_last[i]['number']
|
|
|
|
+ type_score = Score_last[i]['type_score_box']
|
|
|
|
+ del_box = 0
|
|
|
|
+ if num == -1: # 去除同一主观题内对应的多个边框内的小项分数
|
|
|
|
+ if 'ocr' in Score_last[index2]:
|
|
|
|
+ Score_last[index2] = -1
|
|
|
|
+ temp22[index21] = i
|
|
|
|
+ score2[index21] = Score_last[i]['score']
|
|
|
|
+ num2[index21] = Score_last[i]['number']
|
|
|
|
+ type_score2[index21] = Score_last[i]['type_score_box']
|
|
|
|
+ elif 'ocr' in Score_last[i]:
|
|
|
|
+ Score_last[i] = -1
|
|
|
|
+
|
|
|
|
+ else:
|
|
|
|
+ Score_last[i] = -1
|
|
|
|
+
|
|
|
|
+ elif num == 10000:
|
|
|
|
+ Score_last[i] = -1
|
|
|
|
+ elif num2[index21] == 10000 or num2[index21] == -1 and type_score[1] - type_score2[index21][1] > 100: # 同一主观题包含大题分数和小项分数,且大题分数位于边框中间,切分为两个主观题
|
|
|
|
+ yy_max.append(Score_last[i]['model_box'][3])
|
|
|
|
+ del_box = copy.deepcopy(Score_last[index2]['model_box'])
|
|
|
|
+ score_del.append(del_box)
|
|
|
|
+ Score_last[index2]['model_box'] = (
|
|
|
|
+ Score_last[index2]['model_box'][0], Score_last[index2]['model_box'][1],
|
|
|
|
+ Score_last[index2]['model_box'][2], type_score[1])
|
|
|
|
+ Score_last[i]['model_box'] = (
|
|
|
|
+ Score_last[i]['model_box'][0], type_score[1], Score_last[i]['model_box'][2],
|
|
|
|
+ Score_last[i]['model_box'][3])
|
|
|
|
+ score2[index21] = Score_last[i]['score']
|
|
|
|
+ num2[index21] = Score_last[i]['number']
|
|
|
|
+ type_score2[index21] = Score_last[i]['type_score_box']
|
|
|
|
+ temp22[index21] = i
|
|
|
|
+ elif score < score2[index21] and score2[index21] > 30: # 默认有效的分数值小于30分
|
|
|
|
+ Score_last[index2] = -1
|
|
|
|
+ temp22[index21] = i
|
|
|
|
+ score2[index21] = Score_last[i]['score']
|
|
|
|
+ num2[index21] = Score_last[i]['number']
|
|
|
|
+ type_score2[index21] = Score_last[i]['type_score_box']
|
|
|
|
+ elif score < 30 and score2[index21] < 30 and type_score[1] - type_score2[index21][1] > 100: # 同一主观题包含两个大题分数,且距离 >00 的情况下切分为两个主观题
|
|
|
|
+ yy_max.append(Score_last[i]['model_box'][3])
|
|
|
|
+ del_box = copy.deepcopy(Score_last[index2]['model_box'])
|
|
|
|
+ score_del.append(del_box)
|
|
|
|
+ Score_last[index2]['model_box'] = (
|
|
|
|
+ Score_last[index2]['model_box'][0], Score_last[index2]['model_box'][1],
|
|
|
|
+ Score_last[index2]['model_box'][2], type_score[1])
|
|
|
|
+ Score_last[i]['model_box'] = (
|
|
|
|
+ Score_last[i]['model_box'][0], type_score[1], Score_last[i]['model_box'][2],
|
|
|
|
+ Score_last[i]['model_box'][3])
|
|
|
|
+ score2[index21] = Score_last[i]['score']
|
|
|
|
+ num2[index21] = Score_last[i]['number']
|
|
|
|
+ type_score2[index21] = Score_last[i]['type_score_box']
|
|
|
|
+ temp22[index21] = i
|
|
|
|
+ elif score > 30 and score2[index21] > 30: # 默认有效的分数值小于30分
|
|
|
|
+ temp_del = i if score > score2[index21] else index2
|
|
|
|
+ Score_last[temp_del] = -1
|
|
|
|
+ if temp_del == index2:
|
|
|
|
+ temp22[index21] = i
|
|
|
|
+ score2[index21] = Score_last[i]['score']
|
|
|
|
+ num2[index21] = Score_last[i]['number']
|
|
|
|
+ type_score2[index21] = Score_last[i]['type_score_box']
|
|
|
|
+ elif score < 30 and score2[index21] < 30: # 多个分数小于30,且距离 <100 的情况下,删除
|
|
|
|
+ temp_del = i if score < score2[index21] else index2
|
|
|
|
+ Score_last[temp_del] = -1
|
|
|
|
+ if temp_del == index2:
|
|
|
|
+ temp22[index21] = i
|
|
|
|
+ score2[index21] = Score_last[i]['score']
|
|
|
|
+ num2[index21] = Score_last[i]['number']
|
|
|
|
+ type_score2[index21] = Score_last[i]['type_score_box']
|
|
|
|
+ else:
|
|
|
|
+ Score_last[i] = -1
|
|
|
|
+ else:
|
|
|
|
+ model_box2.append(Score_last[i]['model_box'])
|
|
|
|
+ score2.append(Score_last[i]['score'])
|
|
|
|
+ num2.append(Score_last[i]['number'])
|
|
|
|
+ type_score2.append(Score_last[i]['type_score_box'])
|
|
|
|
+ temp22.append(i)
|
|
|
|
+ for del_i in range(len_Score_last - 1, -1, -1):
|
|
|
|
+ if Score_last[del_i] == -1:
|
|
|
|
+ del Score_last[del_i]
|
|
|
|
+ if answer_sheet['subject'] != 'english':
|
|
|
|
+ Score_last = sorted(Score_last, key=lambda x: (x['model_box'][0], x['model_box'][0] + x['model_box'][1]),reverse=True)
|
|
|
|
+ temp33 = 0
|
|
|
|
+ len3 = len(Score_last)
|
|
|
|
+ for i in range(len3 - 1, -1, -1): # 根据type_score合并
|
|
|
|
+ if Score_last[i]['label'] == 'solve' or Score_last[i]['label'] == 'solve0':
|
|
|
|
+ num = Score_last[i]['number']
|
|
|
|
+ type_score = Score_last[i]['type_score_box']
|
|
|
|
+ if type(Score_last[i]['number']) is not list:
|
|
|
|
+ if num == 10000 or num == -1 or num < 4 and (Score_last[i]['label'] == 'solve' or Score_last[i]['label'] == 'solve0'): # 小题题号
|
|
|
|
+ temp3 = 100000
|
|
|
|
+ for indexi, model_box31 in enumerate(Score_last):
|
|
|
|
+ if indexi != i and ((type_score[0] and type_score[2]) in range(model_box31['model_box'][0] - 30,model_box31['model_box'][2])) and ((type_score[1] and type_score[3]) in range(model_box31['model_box'][1],model_box31['model_box'][3]+30)): # 根据小题边框的xmin与主观题xmin的差值判断为一栏,以及纵坐标差值判断条件
|
|
|
|
+ del_box = copy.deepcopy(Score_last[i]['model_box'])
|
|
|
|
+ score_del.append(del_box)
|
|
|
|
+ score_del.append(Score_last[indexi]['model_box'])
|
|
|
|
+ Score_last[indexi]['model_box'] = (
|
|
|
|
+ Score_last[indexi]['model_box'][0], Score_last[indexi]['model_box'][1],
|
|
|
|
+ Score_last[indexi]['model_box'][2], Score_last[i]['model_box'][3])
|
|
|
|
+ del Score_last[i]
|
|
|
|
+ break
|
|
|
|
+ temp31 = int(type_score[1] - model_box31['model_box'][3]) # 计算小题边框的ymin与主观题边框ymax的距离
|
|
|
|
+ if (type_score[0] in range(model_box31['model_box'][0] - 30,model_box31['model_box'][2])) and temp31 > -20 and temp31 < temp3: # 根据小题边框的xmin与主观题xmin的差值判断为一栏,以及纵坐标差值判断条件
|
|
|
|
+ temp3 = temp31
|
|
|
|
+ temp33 = indexi
|
|
|
|
+ yy_max.append(Score_last[i]['model_box'][3])
|
|
|
|
+ if indexi == len(Score_last) - 1:
|
|
|
|
+ del_box = copy.deepcopy(Score_last[temp33]['model_box'])
|
|
|
|
+ score_del.append(del_box)
|
|
|
|
+ score_del.append(Score_last[i]['model_box'])
|
|
|
|
+ Score_last[temp33]['model_box'] = (
|
|
|
|
+ Score_last[temp33]['model_box'][0], Score_last[temp33]['model_box'][1],
|
|
|
|
+ Score_last[temp33]['model_box'][2], Score_last[i]['model_box'][3])
|
|
|
|
+ del Score_last[i]
|
|
|
|
+ break
|
|
|
|
+ elif indexi == len(Score_last) - 1 and temp3 != 100000:
|
|
|
|
+ del_box = copy.deepcopy(Score_last[temp33]['model_box'])
|
|
|
|
+ score_del.append(del_box)
|
|
|
|
+ score_del.append(Score_last[i]['model_box'])
|
|
|
|
+ Score_last[temp33]['model_box'] = (
|
|
|
|
+ Score_last[temp33]['model_box'][0], Score_last[temp33]['model_box'][1],
|
|
|
|
+ Score_last[temp33]['model_box'][2], Score_last[i]['model_box'][3])
|
|
|
|
+ del Score_last[i]
|
|
|
|
+ break
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
if Score_last != []:
|
|
if Score_last != []:
|
|
for i in range(len(Score_last)): # 多选题题号和分数逐个显示
|
|
for i in range(len(Score_last)): # 多选题题号和分数逐个显示
|
|
@@ -806,7 +896,7 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
if Score_last[i]['number_score'] != -1:
|
|
if Score_last[i]['number_score'] != -1:
|
|
answer_sheet['regions'][j]['default_points'] = Score_last[i]['number_score']
|
|
answer_sheet['regions'][j]['default_points'] = Score_last[i]['number_score']
|
|
|
|
|
|
- elif num_choice > 1 or num_cloze >1:
|
|
|
|
|
|
+ elif num_choice > 1 or num_cloze > 1:
|
|
for i in range(len(Score_last)):
|
|
for i in range(len(Score_last)):
|
|
if Score_last[i]['label'] == 'choice':
|
|
if Score_last[i]['label'] == 'choice':
|
|
count_choice_m = 0
|
|
count_choice_m = 0
|
|
@@ -877,18 +967,18 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
'label': 'choice_m',
|
|
'label': 'choice_m',
|
|
'type_box': type_score_choice_m}
|
|
'type_box': type_score_choice_m}
|
|
test_result1['words'] = str()
|
|
test_result1['words'] = str()
|
|
- # try: # tr_OCR
|
|
|
|
- # image_choice = image_src.crop((type_score_choice_m[0], type_score_choice_m[1], type_score_choice_m[2], type_score_choice_m[3]))
|
|
|
|
- # res1 = tr.run(image_choice)
|
|
|
|
- # print('tr_OCR')
|
|
|
|
- # for t in range(len(res1)):
|
|
|
|
- # test_result1['words'] = test_result1['words'] + res1[t][1]
|
|
|
|
- # except Exception as e: # baidu_OCR
|
|
|
|
- # print('baidu_OCR')
|
|
|
|
- res1 = get_ocr_text_and_coordinate_in_google_format(
|
|
|
|
- img0[type_score_choice_m[1]:type_score_choice_m[3], type_score_choice_m[0]:type_score_choice_m[2]], ocr_accuracy=OCR_ACCURACY, language_type='CHN_ENG')
|
|
|
|
- for t in range(len(res1['words'])):
|
|
|
|
- test_result1['words'] = test_result1['words'] + res1['words'][t]
|
|
|
|
|
|
+ try: # tr_OCR
|
|
|
|
+ image_choice = image_src.crop((type_score_choice_m[0], type_score_choice_m[1], type_score_choice_m[2], type_score_choice_m[3]))
|
|
|
|
+ res1 = tr.run(image_choice)
|
|
|
|
+ print('tr_OCR')
|
|
|
|
+ for t in range(len(res1)):
|
|
|
|
+ test_result1['words'] = test_result1['words'] + res1[t][1]
|
|
|
|
+ except Exception as e: # baidu_OCR
|
|
|
|
+ print('baidu_OCR')
|
|
|
|
+ res1 = get_ocr_text_and_coordinate_in_google_format(
|
|
|
|
+ img0[type_score_choice_m[1]:type_score_choice_m[3], type_score_choice_m[0]:type_score_choice_m[2]], ocr_accuracy=OCR_ACCURACY, language_type='CHN_ENG')
|
|
|
|
+ for t in range(len(res1['words'])):
|
|
|
|
+ test_result1['words'] = test_result1['words'] + res1['words'][t]
|
|
if test_result1['words'] != {}:
|
|
if test_result1['words'] != {}:
|
|
test = key_words(test_result1)
|
|
test = key_words(test_result1)
|
|
choice_m_score = -1
|
|
choice_m_score = -1
|
|
@@ -914,21 +1004,39 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
|
|
|
|
'''分数与模型对应'''
|
|
'''分数与模型对应'''
|
|
ocr_flag = 0
|
|
ocr_flag = 0
|
|
- for i in range(len(answer_sheet['regions'])):
|
|
|
|
- for j in range(len(Score_last)):
|
|
|
|
- if (Score_last[j]['model_box'][0] == answer_sheet['regions'][i]['bounding_box']['xmin']
|
|
|
|
- and Score_last[j]['model_box'][1] == answer_sheet['regions'][i]['bounding_box']['ymin']
|
|
|
|
- and Score_last[j]['model_box'][2] == answer_sheet['regions'][i]['bounding_box']['xmax']
|
|
|
|
- and Score_last[j]['model_box'][3] == answer_sheet['regions'][i]['bounding_box']['ymax']):
|
|
|
|
- if Score_last[j]['number'] != -1:
|
|
|
|
|
|
+ for i in range(len(answer_sheet['regions'])-1, -1, -1):
|
|
|
|
+ for j in range(len(Score_last)-1, -1, -1):
|
|
|
|
+ if (int(Score_last[j]['model_box'][0]) == int(answer_sheet['regions'][i]['bounding_box']['xmin']) and
|
|
|
|
+ int(Score_last[j]['model_box'][1]) == int(answer_sheet['regions'][i]['bounding_box']['ymin']) and
|
|
|
|
+ int(Score_last[j]['model_box'][2]) == int(answer_sheet['regions'][i]['bounding_box']['xmax']) and
|
|
|
|
+ int(Score_last[j]['model_box'][3]) != int(answer_sheet['regions'][i]['bounding_box']['ymax'])) and (answer_sheet['regions'][i]['class_name'] == 'solve' or answer_sheet['regions'][i]['class_name'] == 'solve0'):
|
|
|
|
+ answer_sheet['regions'][i]['bounding_box']['ymax'] = int(Score_last[j]['model_box'][3])
|
|
|
|
+ if Score_last[j]['number'] == 10000:
|
|
|
|
+ answer_sheet['regions'][i]['number'] = -1 # 题号
|
|
|
|
+ elif Score_last[j]['number'] != -1 and Score_last[j]['number'] != 10000:
|
|
|
|
+ answer_sheet['regions'][i]['number'] = Score_last[j]['number'] # 题号
|
|
|
|
+ else:
|
|
|
|
+ answer_sheet['regions'][i]['number'] = -1 # 题号
|
|
|
|
+ if Score_last[j]['score'] != -1:
|
|
|
|
+ answer_sheet['regions'][i]['default_points'] = Score_last[j]['score']
|
|
|
|
+ if type(answer_sheet['regions'][i]['default_points']) is list and (
|
|
|
|
+ answer_sheet['regions'][i]['class_name'] == 'solve' or answer_sheet['regions'][i][
|
|
|
|
+ 'class_name'] == 'solve0'):
|
|
|
|
+ answer_sheet['regions'][i]['class_name'] = 'optional_solve'
|
|
|
|
+ elif 'default_points' not in answer_sheet['regions'][i].keys():
|
|
|
|
+ answer_sheet['regions'][i]['default_points'] = -1
|
|
|
|
+ del Score_last[j]
|
|
|
|
+ elif (int(Score_last[j]['model_box'][0]) == int(answer_sheet['regions'][i]['bounding_box']['xmin']) and
|
|
|
|
+ int(Score_last[j]['model_box'][1]) == int(answer_sheet['regions'][i]['bounding_box']['ymin']) and
|
|
|
|
+ int(Score_last[j]['model_box'][2]) == int(answer_sheet['regions'][i]['bounding_box']['xmax']) and
|
|
|
|
+ int(Score_last[j]['model_box'][3]) == int(answer_sheet['regions'][i]['bounding_box']['ymax'])):
|
|
|
|
+ if Score_last[j]['number'] == 10000:
|
|
|
|
+ answer_sheet['regions'][i]['number'] = -1 # 题号
|
|
|
|
+ elif Score_last[j]['number'] != -1 and Score_last[j]['number'] != 10000:
|
|
answer_sheet['regions'][i]['number'] = Score_last[j]['number'] # 题号
|
|
answer_sheet['regions'][i]['number'] = Score_last[j]['number'] # 题号
|
|
|
|
+ else:
|
|
|
|
+ answer_sheet['regions'][i]['number'] = -1 # 题号
|
|
if Score_last[j]['score'] != -1:
|
|
if Score_last[j]['score'] != -1:
|
|
- # score = Score_last[j]['score']
|
|
|
|
- # try:
|
|
|
|
- # length = len(answer_sheet['regions'][i]['number'])
|
|
|
|
- # answer_sheet['regions'][i]['default_points'] = length * [score]
|
|
|
|
- # except Exception:
|
|
|
|
- # answer_sheet['regions'][i]['default_points'] = score
|
|
|
|
answer_sheet['regions'][i]['default_points'] = Score_last[j]['score']
|
|
answer_sheet['regions'][i]['default_points'] = Score_last[j]['score']
|
|
if type(answer_sheet['regions'][i]['default_points']) is list and (
|
|
if type(answer_sheet['regions'][i]['default_points']) is list and (
|
|
answer_sheet['regions'][i]['class_name'] == 'solve' or answer_sheet['regions'][i][
|
|
answer_sheet['regions'][i]['class_name'] == 'solve' or answer_sheet['regions'][i][
|
|
@@ -937,8 +1045,37 @@ def get_sheet_number_total(answer_sheet, res, img0):
|
|
ocr_flag = 1
|
|
ocr_flag = 1
|
|
if 'type_score_ocr' in answer_sheet['regions'][i].keys():
|
|
if 'type_score_ocr' in answer_sheet['regions'][i].keys():
|
|
del answer_sheet['regions'][i]['type_score_ocr']
|
|
del answer_sheet['regions'][i]['type_score_ocr']
|
|
- # answer_sheet['regions'][i]['number_score'] = Score_last[j]['number_score'] # 小题分数
|
|
|
|
- # answer_sheet['regions'][i]['counts'] = Score_last[j]['counts'] # 小题个数
|
|
|
|
|
|
+ elif 'default_points' not in answer_sheet['regions'][i].keys():
|
|
|
|
+ answer_sheet['regions'][i]['default_points'] = -1
|
|
if ocr_flag == 0 and 'ocr' in Score_last[j]: # 没有识别到分数的模块添加type_score_ocr结果
|
|
if ocr_flag == 0 and 'ocr' in Score_last[j]: # 没有识别到分数的模块添加type_score_ocr结果
|
|
answer_sheet['regions'][i]['type_score_ocr'] = Score_last[j]['ocr']
|
|
answer_sheet['regions'][i]['type_score_ocr'] = Score_last[j]['ocr']
|
|
|
|
+ del Score_last[j]
|
|
|
|
+
|
|
|
|
+ if score_del != []: # del_model_boxs
|
|
|
|
+ for j in range(len(score_del)):
|
|
|
|
+ if score_del != [] and (score_del[j][0] == answer_sheet['regions'][i]['bounding_box']['xmin'] and score_del[j][1] ==
|
|
|
|
+ answer_sheet['regions'][i]['bounding_box']['ymin'] and score_del[j][2] ==
|
|
|
|
+ answer_sheet['regions'][i]['bounding_box']['xmax'] and score_del[j][3] ==
|
|
|
|
+ answer_sheet['regions'][i]['bounding_box']['ymax']):
|
|
|
|
+ del answer_sheet['regions'][i]
|
|
|
|
+ for jj in range(len(Score_last)): # add_model_boxs
|
|
|
|
+ answer_sheet_one = {}
|
|
|
|
+ answer_sheet_one['class_name'] = Score_last[jj]['label']
|
|
|
|
+ box_one = {}
|
|
|
|
+ box_one['xmin'] = int(Score_last[jj]['model_box'][0])
|
|
|
|
+ box_one['ymin'] = int(Score_last[jj]['model_box'][1])
|
|
|
|
+ box_one['xmax'] = int(Score_last[jj]['model_box'][2])
|
|
|
|
+ box_one['ymax'] = int(Score_last[jj]['model_box'][3])
|
|
|
|
+ answer_sheet_one['bounding_box'] = box_one
|
|
|
|
+ if Score_last[jj]['number'] == 10000:
|
|
|
|
+ answer_sheet_one['number'] = -1 # 题号
|
|
|
|
+ elif Score_last[jj]['number'] != -1 and Score_last[jj]['number'] != 10000:
|
|
|
|
+ answer_sheet_one['number'] = Score_last[jj]['number'] # 题号
|
|
|
|
+ else:
|
|
|
|
+ answer_sheet_one['number'] = -1 # 题号
|
|
|
|
+ if Score_last[jj]['score'] != -1:
|
|
|
|
+ answer_sheet_one['default_points'] = Score_last[jj]['score']
|
|
|
|
+ else:
|
|
|
|
+ answer_sheet_one['default_points'] = -1
|
|
|
|
+ answer_sheet['regions'].append(answer_sheet_one)
|
|
return answer_sheet
|
|
return answer_sheet
|