MiklX commited on
Commit
be5364e
·
1 Parent(s): ef100aa

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
app.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import cv2
2
+ import pytesseract
3
+ from pytesseract import Output
4
+ from flask import Flask, render_template_string
5
+ app = Flask(__name__)
6
+ @app.route('/')
7
+ def home():
8
+ image_path = 'https://prezentacii.org/upload/cloud/19/01/118181/images/screen7.jpg'
9
+ image = cv2.imread(image_path)
10
+ d = pytesseract.image_to_data(image, output_type=Output.DICT)
11
+ html = '<div style="position: relative;">'
12
+ html += f'<img src="{{ url_for("static", filename="{image_path}") }}" alt="image">'
13
+ n_boxes = len(d['text'])
14
+ for i in range(n_boxes):
15
+ if int(d['conf'][i]) > 60:
16
+ (x, y, w, h) = (d['left'][i], d['top'][i], d['width'][i], d['height'][i])
17
+ html += f'<div style="position: absolute; left: {x}px; top: {y}px;">{d["text"][i]}</div>'
18
+ html += '</div>'
19
+ return render_template_string(html)
20
+ if __name__ == '__main__':
21
+ app.run(host="0.0.0.0", port=7860, use_reloader=False)