-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Didarul Amin
committed
Oct 3, 2019
1 parent
f8a3b4d
commit 4ce1359
Showing
12 changed files
with
635 additions
and
675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
# Luz-Glass | ||
# LUZ GLASS (OCR) | ||
|
||
## A world made with words for those visually impaired or blind. | ||
|
||
#### Browser based (Web RTC) OCR App.([DEMO](https://youtu.be/Bs7ncqaVBnU)) | ||
|
||
##### Using OCR to read text from images. | ||
|
||
[![Luz Glass | Web RTC](https://img.youtube.com/vi/Bs7ncqaVBnU/maxresdefault.jpg)](https://youtu.be/Bs7ncqaVBnU) | ||
[Watch the DEMO](https://youtu.be/Bs7ncqaVBnU) | ||
|
||
============================================= | ||
##### Deploy (Using Docker Compose) | ||
`cd docker` | ||
|
||
`docker-compose up -d` | ||
|
||
`visit: http://localhost:5005` | ||
|
||
##### Deploy (Native) | ||
`cd docker` | ||
|
||
`pip install -r requirements.txt ` | ||
|
||
`cd ..` | ||
|
||
`python server.py` | ||
|
||
`visit: http://localhost:5005` | ||
|
||
|
||
#### TO DO | ||
- Wire it up to ESP32 and audio. | ||
|
||
|
||
> FULL CREDIT GOES TO GOOGLE FOR TESSERACT LIBRARY. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
""" | ||
Luz Glass (OCR) | ||
A world made with words for those visually impaired or blinds. | ||
""" | ||
import os | ||
from flask import Flask, jsonify, request, url_for, render_template | ||
import urllib.request | ||
from flask_cors import CORS | ||
import re, time, base64 | ||
from io import BytesIO | ||
|
||
try: | ||
from PIL import Image | ||
except ImportError: | ||
import Image | ||
import pytesseract | ||
|
||
def sky_ocr(filename): | ||
""" | ||
This function will handle the core OCR processing of images. | ||
""" | ||
text = pytesseract.image_to_string(Image.open(filename)) # We'll use Pillow's Image class to open the image and pytesseract to detect the string in the image | ||
return text # Then we will print the text in the image | ||
|
||
|
||
# Convert Base64 Image to PNG | ||
def getI420FromBase64(codec): | ||
print(codec) | ||
base64_data = re.sub('^data:image/.+;base64,', '', codec) | ||
byte_data = base64.b64decode(base64_data) | ||
image_data = BytesIO(byte_data) | ||
img = Image.open(image_data) | ||
t = time.time() | ||
img.save('images/temp.png', "PNG") | ||
|
||
app = Flask(__name__, static_url_path='/static') | ||
CORS(app) | ||
|
||
@app.route('/') | ||
def home_page(): | ||
return render_template('index.html') | ||
|
||
@app.route('/api', methods=['GET', 'POST']) | ||
def ocr_api(): | ||
post_content = request.args.get('url') | ||
if not request.args.get('url'): | ||
post_content = request.form['url'] | ||
if not post_content: | ||
return jsonify({"Error": 'No URL entered'}) | ||
try: | ||
getI420FromBase64(request.form['url']) | ||
extracted_text = sky_ocr('images/temp.png') | ||
return jsonify({"data": extracted_text}) | ||
except Exception as e: | ||
return jsonify({"Error": 'There was an error while processing your request. ' + str(e)}) | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=False, host='0.0.0.0', port=5005) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
FROM ubuntu:16.04 | ||
|
||
MAINTAINER DIDARUL "" | ||
|
||
RUN apt -y update &&\ | ||
apt -y install python3 python3-pip &&\ | ||
apt -y install libgtk2.0-dev | ||
|
||
RUN python3 -m pip install --upgrade pip | ||
|
||
RUN apt-get install -y --fix-missing \ | ||
build-essential \ | ||
cmake \ | ||
gfortran \ | ||
wget \ | ||
curl \ | ||
graphicsmagick \ | ||
libgraphicsmagick1-dev \ | ||
libatlas-dev \ | ||
libavcodec-dev \ | ||
libavformat-dev \ | ||
libgtk2.0-dev \ | ||
libjpeg-dev \ | ||
liblapack-dev \ | ||
libswscale-dev \ | ||
pkg-config \ | ||
software-properties-common \ | ||
zip | ||
|
||
# Google tesseract | ||
RUN add-apt-repository ppa:alex-p/tesseract-ocr &&\ | ||
apt-get update &&\ | ||
apt install -y tesseract-ocr &&\ | ||
apt install -y libtesseract-dev | ||
|
||
|
||
ADD ./python_requirements.txt / | ||
RUN python3 -m pip install -r python_requirements.txt | ||
|
||
|
||
# ADD ../app / | ||
ENTRYPOINT ["bash","/app/start_flask.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Content AI | ||
version: '3.4' | ||
services: | ||
sky_ocr: | ||
container_name: sky_ocr | ||
build : . | ||
volumes : | ||
- ../:/app | ||
restart: always | ||
ports: | ||
- 5005:5005 | ||
# entrypoint : "/bin/bash" | ||
# stdin_open: true | ||
# tty: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
click==7.0 | ||
Flask==1.0.2 | ||
itsdangerous==1.1.0 | ||
jinja2==2.10.1 | ||
markupsafe==1.1.1 | ||
pillow==5.4.1 | ||
pytesseract==0.2.6 | ||
werkzeug==0.15.3 | ||
flask_cors==3.0.8 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-i https://pypi.org/simple/ | ||
click==7.0 | ||
flask==1.0.2 | ||
itsdangerous==1.1.0 | ||
jinja2==2.10.1 | ||
markupsafe==1.1.1 | ||
pillow==5.4.1 | ||
pytesseract==0.2.6 | ||
werkzeug==0.15.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#! /bin/bash | ||
cd /app | ||
python3 app.py |
Oops, something went wrong.