diff --git a/sumasen_easyocr/views.py b/sumasen_easyocr/views.py index 96c8832..8c03f12 100644 --- a/sumasen_easyocr/views.py +++ b/sumasen_easyocr/views.py @@ -45,8 +45,28 @@ class FileUploadView(APIView): img = cv2.imread('/home/sumasen/django_easyocr_api/orc_api/sumasen_easyocr/uploaded' + up_file.name) #img = cv2.imread('/Users/mohamednouffer/workspace/akira_san/sumasen_ocr/sumasen_easyocr/uploaded' + up_file.name) custom_config = r'--oem 3 --psm 6' - res = pytesseract.image_to_data(img, lang='jpn', config=custom_config, output_type=Output.DICT) - app_json = json.dumps(res) + d = pytesseract.image_to_data(img, lang='jpn', config=custom_config, output_type=Output.DICT) + + n_boxes = len(d['level']) + + output = [] + + #print(d['level']) + for i in range(n_boxes): + (x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i]) + reg = dict({ + "text": d['text'][i], + "left": d['left'][i], + "top": d['top'][i], + "width": d['width'][i], + "height": d['height'][i], + "conf": d['conf'][i] + }) + output.append(reg) + + + + app_json = json.dumps(output) return Response(app_json, status.HTTP_201_CREATED) except Exception as e: diff --git a/templates/sumasen_easyocr/index.html b/templates/sumasen_easyocr/index.html index 007255c..2a7e78b 100644 --- a/templates/sumasen_easyocr/index.html +++ b/templates/sumasen_easyocr/index.html @@ -9,7 +9,7 @@ -{% comment %} http://aiworks.intranet.sumasen.net {% endcomment %} +{% comment %} http://aiworks.intranet.sumasen.net:8600/api/v1/upload {% endcomment %}