示例#1
0
文件: routes.py 项目: hates199/Pierre
def upload():
    if request.method == 'POST':
        # check if there is a file in the request
        if 'file' not in request.files:
            return render_template('upload.html',
                                   msg='No file selected',
                                   title='Upload')
        file = request.files['file']
        # if no file is selected
        if file.filename == '':
            return render_template('upload.html',
                                   msg='No file selected',
                                   title='Upload')

        if file and allowed_file(file.filename):
            filename = secure_filename(file.filename)
            file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
            option = request.form['options']
            lang = request.form.getlist('lang')
            # call the OCR function on it
            extracted_text = (ocr_core(file.filename, option,
                                       lang).split('\n'))
            # extract the text and display it
            return render_template('upload.html',
                                   msg='Successfully processed',
                                   extracted_text=extracted_text,
                                   img_src=filename,
                                   option=option,
                                   file=file.filename,
                                   lang=lang)
    elif request.method == 'GET':
        return render_template('upload.html', title='Upload')
示例#2
0
def predict():
    if request.method == 'POST':
        if request.files:
            image = request.files["image"]
            if image.filename == "":
                
                return render_template('index.html')

            if allowed_file(image.filename):
                text = reader.ocr_core(image)


                return render_template('index.html', result = text, img = image.filename)
            else:
                print("This file extension is not allowed")
                return redirect(request.url)

    return render_template('index.html')
示例#3
0
def upload_page():

    form = ArticleForm(request.form)
    if request.method == 'POST' and not form.validate():
        if 'file' not in request.files:
            return render_template('upload.html',
                                   msgforupload='No file selected')
        file = request.files['file']
        if file.filename == '':
            return render_template('upload.html',
                                   msgforupload='No file selected')

        if file and allowed_file(file.filename):
            extracted_text = ocr_core(file)
            form.body.data = extracted_text
            return render_template('upload.html',
                                   form=form,
                                   text=extracted_text)

    # elif request.method == 'GET':
    #     return render_template('upload.html')

    if request.method == 'POST' and form.validate():
        title = form.title.data

        body = form.body.data
        status = form.status.data
        # subbody = re.compile(r'<[^>]+>').sub('', body)
        cur = mysql.connection.cursor()

        cur.execute(
            "INSERT INTO ARTICLES(title,body, author, status) values ( %s,%s,%s, %s)",
            (title, body, session['username'], status))

        mysql.connection.commit()

        cur.close()

        flash('Article created', 'success')

        return redirect(url_for('dashboard'))
    return render_template('upload.html', form=form)
示例#4
0
def upload_page():
    if request.method == 'POST':
        # check if the post request has the file part
        if 'file' not in request.files:
            return render_template('upload.html', msg='No file selected')
        file = request.files['file']
        # if user does not select file, browser also
        # submit a empty part without filename
        if file.filename == '':
            return render_template('upload.html', msg='No file selected')

        if file and allowed_file(file.filename):
            file.save(os.path.join(os.getcwd() + UPLOAD_FOLDER, file.filename))

            # call the OCR function on it
            extracted_text = ocr_core(file)

            # extract the text and display it
            return render_template('upload.html',
                                   msg='Successfully processed',
                                   extracted_text=extracted_text,
                                   img_src=UPLOAD_FOLDER + file.filename)
    elif request.method == 'GET':
        return render_template('upload.html')
import mss
import mss.tools

with mss.mss() as sct:
    # Get information of monitor 2
    monitor_number = 1
    mon = sct.monitors[monitor_number]

    # The screen part to capture
    monitor = {
        "top": mon["top"] + 270,  # 100px from the top
        "left": 0 - 630,  # 100px from the left
        "width": 284,
        "height": 307,
        "mon": monitor_number,
    }
    output = "image.png".format(**monitor)

    # Grab the data
    sct_img = sct.grab(monitor)

    # Save to the picture file
    mss.tools.to_png(sct_img.rgb, sct_img.size, output=output)
    print(output)
    print(ocr.ocr_core('image.png'))

# import ocr

# print('Image contains...')
# print(ocr.ocr_core('image.png'))
示例#6
0
文件: main.py 项目: tenebris0011/OCR
# Misc imports
from seleniumMethods import screen
from parsing import parse
from parsing import botMessage
from ocr import greyscale
from ocr import ocr_core

if __name__ == '__main__':
    # URL = 'https://www.bestbuy.com/site/nvidia-geforce-rtx-3080-10gb-gddr6x-pci-express-4-0-graphics-card-titanium-and-black/6429440.p?skuId=6429440'
    # URL = 'https://store.ui.com/collections/unifi-protect-cameras/products/unifi-protect-g4-pro-camera'
    URL = 'https://store.ui.com/collections/unifi-protect-cameras/products/unifi-protect-g3-instant-camera'
    file = 'OCR.txt'
    screen(URL)
    greyscale('images/image.png')
    ocr_core(file, 'images/greyscale.png')
    msg = parse(file, URL)
    botMessage(msg)