Skip to content

Commit baf8325

Browse files
committed
OCR django
1 parent 8f5ad38 commit baf8325

27 files changed

+1310
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.vscode
2+
env
3+
__pycache__
4+
5+
# tailwind css
6+
templates/package.json
7+
templates/tailwind.config.js
8+
templates/package-lock.json
9+
templates/node_modules

db.sqlite3

Whitespace-only changes.

manage.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python
2+
"""Django's command-line utility for administrative tasks."""
3+
import os
4+
import sys
5+
6+
7+
def main():
8+
"""Run administrative tasks."""
9+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')
10+
try:
11+
from django.core.management import execute_from_command_line
12+
except ImportError as exc:
13+
raise ImportError(
14+
"Couldn't import Django. Are you sure it's installed and "
15+
"available on your PYTHONPATH environment variable? Did you "
16+
"forget to activate a virtual environment?"
17+
) from exc
18+
execute_from_command_line(sys.argv)
19+
20+
21+
if __name__ == '__main__':
22+
main()

ocr/__init__.py

Whitespace-only changes.

ocr/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.contrib import admin
2+
3+
# Register your models here.

ocr/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class OcrConfig(AppConfig):
5+
default_auto_field = 'django.db.models.BigAutoField'
6+
name = 'ocr'

ocr/migrations/__init__.py

Whitespace-only changes.

ocr/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.db import models
2+
3+
# Create your models here.

ocr/tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from django.test import TestCase
2+
3+
# Create your tests here.

ocr/urls.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from django.contrib import admin
2+
from django.urls import include, path
3+
from .views import homepage
4+
5+
urlpatterns = [
6+
path("",homepage,name="homepage"),
7+
]

ocr/views.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from django.shortcuts import render
2+
import pytesseract
3+
pytesseract.pytesseract.tesseract_cmd = r"C:\Program Files\Tesseract-OCR\tesseract.exe" # Path to tesseract.exe
4+
import numpy as np
5+
from PIL import Image
6+
# Create your views here.
7+
8+
def homepage(request):
9+
if request.method == 'POST':
10+
# get image from "image" form field
11+
img = request.FILES['imagefile']
12+
# convert image to numpy array
13+
img = np.array(Image.open(img))
14+
# extract text from image
15+
text = pytesseract.image_to_string(img)
16+
# return text
17+
return render(request, 'home.html', context={'ocr': text})
18+
return render(request, "home.html")

sample image/2022-02-16_16-25.png

99.6 KB
Loading

sample image/2022-02-16_16-26.png

43.3 KB
Loading

sample image/2022-02-16_16-30.png

40.7 KB
Loading

sample image/2022-02-16_16-31.png

97.7 KB
Loading

static/assets/1.svg

Lines changed: 1 addition & 0 deletions
Loading

0 commit comments

Comments
 (0)