diff --git a/.gitignore b/.gitignore index b9d1b6b..dacde9c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,2 @@ **.idea -**__pycache__ -uploads -static +**__pycache__ \ No newline at end of file diff --git a/app.py b/app.py index c1ab522..c3eaf2a 100644 --- a/app.py +++ b/app.py @@ -1,9 +1,9 @@ -import os from flask import Flask, request, redirect, render_template from markupsafe import Markup -from werkzeug.utils import secure_filename -from main import run +import numpy as np +import cv2 as cv +from main import main UPLOAD_FOLDER = 'uploads' ALLOWED_EXTENSIONS = {'png', 'jpg', 'jpeg'} @@ -12,6 +12,12 @@ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER +def bytes_to_image(bytes): + np_arr = np.frombuffer(bytes, np.uint8) + arr = cv.imdecode(np_arr, cv.IMREAD_COLOR) + return arr + + def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS @@ -28,15 +34,11 @@ def upload_file(): return redirect(request.url) if file and allowed_file(file.filename): - filename = secure_filename(file.filename) - path = os.path.join(app.config['UPLOAD_FOLDER'], filename) - - file.save(path) + image = bytes_to_image(file.read()) tables = {} - for i, table in enumerate(run(path), 0): + for i, table in enumerate(main(image), 0): tables[i] = Markup(table.to_html(index=False)) - print(tables[i]) return render_template('main.html', tables=tables) diff --git a/main.py b/main.py index 85f1608..6e2754e 100644 --- a/main.py +++ b/main.py @@ -11,11 +11,10 @@ def main(image): yield df -def run(path='data/example1.jpg'): +if __name__ == '__main__': + path = 'data/example1.jpg' image = cv.imread(path) - yield from main(image) - -if __name__ == '__main__': - for t in run(): - print(t) + tables = extract(image) + for table in tables: + print(table)