yht 1 日 前
コミット
43f6a9a705

+ 2 - 1
.gitignore

@@ -195,4 +195,5 @@ secrets.json
 !**/**.css
 !**/**.js
 !**/**.jpg
-!**/**.png
+!**/**.png
+!**/db.sqlite3

BIN
pythonweb/db.sqlite3


+ 1 - 1
pythonweb/newsApp/whoosh_backend.py

@@ -11,7 +11,7 @@ import warnings
 
 from django.conf import settings
 from django.core.exceptions import ImproperlyConfigured
-from django.utils import six
+import six
 from django.utils.datetime_safe import datetime
 from django.utils.encoding import force_str
 

+ 2 - 1
pythonweb/serviceApp/admin.py

@@ -1,5 +1,6 @@
 from django.contrib import admin
 from .models import Doc
 
+
 # Register your models here.
-admin.site.register(Doc)
+admin.register(Doc)

+ 8 - 10
pythonweb/serviceApp/models.py

@@ -3,16 +3,14 @@ import django.utils.timezone as timezone
 
 # Create your models here.
 class Doc(models.Model):
-    title = models.CharField(max_length=250,verbose_name='资料名称')
-    file = models.FileField(upload_to='Service/',
-                            blank=True,
-                            verbose_name='文件资料')
-    publishDate = models.DateTimeField(max_length=20,
-                                       default=timezone.now,
-                                       verbose_name='发布时间')
+    title = models.CharField(max_length=250,verbose_name="资料名称")
+    file = models.FileField(upload_to='Service/',blank=True,verbose_name="文件资料")
+    publishDate = models.DateTimeField(max_length=20,default=timezone.now,verbose_name="发布时间")
+
     def __str__(self):
         return self.title
+
     class Meta:
-        ordering = ['publishDate']
-        verbose_name = '资料'
-        verbose_name_plural = verbose_name
+        ordering = ['-publishDate']
+        verbose_name = "资料"
+        verbose_name_plural = verbose_name

+ 25 - 8
pythonweb/serviceApp/templates/docList.html

@@ -1,4 +1,11 @@
-{% extends "base.html" %} {% load static %} {% block title %} 资料下载 {% endblock %} {% block content %}
+{% extends "base.html" %}
+{% load staticfiles %}
+
+{% block title %}
+资料下载
+{% endblock %}
+
+{% block content %}
 <link href="{% static 'css/news.css' %}" rel="stylesheet">
 <!-- 广告横幅 -->
 <div class="container-fluid">
@@ -37,23 +44,33 @@
                     <a href="{% url 'serviceApp:getDoc' doc.id %}"><b>{{doc.title}}</b></a>
                     <span>【{{doc.publishDate|date:"Y-m-d"}}】</span>
                 </div>
-                {% endfor %} {% if pageData %}
+                {% endfor %}
+
+                {% if pageData %}
                 <div class="paging">
                     <ul id="pages" class="pagination">
                         {% if pageData.first %}
                         <li><a href="?page=1">1</a></li>
-                        {% endif %} {% if pageData.left %} {% if pageData.left_has_more %}
+                        {% endif %}
+                        {% if pageData.left %}
+                        {% if pageData.left_has_more %}
                         <li><span>...</span></li>
-                        {% endif %} {% for i in pageData.left %}
+                        {% endif %}
+                        {% for i in pageData.left %}
                         <li><a href="?page={{i}}">{{i}}</a></li>
-                        {% endfor %} {% endif %}
+                        {% endfor %}
+                        {% endif %}
                         <li class="active"><a href="?page={{pageData.page}}">
                                 {{pageData.page}}</a></li>
-                        {% if pageData.right %} {% for i in pageData.right %}
+                        {% if pageData.right %}
+                        {% for i in pageData.right %}
                         <li><a href="?page={{i}}">{{i}}</a></li>
-                        {% endfor %} {% if pageData.right_has_more %}
+                        {% endfor %}
+                        {% if pageData.right_has_more %}
                         <li><span>...</span></li>
-                        {% endif %} {% endif %} {% if pageData.last %}
+                        {% endif %}
+                        {% endif %}
+                        {% if pageData.last %}
                         <li><a href="?page={{pageData.total_pages}}">
                                 {{pageData.total_pages}}</a></li>
                         {% endif %}

+ 20 - 12
pythonweb/serviceApp/templates/platForm.html

@@ -1,4 +1,11 @@
-{% extends "base.html" %} {% load static %} {% block title %} 人脸识别开放平台 {% endblock %} {% block content %}
+{% extends "base.html" %}
+{% load staticfiles %}
+
+{% block title %}
+人脸识别开放平台
+{% endblock %}
+
+{% block content %}
 <link href="{% static 'css/news.css' %}" rel="stylesheet">
 <link rel="stylesheet" href="{% static 'css/codemirror.css' %}">
 <script src="{% static 'js/codemirror.js' %}"></script>
@@ -47,7 +54,8 @@
                     人脸检测
                 </button>
                 <!-- 模态框(Modal) -->
-                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
+                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
+                    aria-hidden="true">
                     <div class="modal-dialog">
                         <div class="modal-content">
                             <div class="modal-header">
@@ -59,7 +67,8 @@
                                 </h4>
                             </div>
                             <div class="modal-body">
-                                <img id="photoIn" src="{% static 'img/sample.png' %}" class="img-responsive" style="max-width:250px">
+                                <img id="photoIn" src="{% static 'img/sample.png' %}" class="img-responsive"
+                                    style="max-width:250px">
                                 <input type="file" id="photo" name="photo" />
                             </div>
                             <div class="modal-footer">
@@ -69,25 +78,23 @@
                                     开始检测
                                 </button>
                             </div>
-                        </div>
-                        <!-- /.modal-content -->
-                    </div>
-                    <!-- /.modal -->
+                        </div><!-- /.modal-content -->
+                    </div><!-- /.modal -->
                 </div>
                 <script>
-                    $(function() {
-                        $('#photo').on('change', function() {
+                    $(function () {
+                        $('#photo').on('change', function () {
                             var r = new FileReader();
                             f = document.getElementById('photo').files[0];
                             r.readAsDataURL(f);
-                            r.onload = function(e) {
+                            r.onload = function (e) {
                                 document.getElementById('photoIn').src = this.result;
                             };
                         });
                     });
                 </script>
                 <script>
-                    $('#compute').click(function() {
+                    $('#compute').click(function () {
                         formdata = new FormData();
                         var file = $("#photo")[0].files[0];
                         formdata.append("image", file);
@@ -120,7 +127,8 @@
                 </br>
                 <h4><strong>接口描述:</strong></h4>
                 <p>
-                    人脸检测,此接口多用于调用人脸识别、人脸比对的接口之前,用于从图像数据中检测出人脸区域,并以 矩形框形式返回人脸检测结果。目前该接口仅供测试使用,调用该接口暂时不限制调用次数。
+                    人脸检测,此接口多用于调用人脸识别、人脸比对的接口之前,用于从图像数据中检测出人脸区域,并以
+                    矩形框形式返回人脸检测结果。目前该接口仅供测试使用,调用该接口暂时不限制调用次数。
                 </p>
 
                 </br>

+ 3 - 3
pythonweb/serviceApp/urls.py

@@ -6,7 +6,7 @@ app_name = 'serviceApp'
 urlpatterns = [
     path('download/', views.download, name='download'),  # 资料下载
     path('platform/', views.platform, name='platform'),  # 人脸识别开放平台
-    path('getDoc/<int:id>/',views.getDoc,name='getDoc'),
-    path('facedetect/',views.facedetect,name='facedetect'),
-    path('facedetectDemo/',views.facedetectDemo,name='facedetectDemo'), 
+    path('getDoc/<int:id>/', views.getDoc, name='getDoc'),
+    path('facedetect/', views.facedetect, name='facedetect'),
+    path('facedetectDemo/', views.facedetectDemo, name='facedetectDemo'),
 ]

+ 79 - 140
pythonweb/serviceApp/views.py

@@ -1,178 +1,117 @@
-from django.shortcuts import render
-from django.shortcuts import HttpResponse
-from django.shortcuts import get_object_or_404
-from django.http import StreamingHttpResponse
-from django.core.paginator import Paginator
-from .models import Doc
+import base64
 import os
-import numpy as np
-import urllib
-import json
+
 import cv2
+import numpy as np
+from django.http import StreamingHttpResponse, JsonResponse
+from django.shortcuts import render, get_object_or_404
+from django.shortcuts import HttpResponse
 from django.views.decorators.csrf import csrf_exempt
-from django.http import JsonResponse
-import base64
+
+from .models import Doc
+
+face_detector_path = 'serviceApp/haarcascade_frontalface_default.xml'
+face_detector = cv2.CascadeClassifier(face_detector_path)
 
 # Create your views here.
 def download(request):
-    submenu = 'download'
-    docList = Doc.objects.all().order_by('-publishDate')
-    p = Paginator(docList, 5)
-    if p.num_pages <= 1:
-        pageData = ''
-    else:
-        page = int(request.GET.get('page', 1))
-        newList = p.page(page)
-        left = []
-        right = []
-        left_has_more = False
-        right_has_more = False
-        first = False
-        last = False
-        total_pages = p.num_pages
-        page_range = p.page_range
-        if page == 1:
-            right = page_range[page:page + 2]
-            print(total_pages)
-            if right[-1] < total_pages - 1:
-                right_has_more = True
-            if right[-1] < total_pages:
-                last = True
-        elif page == total_pages:
-            left = page_range[(page - 3) if (page - 3) > 0 else 0:page - 1]
-            if left[0] > 2:
-                left_has_more = True
-            if left[0] > 1:
-                first = True
-        else:
-            left = page_range[(page - 3) if (page - 3) > 0 else 0:page - 1]
-            right = page_range[page:page + 2]
-            if left[0] > 2:
-                left_has_more = True
-            if left[0] > 1:
-                first = True
-            if right[-1] < total_pages - 1:
-                right_has_more = True
-            if right[-1] < total_pages:
-                last = True
-        pageData = {
-            'left': left,
-            'right': right,
-            'left_has_more': left_has_more,
-            'right_has_more': right_has_more,
-            'first': first,
-            'last': last,
-            'total_pages': total_pages,
-            'page': page,
-        }
-    return render(
-        request, 'docList.html', {
-            'active_menu': 'service',
-            'sub_menu': submenu,
-            'docList': docList,
-            'pageData': pageData,
-        })
+    return render(request,'docList.html',{'active_menu':'download'})
+
 
-def read_file(file_name, size):
-    with open(file_name, mode='rb') as fp:
+def platform(request):
+    return render(request,'platForm.html',{'active_menu':'platform'})
+
+def getDoc(request,id):
+    doc = get_object_or_404(Doc,id=id)
+    update_to,filename = str(doc.file.split('/'))
+    filepath = '%s/media/%s/%s' % (os.getcwd(),update_to,filename)
+    response = StreamingHttpResponse(read_file(filepath,512))
+    response['Content-Type'] = 'application/octet-stream'
+    response['Content-Disposition'] = 'attachment; filename=%s' % filename
+    return response
+
+def read_file(file_name,size):
+    with open(file_name,'rb') as f:
         while True:
-            c = fp.read(size)
+            c = f.read(size)
             if c:
                 yield c
             else:
                 break
 
-def getDoc(request, id):
-    doc = get_object_or_404(Doc, id=id)
-    update_to, filename = str(doc.file).split('/')
-    filepath = '%s/media/%s/%s' % (os.getcwd(), update_to, filename)
-    response = StreamingHttpResponse(read_file(filepath, 512))
-    response['Content-Type'] = 'application/octet-stream'
-    response['Content-Disposition'] = 'attachment;filename="{}"'.format(
-        filename)
-    return response
-
-
-def platform(request):
-    submenu = 'platform'
-    return render(request, 'platForm.html', {
-        'active_menu': 'service',
-        'sub_menu': submenu,
-    })
-    # html = '<html><body>人脸识别开放平台</body></html>'
-    # return HttpResponse(html)
-
-def read_image(stream=None):
-    if stream is not None:
-        data_temp = stream.read()
-    img = np.asarray(bytearray(data_temp), dtype="uint8")
-    img = cv2.imdecode(img, cv2.IMREAD_COLOR)
-    return img
-
-face_detector_path = "serviceApp\\haarcascade_frontalface_default.xml"
-face_detector = cv2.CascadeClassifier(face_detector_path)
-
 @csrf_exempt
 def facedetect(request):
     result = {}
-
-    if request.method == "POST":
-        if request.FILES.get("image", None) is not None:
-            img = read_image(stream=request.FILES["image"])
+    if request.method == 'POST':
+        if request.FILES['file'].get('image', None) is not None:
+            img = read_image(stream = request.FILES['image'])
         else:
             result.update({
-                "#faceNum": -1,
+                "#faceNum":-1
             })
             return JsonResponse(result)
 
         if img.shape[2] == 3:
-            img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
+            img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
+
+        values = face_detector.detectMultiScale(
+            img,
+            scaleFactor=1.1,
+            minNeighbors=5,
+            minSize=(30, 30),
+            falgs = cv2.CASCADE_SCALE_IMAGE
+        )
 
-        values = face_detector.detectMultiScale(img,
-                                                scaleFactor=1.1,
-                                                minNeighbors=5,
-                                                minSize=(30, 30),
-                                                flags=cv2.CASCADE_SCALE_IMAGE)
+        values = [
+            (int(a),int(b),int(a+c),int(b+d))
+            for (a,b,c,d) in values
+        ]
 
-        values = [(int(a), int(b), int(a + c), int(b + d))
-                  for (a, b, c, d) in values]
         result.update({
-            "#faceNum": len(values),
-            "faces": values,
+            "#faceNum":len(values),
+            "face":values,
         })
-    return JsonResponse(result)
+        return JsonResponse(result)
 
 
+def read_image(stream = None):
+    if stream is not None:
+        data_temp = stream.read()
+    img = np.asarray(bytearray(data_temp), dtype="uint8")
+    img = cv2.imdecode(img,cv2.IMREAD_COLOR)
+    return img
+
 @csrf_exempt
 def facedetectDemo(request):
     result = {}
-
-    if request.method == "POST":
-        if request.FILES.get('image') is not None:  #
-            img = read_image(stream=request.FILES["image"])
+    if request.method == 'POST':
+        if request.FILES['file'].get('image', None) is not None:
+            img = read_image(stream = request.FILES['file'])
         else:
-            result["#faceNum"] = -1
-            return JsonResponse(default)
+            result.update({
+                "#faceNum":-1
+            })
+            return JsonResponse(result)
 
         if img.shape[2] == 3:
-            imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
+            imgGray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
         else:
             imgGray = img
 
-        values = face_detector.detectMultiScale(imgGray,
-                                           scaleFactor=1.1,
-                                           minNeighbors=5,
-                                           minSize=(30, 30),
-                                           flags=cv2.CASCADE_SCALE_IMAGE)
-
-        values = [(int(a), int(b), int(a + c), int(b + d))
-                  for (a, b, c, d) in values]
-
-        for (w, x, y, z) in values:
-            cv2.rectangle(img, (w, x), (y, z), (0, 255, 0), 2)
-
-        retval, buffer_img = cv2.imencode('.jpg', img)
+        values = face_detector.detectMultiScale(
+            imgGray,
+            scaleFactor=1.1,
+            minNeighbors=5,
+            minSize=(30, 30),
+            falgs = cv2.CASCADE_SCALE_IMAGE
+        )
+
+        values = [
+            (int(a),int(b),int(a+c),int(b+d))
+            for (a,b,c,d) in values
+        ]
+        retval,buffer_img = cv2.imencode('.jpg',img)
         img64 = base64.b64encode(buffer_img)
-        img64 = str(img64, encoding='utf-8')
-        result["img64"] = img64
-    return JsonResponse(result)
+        img64 = str(img64, 'utf-8')
+        result['img64'] = img64
+        return JsonResponse(result)