vk commited on
Commit
9568953
·
1 Parent(s): 1bc44fc

bounding box added

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -19,8 +19,11 @@ def get_response(input_img):
19
 
20
  '''
21
 
 
 
22
  if hasattr(input_img,'shape'):
23
  src_img=input_img.copy()
 
24
  outputs=text_detector.predict([input_img])
25
 
26
 
@@ -41,12 +44,12 @@ def get_response(input_img):
41
  # Find bounding box and crop
42
  x, y, w, h = cv2.boundingRect(pts)
43
  cropped = result[y:y + h, x:x + w, :]
44
- # cv2.polylines(src_im, [box], True, color=(255, 255, 0), thickness=2)
45
  # cv2.imwrite(f"cropped/output_{i}_{j}.jpg",cropped)
46
  texts.append(ocr.predict([cropped])[0])
47
  j += 1
48
 
49
- return "\n".join(texts)
50
 
51
 
52
  if __name__ == "__main__":
@@ -55,7 +58,7 @@ if __name__ == "__main__":
55
  iface = gr.Interface(
56
  fn=get_response,
57
  inputs=gr.Image(type="numpy"), # Accepts image input
58
- outputs=gr.Textbox(),
59
  title="Latin Text Detection & Recognition",
60
  description="Upload images for fast & accurate English(Latin) OCR. Works best with image format of invoice, documents"
61
  )
 
19
 
20
  '''
21
 
22
+ src_img = None
23
+ out_img = None
24
  if hasattr(input_img,'shape'):
25
  src_img=input_img.copy()
26
+ out_img=input_img.copy()
27
  outputs=text_detector.predict([input_img])
28
 
29
 
 
44
  # Find bounding box and crop
45
  x, y, w, h = cv2.boundingRect(pts)
46
  cropped = result[y:y + h, x:x + w, :]
47
+ cv2.polylines(out_img,[pts], True, color=(255, 255, 0), thickness=2)
48
  # cv2.imwrite(f"cropped/output_{i}_{j}.jpg",cropped)
49
  texts.append(ocr.predict([cropped])[0])
50
  j += 1
51
 
52
+ return "\n".join(texts),out_img
53
 
54
 
55
  if __name__ == "__main__":
 
58
  iface = gr.Interface(
59
  fn=get_response,
60
  inputs=gr.Image(type="numpy"), # Accepts image input
61
+ outputs=[gr.Textbox(),gr.Image(type="numpy")],
62
  title="Latin Text Detection & Recognition",
63
  description="Upload images for fast & accurate English(Latin) OCR. Works best with image format of invoice, documents"
64
  )