diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..fc80f6a --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python.pythonPath": "C:\\Users\\Norbert\\AppData\\Local\\Programs\\Python\\Python38\\python.exe" +} \ No newline at end of file diff --git a/bibrecognition/bibrecognition/__pycache__/__init__.cpython-38.pyc b/bibrecognition/bibrecognition/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..4825c05 Binary files /dev/null and b/bibrecognition/bibrecognition/__pycache__/__init__.cpython-38.pyc differ diff --git a/bibrecognition/bibrecognition/__pycache__/settings.cpython-38.pyc b/bibrecognition/bibrecognition/__pycache__/settings.cpython-38.pyc new file mode 100644 index 0000000..c71a951 Binary files /dev/null and b/bibrecognition/bibrecognition/__pycache__/settings.cpython-38.pyc differ diff --git a/bibrecognition/bibrecognition/__pycache__/urls.cpython-38.pyc b/bibrecognition/bibrecognition/__pycache__/urls.cpython-38.pyc new file mode 100644 index 0000000..cad8a73 Binary files /dev/null and b/bibrecognition/bibrecognition/__pycache__/urls.cpython-38.pyc differ diff --git a/bibrecognition/bibrecognition/__pycache__/wsgi.cpython-38.pyc b/bibrecognition/bibrecognition/__pycache__/wsgi.cpython-38.pyc new file mode 100644 index 0000000..04781db Binary files /dev/null and b/bibrecognition/bibrecognition/__pycache__/wsgi.cpython-38.pyc differ diff --git a/bibrecognition/bibrecognition/settings.py b/bibrecognition/bibrecognition/settings.py index 2450ade..7e68fa1 100644 --- a/bibrecognition/bibrecognition/settings.py +++ b/bibrecognition/bibrecognition/settings.py @@ -119,3 +119,4 @@ USE_TZ = True # https://docs.djangoproject.com/en/3.0/howto/static-files/ STATIC_URL = '/static/' + diff --git a/bibrecognition/db.sqlite3 b/bibrecognition/db.sqlite3 index cf7bce3..53d4a22 100644 Binary files a/bibrecognition/db.sqlite3 and b/bibrecognition/db.sqlite3 differ diff --git a/bibrecognition/imguploader/__pycache__/__init__.cpython-38.pyc b/bibrecognition/imguploader/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..1f47c36 Binary files /dev/null and b/bibrecognition/imguploader/__pycache__/__init__.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/__pycache__/admin.cpython-37.pyc b/bibrecognition/imguploader/__pycache__/admin.cpython-37.pyc index 8beaf67..0c2a862 100644 Binary files a/bibrecognition/imguploader/__pycache__/admin.cpython-37.pyc and b/bibrecognition/imguploader/__pycache__/admin.cpython-37.pyc differ diff --git a/bibrecognition/imguploader/__pycache__/admin.cpython-38.pyc b/bibrecognition/imguploader/__pycache__/admin.cpython-38.pyc new file mode 100644 index 0000000..71628dc Binary files /dev/null and b/bibrecognition/imguploader/__pycache__/admin.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/__pycache__/apps.cpython-38.pyc b/bibrecognition/imguploader/__pycache__/apps.cpython-38.pyc new file mode 100644 index 0000000..28f646f Binary files /dev/null and b/bibrecognition/imguploader/__pycache__/apps.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/__pycache__/forms.cpython-38.pyc b/bibrecognition/imguploader/__pycache__/forms.cpython-38.pyc new file mode 100644 index 0000000..f31c41f Binary files /dev/null and b/bibrecognition/imguploader/__pycache__/forms.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/__pycache__/models.cpython-38.pyc b/bibrecognition/imguploader/__pycache__/models.cpython-38.pyc new file mode 100644 index 0000000..308d83f Binary files /dev/null and b/bibrecognition/imguploader/__pycache__/models.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/__pycache__/urls.cpython-38.pyc b/bibrecognition/imguploader/__pycache__/urls.cpython-38.pyc new file mode 100644 index 0000000..b0b8a69 Binary files /dev/null and b/bibrecognition/imguploader/__pycache__/urls.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/__pycache__/views.cpython-38.pyc b/bibrecognition/imguploader/__pycache__/views.cpython-38.pyc new file mode 100644 index 0000000..1430f17 Binary files /dev/null and b/bibrecognition/imguploader/__pycache__/views.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/admin.py b/bibrecognition/imguploader/admin.py index 8c38f3f..5937740 100644 --- a/bibrecognition/imguploader/admin.py +++ b/bibrecognition/imguploader/admin.py @@ -1,3 +1,10 @@ from django.contrib import admin # Register your models here. +from .models import Competitions +from .models import Photo +from .models import PhotoMeta + +admin.site.register(Competitions) +admin.site.register(Photo) +admin.site.register(PhotoMeta) \ No newline at end of file diff --git a/bibrecognition/imguploader/forms.py b/bibrecognition/imguploader/forms.py new file mode 100644 index 0000000..79f447b --- /dev/null +++ b/bibrecognition/imguploader/forms.py @@ -0,0 +1,7 @@ +# forms.py +from django import forms +from .models import * + +class PhotoForm(forms.Form): + zawody = forms.CharField(max_length=50) + file_field = forms.FileField(widget=forms.ClearableFileInput()) diff --git a/bibrecognition/imguploader/functions.py b/bibrecognition/imguploader/functions.py new file mode 100644 index 0000000..20264b0 --- /dev/null +++ b/bibrecognition/imguploader/functions.py @@ -0,0 +1,189 @@ +try: + from PIL import Image +except ImportError: + import Image +from cv2 import cv2 +import pytesseract +import argparse +import numpy as np +from imutils.object_detection import non_max_suppression + +pytesseract.pytesseract.tesseract_cmd = r'C:\Program Files\Tesseract-OCR\tesseract.exe' +faceCascade = cv2.CascadeClassifier( + 'haarcascade/haarcascade_frontalface_default.xml') + + +def decode_predictions(scores, geometry): + # grab the number of rows and columns from the scores volume, then + # initialize our set of bounding box rectangles and corresponding + # confidence scores + (numRows, numCols) = scores.shape[2:4] + rects = [] + confidences = [] + + # loop over the number of rows + for y in range(0, numRows): + # extract the scores (probabilities), followed by the + # geometrical data used to derive potential bounding box + # coordinates that surround text + scoresData = scores[0, 0, y] + xData0 = geometry[0, 0, y] + xData1 = geometry[0, 1, y] + xData2 = geometry[0, 2, y] + xData3 = geometry[0, 3, y] + anglesData = geometry[0, 4, y] + + # loop over the number of columns + for x in range(0, numCols): + # if our score does not have sufficient probability, + # ignore it + if scoresData[x] < args["min_confidence"]: + continue + + # compute the offset factor as our resulting feature + # maps will be 4x smaller than the input image + (offsetX, offsetY) = (x * 4.0, y * 4.0) + + # extract the rotation angle for the prediction and + # then compute the sin and cosine + angle = anglesData[x] + cos = np.cos(angle) + sin = np.sin(angle) + + # use the geometry volume to derive the width and height + # of the bounding box + h = xData0[x] + xData2[x] + w = xData1[x] + xData3[x] + + # compute both the starting and ending (x, y)-coordinates + # for the text prediction bounding box + endX = int(offsetX + (cos * xData1[x]) + (sin * xData2[x])) + endY = int(offsetY - (sin * xData1[x]) + (cos * xData2[x])) + startX = int(endX - w) + startY = int(endY - h) + + # add the bounding box coordinates and probability score + # to our respective lists + rects.append((startX, startY, endX, endY)) + confidences.append(scoresData[x]) + + # return a tuple of the bounding boxes and associated confidences + return (rects, confidences) + + +# construct the argument parser and parse the arguments +ap = argparse.ArgumentParser() +ap.add_argument("-i", "--image", type=str, + help="path to input image") +ap.add_argument("-east", "--east", type=str, default="./EAST/frozen_east_text_detection.pb", + help="path to input EAST text detector") +ap.add_argument("-c", "--min-confidence", type=float, default=0.5, + help="minimum probability required to inspect a region") +ap.add_argument("-w", "--width", type=int, default=320, + help="nearest multiple of 32 for resized width") +ap.add_argument("-e", "--height", type=int, default=320, + help="nearest multiple of 32 for resized height") +ap.add_argument("-p", "--padding", type=float, default=0.0, + help="amount of padding to add to each border of ROI") +args = vars(ap.parse_args()) + +# load the input image and grab the image dimensions +image = cv2.imread(args["image"]) +orig = image.copy() +(origH, origW) = image.shape[:2] + +# set the new width and height and then determine the ratio in change +# for both the width and height +(newW, newH) = (args["width"], args["height"]) +rW = origW / float(newW) +rH = origH / float(newH) + +# resize the image and grab the new image dimensions +image = cv2.resize(image, (newW, newH)) +(H, W) = image.shape[:2] + +# define the two output layer names for the EAST detector model that +# we are interested -- the first is the output probabilities and the +# second can be used to derive the bounding box coordinates of text +layerNames = [ + "feature_fusion/Conv_7/Sigmoid", + "feature_fusion/concat_3"] + +# load the pre-trained EAST text detector +print("[INFO] loading EAST text detector...") +net = cv2.dnn.readNet(args["east"]) + +# construct a blob from the image and then perform a forward pass of +# the model to obtain the two output layer sets +blob = cv2.dnn.blobFromImage(image, 1.0, (W, H), + (123.68, 116.78, 103.94), swapRB=True, crop=False) +net.setInput(blob) +(scores, geometry) = net.forward(layerNames) + +# decode the predictions, then apply non-maxima suppression to +# suppress weak, overlapping bounding boxes +(rects, confidences) = decode_predictions(scores, geometry) +boxes = non_max_suppression(np.array(rects), probs=confidences) + +# initialize the list of results +results = [] + +# loop over the bounding boxes +for (startX, startY, endX, endY) in boxes: + # scale the bounding box coordinates based on the respective + # ratios + startX = int(startX * rW) + startY = int(startY * rH) + endX = int(endX * rW) + endY = int(endY * rH) + + # in order to obtain a better OCR of the text we can potentially + # apply a bit of padding surrounding the bounding box -- here we + # are computing the deltas in both the x and y directions + dX = int((endX - startX) * args["padding"]) + dY = int((endY - startY) * args["padding"]) + + # apply padding to each side of the bounding box, respectively + startX = max(0, startX - dX) + startY = max(0, startY - dY) + endX = min(origW, endX + (dX * 2)) + endY = min(origH, endY + (dY * 2)) + + # extract the actual padded ROI + roi = orig[startY:endY, startX:endX] + + # in order to apply Tesseract v4 to OCR text we must supply + # (1) a language, (2) an OEM flag of 4, indicating that the we + # wish to use the LSTM neural net model for OCR, and finally + # (3) an OEM value, in this case, 7 which implies that we are + # treating the ROI as a single line of text + config = ("-l eng --oem 1 --psm 7") + text = pytesseract.image_to_string(roi, config=config) + + # add the bounding box coordinates and OCR'd text to the list + # of results + results.append(((startX, startY, endX, endY), text)) + +# sort the results bounding box coordinates from top to bottom +results = sorted(results, key=lambda r: r[0][1]) + +# loop over the results +for ((startX, startY, endX, endY), text) in results: + # display the text OCR'd by Tesseract + print("OCR TEXT") + print("========") + print("{}\n".format(text)) + + # strip out non-ASCII text so we can draw the text on the image + # using OpenCV, then draw the text and a bounding box surrounding + # the text region of the input image + text = "".join([c if ord(c) < 128 else "" for c in text]).strip() + output = orig.copy() + cv2.rectangle(output, (startX, startY), (endX, endY), + (0, 0, 255), 2) + cv2.putText(output, text, (startX, startY - 20), + cv2.FONT_HERSHEY_SIMPLEX, 1.2, (0, 0, 255), 3) + + # show the output image + cv2.imshow("Text Detection", output) + cv2.waitKey(0) diff --git a/bibrecognition/imguploader/migrations/0002_auto_20200210_1945.py b/bibrecognition/imguploader/migrations/0002_auto_20200210_1945.py new file mode 100644 index 0000000..7659b12 --- /dev/null +++ b/bibrecognition/imguploader/migrations/0002_auto_20200210_1945.py @@ -0,0 +1,23 @@ +# Generated by Django 3.0.3 on 2020-02-10 18:45 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('imguploader', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='photo', + name='image', + field=models.ImageField(default='placeholder.jpg', upload_to='images/'), + ), + migrations.AddField( + model_name='photo', + name='name', + field=models.CharField(default='Zdjecie', max_length=100), + ), + ] diff --git a/bibrecognition/imguploader/migrations/0003_competitions_status.py b/bibrecognition/imguploader/migrations/0003_competitions_status.py new file mode 100644 index 0000000..7b4f5d4 --- /dev/null +++ b/bibrecognition/imguploader/migrations/0003_competitions_status.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.3 on 2020-06-14 18:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('imguploader', '0002_auto_20200210_1945'), + ] + + operations = [ + migrations.AddField( + model_name='competitions', + name='status', + field=models.CharField(default='draft', max_length=10), + ), + ] diff --git a/bibrecognition/imguploader/migrations/__pycache__/0001_initial.cpython-38.pyc b/bibrecognition/imguploader/migrations/__pycache__/0001_initial.cpython-38.pyc new file mode 100644 index 0000000..bc70b08 Binary files /dev/null and b/bibrecognition/imguploader/migrations/__pycache__/0001_initial.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/migrations/__pycache__/0002_auto_20200210_1945.cpython-38.pyc b/bibrecognition/imguploader/migrations/__pycache__/0002_auto_20200210_1945.cpython-38.pyc new file mode 100644 index 0000000..0a9f061 Binary files /dev/null and b/bibrecognition/imguploader/migrations/__pycache__/0002_auto_20200210_1945.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/migrations/__pycache__/0003_competitions_status.cpython-38.pyc b/bibrecognition/imguploader/migrations/__pycache__/0003_competitions_status.cpython-38.pyc new file mode 100644 index 0000000..8f04eaa Binary files /dev/null and b/bibrecognition/imguploader/migrations/__pycache__/0003_competitions_status.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/migrations/__pycache__/__init__.cpython-38.pyc b/bibrecognition/imguploader/migrations/__pycache__/__init__.cpython-38.pyc new file mode 100644 index 0000000..eef368f Binary files /dev/null and b/bibrecognition/imguploader/migrations/__pycache__/__init__.cpython-38.pyc differ diff --git a/bibrecognition/imguploader/models.py b/bibrecognition/imguploader/models.py index c4b89a5..57dc232 100644 --- a/bibrecognition/imguploader/models.py +++ b/bibrecognition/imguploader/models.py @@ -4,9 +4,12 @@ from django.db import models class Competitions(models.Model): comp_slug = models.CharField(max_length=100) comp_name = models.CharField(max_length=100) + status = models.CharField(max_length=10, default="draft") class Photo(models.Model): comp_id = models.ForeignKey(Competitions, on_delete=models.CASCADE) + name = models.CharField(max_length=100, default='Zdjecie') + image = models.ImageField(upload_to='images/', default='placeholder.jpg') url = models.CharField(max_length=50) class PhotoMeta(models.Model): diff --git a/bibrecognition/imguploader/templates/index.html b/bibrecognition/imguploader/templates/index.html new file mode 100644 index 0000000..6849961 --- /dev/null +++ b/bibrecognition/imguploader/templates/index.html @@ -0,0 +1,15 @@ + + + + + + RunPhoto + + + {% if user.is_authenticated %} + Zalogowany 😎 + {% else %} + Gość 🏃‍♀️ + {% endif %} + + \ No newline at end of file diff --git a/bibrecognition/imguploader/templates/upload.html b/bibrecognition/imguploader/templates/upload.html new file mode 100644 index 0000000..ad8c1ce --- /dev/null +++ b/bibrecognition/imguploader/templates/upload.html @@ -0,0 +1,15 @@ + + + + + + Upload Photos + + +
+ {% csrf_token %} + {{ form }} + +
+ + \ No newline at end of file diff --git a/bibrecognition/imguploader/urls.py b/bibrecognition/imguploader/urls.py index 192d770..334a710 100644 --- a/bibrecognition/imguploader/urls.py +++ b/bibrecognition/imguploader/urls.py @@ -4,4 +4,5 @@ from . import views urlpatterns = [ path('', views.index, name="index"), -] \ No newline at end of file + path('upload', views.uploadPhotos, name="upload"), +] diff --git a/bibrecognition/imguploader/views.py b/bibrecognition/imguploader/views.py index aafab64..1f1fea1 100644 --- a/bibrecognition/imguploader/views.py +++ b/bibrecognition/imguploader/views.py @@ -1,7 +1,24 @@ from django.shortcuts import render from django.http import HttpResponse +from .forms import PhotoForm +from django.http import HttpResponseRedirect # Create your views here. def index(request): - return HttpResponse("Hello, world. This is imageUploader") + return render(request, 'index.html', {}) + # return HttpResponse("Hello, world. This is imageUploader") + + +def uploadPhotos(request): + if request.method == 'POST': + form = PhotoForm(request.POST, request.FILES) + if form.is_valid(): + + form.save() + # return render(request, print(request.FILES['file_field'])) + return HttpResponseRedirect('/success/url/') + else: + form = PhotoForm() + return render(request, 'upload.html', {'form': form}) + # return HttpResponse("Hello, world. This is imageUploader") diff --git a/main.py b/main.py index bfc76b8..a274ba3 100644 --- a/main.py +++ b/main.py @@ -76,7 +76,7 @@ def decode_predictions(scores, geometry): ap = argparse.ArgumentParser() ap.add_argument("-i", "--image", type=str, help="path to input image") -ap.add_argument("-east", "--east", type=str, +ap.add_argument("-east", "--east", type=str, default="./EAST/frozen_east_text_detection.pb", help="path to input EAST text detector") ap.add_argument("-c", "--min-confidence", type=float, default=0.5, help="minimum probability required to inspect a region")