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')
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')
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)
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'))
# 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)