probably works. Added possibility changing associated numbers

This commit is contained in:
Norbert 2020-06-20 06:20:00 +02:00
parent 6d4bbf4bdc
commit 680c586bb3
27 changed files with 156 additions and 6 deletions

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 528 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 KiB

View File

@ -11,5 +11,14 @@ class PhotoForm(forms.Form):
class SearchForm(forms.Form):
zawody = forms.ModelChoiceField(
queryset=Competitions.objects.all(), to_field_name="comp_slug")
queryset=Competitions.objects.filter(status="published"), to_field_name="comp_slug")
numer = forms.DecimalField(decimal_places=0)
class ChangeForm(forms.Form):
zawody = forms.ModelChoiceField(
queryset=Competitions.objects.all(), to_field_name="comp_slug")
class ChangeIDForm(forms.Form):
numerki = forms.CharField()

View File

@ -72,7 +72,7 @@ def decode_predictions(scores, geometry):
def findNumber(url):
image = cv2.imread(url)
image = cv2.imread("./"+url)
orig = image.copy()
(origH, origW) = image.shape[:2]
(newW, newH) = (320,320)

View File

@ -17,7 +17,7 @@ class Competitions(models.Model):
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')
image = models.ImageField(upload_to='./', default='placeholder.jpg')
# url = models.CharField(max_length=50)
objects = PhotoManager()

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search Photos</title>
</head>
<body>
{% if form %}
<form action="/change" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
{% endif %}
{% if meta %}
<ul>
{% for n in meta %}
<li><img src="images/{{ n.0 }}" />
<div>
{% for nr in n.1 %}
<p>{{ nr }}</p>
{% endfor %}
</div>
</li>
{% endfor %}
</ul>
{% endif %}
</body>
</html>

View File

@ -0,0 +1,30 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search Photos</title>
</head>
<body>
{% if foto %}
<img src="{{ foto }}" />
<p>Znalezione wartości:</p>
<span>
{% for n in numery %}
{{ n }},
{% endfor %}
<p>Nowe wartości (po przecinku): </p>
<form action="/change/{{ photoid }}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit" value="Submit">
</form>
</span>
{% endif %}
</body>
</html>

View File

@ -9,7 +9,8 @@
{% if user.is_authenticated %}
Zalogowany 😎 <br />
<a href="{% url 'upload' %}">Załaduj zdjęcia</a><br />
<a href="{% url 'search' %}">Przeszukaj bazę</a>
<a href="{% url 'search' %}">Przeszukaj bazę</a><br />
<a href="{% url 'change' %}">Koryguj</a>
{% else %}
Gość 🏃‍♀️<br />
<a href="{% url 'search' %}">Przeszukaj bazę</a>

View File

@ -18,7 +18,7 @@
{% if foto %}
<ul>
{% for n in foto %}
<li><img src="{{ n }}" /></li>
<li><img src="images/{{ n }}" /></li>
{% endfor %}
</ul>
{% endif %}

View File

@ -8,6 +8,8 @@ urlpatterns = [
path('', views.index, name="index"),
path('upload', views.uploadPhotos, name="upload"),
path('search', views.searchPhotos, name="search"),
path('change', views.changePhotos, name="change"),
path('change/<int:photo>', views.changePhotoID, name="changeid"),

View File

@ -2,6 +2,8 @@ from django.shortcuts import render
from django.http import HttpResponse
from .forms import PhotoForm
from .forms import SearchForm
from .forms import ChangeForm
from .forms import ChangeIDForm
from django.http import HttpResponseRedirect
from .models import PhotoManager
@ -55,7 +57,7 @@ def searchPhotos(request):
form = SearchForm(request.POST)
comp = request.POST['zawody']
numer = request.POST['numer']
print(request)
# print(request)
if form.is_valid():
allFotos = []
@ -76,6 +78,7 @@ def searchPhotos(request):
return render(request, 'search.html', {'foto': imgUrls})
else:
print('no ni ma')
return HttpResponseRedirect('/failed/')
return HttpResponseRedirect('/success/')
else:
@ -85,3 +88,75 @@ def searchPhotos(request):
form = SearchForm()
return render(request, 'search.html', {'form': form})
# return HttpResponse("Hello, world. This is imageUploader")
def changePhotos(request):
if request.method == 'POST':
form = ChangeForm(request.POST)
comp = request.POST['zawody']
imgMeta = []
if form.is_valid():
zawody = Competitions.objects.get(comp_slug=comp)
try:
zdjecia = Photo.objects.filter(
comp_id=zawody)
except Photo.DoesNotExist:
zdjecia = None
if( zdjecia ):
for zdjecie in zdjecia:
meta = []
pm = PhotoMeta.objects.filter(photo_id=zdjecie)
meta.append(zdjecie.image.name)
numery = []
for numer in pm:
numery.append(numer.meta_value)
meta.append(numery)
imgMeta.append(meta)
return render(request, 'change.html', {'meta': imgMeta})
else:
print('no ni ma')
return HttpResponseRedirect('/failed/')
else:
return HttpResponseRedirect('/failed/')
else:
form = ChangeForm()
return render(request, 'change.html', {'form': form})
def changePhotoID(request, photo):
if request.method == 'POST':
form = ChangeIDForm(request.POST)
meta = request.POST['numerki']
numerki = meta.split(',')
zdjecie = Photo.objects.get(pk=photo)
PhotoMeta.objects.filter(photo_id=zdjecie).delete()
for n in numerki:
n = n.strip()
pm = PhotoMeta(comp_id=zdjecie.comp_id, photo_id=zdjecie,
meta_key="detect_number", meta_value=n)
pm.save(force_insert=True)
return render(request, 'changeid.html')
else:
form = ChangeIDForm()
try:
zdjecie = Photo.objects.get(pk=photo)
except Photo.DoesNotExist:
zdjecie = None
if(zdjecie):
pm = PhotoMeta.objects.filter(photo_id=zdjecie)
foto = zdjecie.image.url
numery = []
for nr in pm:
numery.append(nr.meta_value)
else:
print('no ni ma')
return HttpResponseRedirect('/failed/')
return render(request, 'changeid.html', {'photoid':photo,'foto': foto, 'numery': numery, 'form': form})

BIN
imgs/bib_05.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 446 KiB

BIN
imgs/bib_06.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

BIN
imgs/bib_07.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

BIN
imgs/bib_08.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

BIN
imgs/bib_09.jpg Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 268 KiB