views.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. # @Author : lightXu
  2. # @File : views.py
  3. # @Time : 2018/7/19 0019 下午 14:28
  4. import json
  5. import os
  6. import time
  7. import uuid
  8. import cv2
  9. import numpy as np
  10. import requests
  11. from PIL import Image
  12. from django.conf import settings
  13. from django.http import HttpResponse
  14. from django.shortcuts import render
  15. from django.views.decorators.csrf import csrf_exempt
  16. import segment.logging_config as logging
  17. from segment.form import UploadImageForm, FormulaUrlForm, UploadFileForm
  18. from segment.formula import formula_segment, formula_segment_and_show
  19. from segment.image_operation.utils import png_read
  20. from segment.image_operation.utils import write_single_img, resize_by_percent
  21. from segment.sheet_resolve.tools.utils import NpEncoder
  22. from segment.models import ExamImage
  23. from segment.server import get_exam_bbox_by_tesseract, get_exam_ocr, opencv2base64
  24. from segment.server import get_exam_box
  25. from segment.server import get_exam_ocr_by_penguin
  26. from segment.server import get_segment_by_ocr_once, get_exam_ocr_once
  27. from segment.server import save_pdf_image
  28. from segment.server import save_raw_image, save_raw_image_without_segment, ocr_login
  29. from segment.server import save_raw_image_in_jpeg
  30. logger = logging.getLogger(settings.LOGGING_TYPE)
  31. subject_id_dict = {0: 'unknown_subject',
  32. 3: 'math',
  33. 6: 'math_zxhx',
  34. 8: 'english',
  35. 9: 'chinese',
  36. 12: 'physics',
  37. 13: 'chemistry',
  38. 14: 'biology',
  39. 15: 'politics',
  40. 16: 'history',
  41. 17: 'geography',
  42. 18: 'science_comprehensive',
  43. 19: 'arts_comprehensive',
  44. 98: 'english_B',
  45. 99: 'english_T',
  46. }
  47. # Create your views here.
  48. def index(request):
  49. return render(request, 'exam_bbox.html')
  50. @csrf_exempt
  51. def upload_img(request):
  52. if request.method == 'POST':
  53. time_str = time.strftime('%Y-%m-%d', time.localtime(time.time()))
  54. form = UploadImageForm(request.POST, request.FILES)
  55. if form.is_valid():
  56. subject_id = int(form.cleaned_data['subject'])
  57. subject = subject_id_dict.get(subject_id)
  58. if not subject:
  59. subject = 'unknown_subject'
  60. upload_img_list = request.FILES.getlist('img_data')
  61. res_info_list = []
  62. is_success = 1
  63. for img in upload_img_list:
  64. start_time = time.time()
  65. raw_name = img.name
  66. save_path, _ = save_raw_image(subject, time_str, img, 'segment')
  67. try:
  68. img_instance = ExamImage(upload_date=time_str, raw_name=raw_name,
  69. save_path=save_path, subject_id=subject_id, subject=subject)
  70. img_instance.save()
  71. logger.info('{}试卷 {} 存储成功: {}'.format(subject, raw_name, save_path))
  72. except Exception as e:
  73. # traceback.print_exc()
  74. logger.info('{}试卷 {} 存储失败: {}'.format(subject, raw_name, e))
  75. status, bbox_info = get_exam_bbox_by_tesseract(raw_name, save_path, subject)
  76. is_success = status
  77. end_time = time.time()
  78. cost_time = '{:.2f}s'.format(float(end_time - start_time))
  79. bbox_info.update({'cost_time': cost_time})
  80. res_info_list.append(bbox_info)
  81. res = {'isSuccess': is_success, 'imgs_info': res_info_list}
  82. res_json = json.dumps(res, ensure_ascii=False, cls=NpEncoder)
  83. logger.info('segment_info: {}'.format(res_json))
  84. return HttpResponse(res_json)
  85. else:
  86. error_json = form.errors.as_json()
  87. is_success = 99
  88. res = {'isSuccess': is_success, 'error': error_json}
  89. return HttpResponse('{}'.format(res))
  90. else:
  91. form = UploadImageForm()
  92. return render(request, 'exam_bbox.html', {'form': form})
  93. @csrf_exempt # 试卷分题
  94. def analysis_exam_view(request):
  95. if request.method == 'POST':
  96. time_str = time.strftime('%Y-%m-%d', time.localtime(time.time()))
  97. form = UploadImageForm(request.POST, request.FILES)
  98. if form.is_valid():
  99. subject_id = int(form.cleaned_data['subject'])
  100. subject = subject_id_dict.get(subject_id)
  101. if not subject:
  102. subject = 'unknown_subject'
  103. upload_img_list = request.FILES.getlist('img_data')
  104. res_info_list = []
  105. error_info = ''
  106. is_success = 1
  107. try:
  108. access_token = ocr_login()
  109. for img in upload_img_list:
  110. start_time = time.time()
  111. raw_name = img.name
  112. save_path = ''
  113. bin_parts_img_list = []
  114. opencv_img = ''
  115. try:
  116. # save_path, bin_parts_img_list = save_raw_image(subject, time_str, img, 'segment')
  117. save_path, opencv_img, _ = save_raw_image_without_segment(subject, time_str, img, 'segment')
  118. img_instance = ExamImage(upload_date=time_str, raw_name=raw_name,
  119. save_path=save_path, subject_id=subject_id, subject=subject)
  120. img_instance.save()
  121. logger.info('{}试卷: {} 存储成功: {}'.format(subject, raw_name, save_path))
  122. except Exception as e:
  123. # traceback.print_exc()
  124. logger.info('{}试卷: {} 存储失败: {}'.format(subject, raw_name, e))
  125. # status, bbox_info = get_exam_box(raw_name, bin_parts_img_list, save_path, subject, access_token)
  126. status, bbox_info = get_segment_by_ocr_once(opencv_img, access_token, subject, save_path, raw_name)
  127. is_success = status
  128. end_time = time.time()
  129. cost_time = '{:.2f}s'.format(float(end_time - start_time))
  130. bbox_info.update({'cost_time': cost_time})
  131. res_info_list.append(bbox_info)
  132. except Exception as e:
  133. logger.info('ocr error: {}'.format(e))
  134. is_success = 0
  135. error_info = 'ocr error'
  136. res = {'isSuccess': is_success, 'imgs_info': res_info_list}
  137. if error_info:
  138. res['error'] = error_info
  139. res_json = json.dumps(res, ensure_ascii=False, cls=NpEncoder)
  140. logger.info('segment_info: {}\n'.format(res_json))
  141. return HttpResponse(res_json)
  142. else:
  143. error_json = form.errors.as_json()
  144. is_success = 99
  145. res = {'isSuccess': is_success, 'error': error_json}
  146. return HttpResponse('{}'.format(res))
  147. else:
  148. form = UploadImageForm()
  149. return render(request, 'exam_bbox.html', {'form': form})
  150. @csrf_exempt # 试卷识别文字
  151. def ocr_exam_view(request):
  152. if request.method == 'POST':
  153. time_str = time.strftime('%Y-%m-%d', time.localtime(time.time()))
  154. form = UploadImageForm(request.POST, request.FILES)
  155. if form.is_valid():
  156. subject_id = int(form.cleaned_data['subject'])
  157. subject = subject_id_dict.get(subject_id)
  158. if not subject:
  159. subject = 'unknown_subject'
  160. upload_img_list = request.FILES.getlist('img_data')
  161. res_info_list = []
  162. error_info = ''
  163. is_success = 1
  164. opencv_img = ''
  165. try:
  166. access_token = ocr_login()
  167. for img in upload_img_list:
  168. start_time = time.time()
  169. raw_name = img.name
  170. img_mem_size = img.size
  171. save_path = ''
  172. bin_parts_img_list = []
  173. try:
  174. save_path, opencv_img, _, = save_raw_image_without_segment(subject, time_str, img, 'ocr')
  175. img_instance = ExamImage(upload_date=time_str, raw_name=raw_name,
  176. save_path=save_path, subject_id=subject_id, subject=subject)
  177. img_instance.save()
  178. logger.info('{}试卷: {} 存储成功: {}'.format(subject, raw_name, save_path))
  179. except Exception as e:
  180. # traceback.print_exc()
  181. logger.info('{}试卷: {} 存储失败: {}'.format(subject, raw_name, e))
  182. if subject == 'english' or subject == 'english_B': # 英语不分栏, 直接识别
  183. bin_parts_img_list = [{'img_part': opencv2base64(opencv_img)}]
  184. status, text_info = get_exam_ocr(raw_name, bin_parts_img_list, save_path, subject, access_token)
  185. elif subject == 'english_T':
  186. status, text_info = get_exam_ocr_by_penguin(raw_name, opencv_img, img_mem_size, save_path, subject)
  187. else:
  188. # 识别并分栏
  189. status, text_info = get_exam_ocr_once(opencv_img, access_token, subject, save_path, raw_name)
  190. is_success = status
  191. end_time = time.time()
  192. cost_time = '{:.2f}s'.format(float(end_time - start_time))
  193. text_info.update({'cost_time': cost_time})
  194. res_info_list.append(text_info)
  195. except Exception as e:
  196. logger.info('ocr error: {}'.format(e))
  197. is_success = 0
  198. error_info = 'ocr error'
  199. res = {'isSuccess': is_success, 'imgs_info': res_info_list}
  200. if error_info:
  201. res['error'] = error_info
  202. res_json = json.dumps(res, ensure_ascii=False, cls=NpEncoder)
  203. logger.info('text_info: {}\n'.format(res_json))
  204. return HttpResponse(res_json)
  205. else:
  206. error_json = form.errors.as_json()
  207. is_success = 99
  208. res = {'isSuccess': is_success, 'error': error_json}
  209. return HttpResponse('{}'.format(res))
  210. else:
  211. form = UploadImageForm()
  212. return render(request, 'exam_bbox.html', {'form': form})
  213. @csrf_exempt
  214. def ocr_exam_view_of_pdf(request):
  215. if request.method == 'POST':
  216. time_str = time.strftime('%Y-%m-%d', time.localtime(time.time()))
  217. form = UploadFileForm(request.POST, request.FILES)
  218. if form.is_valid():
  219. subject_id = int(form.cleaned_data['subject'])
  220. subject = subject_id_dict.get(subject_id)
  221. if not subject:
  222. subject = 'unknown_subject'
  223. pdf_file = request.FILES.get('img_data')
  224. suffix = pdf_file.name
  225. if suffix[-4:] == '.pdf':
  226. upload_img_list, images_list = save_pdf_image(pdf_file, subject, time_str)
  227. res_info_list = []
  228. error_info = ''
  229. is_success = 1
  230. try:
  231. access_token = ocr_login()
  232. for pdf_img_index, img_path in enumerate(sorted(upload_img_list)):
  233. start_time = time.time()
  234. save_name = ''
  235. try:
  236. save_name = '{}_{}_{:04d}'.format(suffix[:-4], 'pdf', pdf_img_index+1)
  237. img_instance = ExamImage(upload_date=time_str, raw_name=save_name,
  238. save_path=img_path, subject_id=subject_id, subject=subject)
  239. img_instance.save()
  240. logger.info('{}试卷: {} 存储成功: {}'.format(subject, save_name, img_path))
  241. except Exception as e:
  242. # traceback.print_exc()
  243. logger.info('{}试卷: {} 存储失败: {}'.format(subject, save_name, e))
  244. status, text_info = get_exam_ocr_once(images_list[pdf_img_index], access_token, subject, img_path, save_name)
  245. is_success = status
  246. end_time = time.time()
  247. cost_time = '{:.2f}s'.format(float(end_time - start_time))
  248. text_info.update({'cost_time': cost_time})
  249. res_info_list.append(text_info)
  250. except Exception as e:
  251. logger.info('ocr error: {}'.format(e))
  252. is_success = 0
  253. error_info = 'ocr error'
  254. res = {'isSuccess': is_success, 'imgs_info': res_info_list}
  255. if error_info:
  256. res['error'] = error_info
  257. res_json = json.dumps(res, ensure_ascii=False, cls=NpEncoder)
  258. logger.info('text_info: {}\n'.format(res_json))
  259. return HttpResponse(res_json)
  260. else:
  261. raise ValueError('{} is not a pdf file'.format(suffix))
  262. else:
  263. error_json = form.errors.as_json()
  264. is_success = 99
  265. res = {'isSuccess': is_success, 'error': error_json}
  266. return HttpResponse('{}'.format(res))
  267. else:
  268. form = UploadImageForm()
  269. return render(request, 'exam_bbox.html', {'form': form})
  270. @csrf_exempt
  271. def formula_analysis_show(request):
  272. if request.method == 'POST':
  273. time_str = time.strftime('%Y-%m-%d', time.localtime(time.time()))
  274. form = UploadImageForm(request.POST, request.FILES)
  275. if form.is_valid():
  276. subject_id = int(form.cleaned_data['subject'])
  277. subject = subject_id_dict.get(subject_id)
  278. if not subject:
  279. subject = 'unknown_subject'
  280. img = request.FILES.get('img_data')
  281. error_info = ''
  282. text_info = ''
  283. raw_text_info = ''
  284. img_url_path = ''
  285. raw_name = img.name
  286. img_height = 0
  287. try:
  288. start_time = time.time()
  289. save_path = ''
  290. opencv_img = ''
  291. try:
  292. save_path, opencv_img, img_url_path = save_raw_image_without_segment(subject, time_str, img, 'formula')
  293. img_instance = ExamImage(upload_date=time_str, raw_name=raw_name,
  294. save_path=save_path, subject_id=subject_id, subject=subject)
  295. img_instance.save()
  296. logger.info('{}试卷: {} 存储成功: {}'.format(subject, raw_name, save_path))
  297. except Exception as e:
  298. # traceback.print_exc()
  299. logger.info('{}试卷: {} 存储失败: {}'.format(subject, raw_name, e))
  300. access_token = ocr_login()
  301. text_info, raw_text_info, img_height = formula_segment_and_show.segment(opencv_img, save_path,
  302. access_token)
  303. is_success = 1
  304. end_time = time.time()
  305. cost_time = '{:.2f}s'.format(float(end_time - start_time))
  306. except Exception as e:
  307. logger.info('ocr error: {}'.format(e))
  308. is_success = 0
  309. error_info = 'analysis error'
  310. txt_url = os.path.join('/segment/', raw_name.replace('.jpg', '.html'))
  311. chars_lines = [ele for ele in text_info]
  312. chars_str = ''.join(chars_lines)
  313. raw_chars_lines = [ele for ele in raw_text_info]
  314. raw_chars_str = ''.join(raw_chars_lines)
  315. height = 300
  316. if img_height > height:
  317. height = img_height + 50
  318. res_dict = {'url': img_url_path, 'txt_url': txt_url,
  319. 'texts': chars_str,
  320. 'raw_texts': raw_chars_str,
  321. 'name': raw_name.replace('.jpg', ''),
  322. 'img_height': height,
  323. 'text_height': 1.5 * height
  324. }
  325. return render(request, 'showimg.html', res_dict)
  326. # return HttpResponse(res_json)
  327. else:
  328. error_json = form.errors.as_json()
  329. is_success = 99
  330. res = {'is_success': is_success, 'error': error_json}
  331. return HttpResponse('{}'.format(res))
  332. else:
  333. img_form = UploadImageForm()
  334. formula_form = FormulaUrlForm()
  335. return render(request, 'uploadimg.html', {'img_form': img_form,
  336. 'formula_form': formula_form})
  337. @csrf_exempt
  338. def ai_formula_analysis_show(request):
  339. if request.method == 'POST':
  340. time_str = time.strftime('%Y-%m-%d', time.localtime(time.time()))
  341. form = UploadImageForm(request.POST, request.FILES)
  342. if form.is_valid():
  343. subject_id = int(form.cleaned_data['subject'])
  344. subject = subject_id_dict.get(subject_id)
  345. if not subject:
  346. subject = 'unknown_subject'
  347. img = request.FILES.get('img_data')
  348. error_info = ''
  349. text_info = ''
  350. raw_text_info = ''
  351. img_url_path = ''
  352. raw_name = img.name
  353. img_height = 0
  354. try:
  355. start_time = time.time()
  356. save_path = ''
  357. opencv_img = ''
  358. try:
  359. save_path, img_url_path, opencv_img = \
  360. save_raw_image_in_jpeg(subject, time_str, img, 'formula')
  361. img_instance = ExamImage(upload_date=time_str, raw_name=raw_name,
  362. save_path=save_path, subject_id=subject_id, subject=subject)
  363. img_instance.save()
  364. logger.info('{}试卷: {} 存储成功: {}'.format(subject, raw_name, save_path))
  365. except Exception as e:
  366. # traceback.print_exc()
  367. logger.info('{}试卷: {} 存储失败: {}'.format(subject, raw_name, e))
  368. # 对整体图像大小进行resize
  369. img_height, w = opencv_img.shape[0], opencv_img.shape[1]
  370. save_path = save_path.replace('\\', '/')
  371. formula_img_name = save_path.split('/')[-1]
  372. formula_name_txt_path = save_path.replace('.jpg', '.txt')
  373. with open(formula_name_txt_path, 'w', encoding='utf-8') as writer:
  374. writer.writelines(formula_img_name + '\n')
  375. save_dir = save_path.replace(save_path.split('/')[-1], '')[:-1]
  376. text_info, raw_text_info = formula_segment_and_show\
  377. .get_latex_by_ai_formula(save_dir, formula_name_txt_path)
  378. is_success = 1
  379. end_time = time.time()
  380. cost_time = '{:.2f}s'.format(float(end_time - start_time))
  381. except Exception as e:
  382. logger.info('ocr login error: {}'.format(e))
  383. is_success = 0
  384. error_info = 'analysis error'
  385. txt_url = os.path.join('/segment/', raw_name.replace('.jpg', '.html'))
  386. chars_lines = [ele for ele in text_info]
  387. chars_str = ''.join(chars_lines)
  388. raw_chars_lines = [ele for ele in raw_text_info]
  389. raw_chars_str = ''.join(raw_chars_lines)
  390. height = 300
  391. if img_height > height:
  392. height = img_height + 50
  393. res_dict = {'url': img_url_path, 'txt_url': txt_url,
  394. 'texts': chars_str,
  395. 'raw_texts': raw_chars_str,
  396. 'name': raw_name.replace('.jpg', ''),
  397. 'img_height': height,
  398. 'text_height': 1.5 * height
  399. }
  400. return render(request, 'showimg.html', res_dict)
  401. # return HttpResponse(res_json)
  402. else:
  403. error_json = form.errors.as_json()
  404. is_success = 99
  405. res = {'is_success': is_success, 'error': error_json}
  406. return HttpResponse('{}'.format(res))
  407. else:
  408. img_form = UploadImageForm()
  409. formula_form = FormulaUrlForm()
  410. return render(request, 'uploadimg.html', {'img_form': img_form,
  411. 'formula_form': formula_form})
  412. @csrf_exempt
  413. def formula_analysis(request):
  414. if request.method == 'POST':
  415. time_str = time.strftime('%Y-%m-%d', time.localtime(time.time()))
  416. form = FormulaUrlForm(request.POST, )
  417. if form.is_valid():
  418. image_url = form.cleaned_data['img_url']
  419. error_info = ''
  420. text_info = ''
  421. try:
  422. save_path = ''
  423. r = requests.get(image_url, timeout=3)
  424. save_dir = os.path.join(settings.MEDIA_ROOT, 'formula', time_str)
  425. if not os.path.exists(save_dir):
  426. os.makedirs(save_dir)
  427. if '.png' in image_url:
  428. ext = 'png'
  429. file_name = '{}.{}'.format(uuid.uuid4().hex[:10], ext)
  430. save_path = os.path.join(save_dir, file_name)
  431. with open(save_path, 'wb') as f:
  432. f.write(r.content)
  433. open_cv_image = png_read(save_path)
  434. else:
  435. ext = 'jpg'
  436. file_name = '{}.{}'.format(uuid.uuid4().hex[:10], ext)
  437. save_path = os.path.join(save_dir, file_name)
  438. with open(save_path, 'wb') as f:
  439. f.write(r.content)
  440. open_cv_image = cv2.imread(save_path)
  441. access_token = ocr_login()
  442. text_info, raw_text_info = formula_segment.segment(open_cv_image, save_path, access_token)
  443. txt_path = save_path[:-3] + 'txt'
  444. with open(txt_path, 'w') as f:
  445. f.writelines(text_info)
  446. is_success = 1
  447. except Exception as e:
  448. logger.info('analysis error: {}'.format(e))
  449. is_success = 0
  450. error_info = 'analysis error: {}'.format(e)
  451. chars_lines = [ele for ele in text_info]
  452. chars_str = ''.join(chars_lines)
  453. res_dict = {'image_url': image_url,
  454. 'texts': chars_str,
  455. 'is_success': is_success
  456. }
  457. if error_info:
  458. res_dict['error'] = error_info
  459. res_json = json.dumps(res_dict, ensure_ascii=False, cls=NpEncoder)
  460. return HttpResponse(res_json)
  461. else:
  462. error_json = form.errors.as_json()
  463. is_success = 99
  464. res = {'is_success': is_success, 'error': error_json}
  465. return HttpResponse('{}'.format(res))
  466. else:
  467. formula_form = FormulaUrlForm()
  468. img_form = UploadImageForm()
  469. return render(request, 'uploadimg.html', {'img_form': img_form,
  470. 'formula_form': formula_form})
  471. @csrf_exempt
  472. def exam_analysis_show(request):
  473. if request.method == 'POST':
  474. time_str = time.strftime('%Y-%m-%d', time.localtime(time.time()))
  475. form = UploadImageForm(request.POST, request.FILES)
  476. if form.is_valid():
  477. subject_id = int(form.cleaned_data['subject'])
  478. subject = subject_id_dict.get(subject_id)
  479. if not subject:
  480. subject = 'unknown_subject'
  481. img = request.FILES.get('img_data')
  482. img_url_path = ''
  483. raw_name = img.name
  484. img_height = 0
  485. bbox_info = ''
  486. save_path = ''
  487. try:
  488. save_path, bin_parts_img_list, img_url_path = save_raw_image(subject, time_str, img, 'segment')
  489. img_instance = ExamImage(upload_date=time_str, raw_name=raw_name,
  490. save_path=save_path, subject_id=subject_id, subject=subject)
  491. img_instance.save()
  492. access_token = ocr_login()
  493. status, bbox_info = get_exam_box(raw_name, bin_parts_img_list, save_path, subject, access_token)
  494. except Exception as e:
  495. logger.info('ocr login error: {}'.format(e))
  496. is_success = 0
  497. error_info = 'analysis error'
  498. raw_img = Image.open(img) # 读取上传的网络图像
  499. open_cv_image = np.array(raw_img)
  500. show_ratio = 0.2
  501. open_cv_image = resize_by_percent(open_cv_image, show_ratio)
  502. for ele in bbox_info['coordinate']:
  503. xmin = int(ele[0])*show_ratio
  504. ymin = int(ele[1])*show_ratio
  505. xmax = int(ele[2])*show_ratio
  506. ymax = int(ele[3])*show_ratio
  507. cv2.rectangle(open_cv_image, (int(xmin), int(ymin)), (int(xmax), int(ymax)), (0, 255, 0), 1)
  508. write_single_img(open_cv_image, save_path)
  509. height, width = open_cv_image.shape[0], open_cv_image.shape[1]
  510. if img_height > height:
  511. height = img_height + 50
  512. res_dict = {'url': img_url_path,
  513. 'texts': bbox_info,
  514. 'raw_texts': bbox_info,
  515. 'name': raw_name.replace('.jpg', ''),
  516. 'img_height': height,
  517. 'text_height': 1.5 * height
  518. }
  519. return render(request, 'showimg.html', res_dict)
  520. # return HttpResponse(res_json)
  521. else:
  522. error_json = form.errors.as_json()
  523. is_success = 99
  524. res = {'is_success': is_success, 'error': error_json}
  525. return HttpResponse('{}'.format(res))
  526. else:
  527. img_form = UploadImageForm()
  528. return render(request, 'exam_bbox.html', {'form': img_form})