I have a python function for face recognition. I am uploading image with django. and in django given to me a path of image. So i want to call the python function for send a path to function. This python function is making face recognition and return to recognition image path. So i want to call this python function in django. Then I can show as in django.
My post method:
def list(request):
# Handle file upload
if request.method == 'POST':
form = DocumentForm(request.POST, request.FILES)
if form.is_valid():
newdoc = Document(docfile = request.FILES['docfile'])
newdoc.save()
# Redirect to the document list after POST
return HttpResponseRedirect(reverse('list'))
else:
form = DocumentForm() # A empty, unbound form
# Load documents for the list page
documents = Document.objects.all()
# Render list page with the documents and the form
return render_to_response(
'myapp/list.html',
{'documents': documents, 'form': form},
context_instance=RequestContext(request)
)`
list.html:
<!-- List of uploaded documents -->
{% if documents %}
{% for document in documents %}
<article class="one_quarter" style="margin-bottom:6px;">
<figure>
<img src="{{ document.docfile.url }}" width="215" height="315" alt="{{ document.docfile.name }}">
<figcaption>Adsız</figcaption>
</figure>
</article>
{% endfor %}
{% else %}
<p>Resim Bulunamadı</p>
{% endif %}
<div>
<!-- Upload form. Note enctype attribute! -->
<form action="{% url "list" %}" method="post" enctype="multipart/form-data">
{% csrf_token %}
<p>{{ form.non_field_errors }}</p>
<p>{{ form.docfile.label_tag }} </p>
<p>
{{ form.docfile.errors }}
{{ form.docfile }}
</p>
<p><input type="submit" value="Upload" /></p>
When i was uploading image, This python function take to image path and test image folder path, then should return to image path of recognition. Then i want to show which image path returned.
Python libraries :
import cv2, os
import numpy as np
from PIL import Image
and function definition in python:
def get_face_recog(path, image_path)
...
return frimage