Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from flask import Flask, request, redirect, url_for
from flask import send_from_directory
from werkzeug.utils import secure_filename
import autocorrect
import receiptparser
# Store pics temporarily on api server
OCR_SCRIPT = './ocr.sh'
UPLOAD_FOLDER = 'uploads/'
STATIC_FOLDER = '../web-client/'
ALLOWED_EXTENSIONS = set(['png','jpg','jpeg','gif'])
app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
autocorrect.init('wordlist.txt')
def allowed_file(filename):
return '.' in filename and \
filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS
def optical_character_recognition(imagepath):
""" Does OCR on an image and returns tuple:
(raw text, autocorrected text, parsed receipt data) """
# Process image with ImageMagick
tempimagepath = os.path.join(app.config['UPLOAD_FOLDER'], 'temp.png')
im_proc = subprocess.Popen(['convert',imagepath,'-resize','600x800',
'-blur','2','-lat','8x8-2%',tempimagepath],
stdout=subprocess.PIPE)