{"id":304677,"date":"2020-06-01T21:01:20","date_gmt":"2020-06-01T21:01:20","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=304677"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=304677","title":{"rendered":"\u041f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u043b\u0438\u0446\u0430 \u00ab\u043d\u0430 \u043b\u0435\u0442\u0443\u00bb \u0432 Django"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/504748\/\">\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0434\u043d\u044f!<\/p>\n<p>  \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0421\u043e\u0431\u043e\u043b\u0435\u0432 \u0410\u043d\u0434\u0440\u0435\u0439 \u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u00ab\u043f\u043b\u044e\u0448\u043a\u0443\u00bb \u043a Django, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u043b\u0438\u0446\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 (\u0447\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432 \u043a\u0443\u0447\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439).<\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f OpenCV \u0438 5 \u043c\u0438\u043d\u0443\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e\u0435\u0445\u0430\u043b\u0438.<br \/>  <a name=\"habracut\"><\/a><\/p>\n<h3>\u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430<\/h3>\n<p>  \u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u043c \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0432 \u0434\u043e\u043a\u0435\u0440 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440   <\/p>\n<pre><code class=\"python\">FROM python:3.8.3-buster  RUN apt-get update &amp;&amp; \\     apt-get upgrade -y &amp;&amp; \\     apt-get install -y \\     gcc &amp;&amp; apt-get install -y \\       libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev libjpeg-dev libfreetype6-dev python-dev libpq-dev python-dev libxml2-dev libxslt-dev postgresql-client git &amp;&amp; \\     apt-get install -y libxrender1 libxext-dev fontconfig &amp;&amp; \\     pip3 install -U pip setuptools   COPY .\/requirements.txt \/home\/ * * * <\/code><\/pre>\n<p>  \u0418 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0432 requirements.txt  <\/p>\n<pre><code class=\"python\">opencv-python matplotlib numpy <\/code><\/pre>\n<h3>detect_face<\/h3>\n<p>  \u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0444\u0430\u0439\u043b utils.py (\u043a \u043f\u0440\u0438\u043c\u0435\u0440\u0443 \u0432 \u043f\u0430\u043f\u043a\u0435 main) \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u0442\u0443\u0434\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0435 \u0441\u0442\u0440\u043e\u0447\u043a\u0438   <\/p>\n<pre><code class=\"python\">import cv2 as cv import numpy as np  def detect_face(in_memory_photo):     face_cascade = cv.CascadeClassifier(cv.__path__[0] + &quot;\/data\/haarcascade_frontalface_default.xml&quot;)     in_memory_photo = in_memory_photo.read()     nparr = np.fromstring(in_memory_photo, np.uint8)     img = cv.imdecode(nparr, 4)     gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY)     faces = face_cascade.detectMultiScale(gray, 1.3, 5)     if len(faces) &gt; 0:         return True     else:         return False <\/code><\/pre>\n<h3>\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0432 \u0444\u043e\u0440\u043c\u0443 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u043e\u0433\u043e \u0432\u0432\u043e\u0434\u0430<\/h3>\n<p>  \u0418\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0430\u0448\u0443 \u0444\u0443\u043d\u043a\u0446\u0438\u044e  <\/p>\n<pre><code class=\"python\">from main.utils import detect_face <\/code><\/pre>\n<p>  \u0418 \u00ab\u043f\u0440\u043e\u0432\u0435\u0440\u0438\u043c \u043b\u0438\u0446\u043e\u00bb \u043f\u0440\u0438 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043d\u043e\u0432\u043e\u0433\u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f.  <\/p>\n<pre><code class=\"python\">if request.method == &quot;POST&quot;:     form = RegistrationForm(request.POST, request.FILES)      if form.is_valid():          try:             in_memory_uploaded_file = request.FILES[&quot;photo&quot;]         except:             in_memory_uploaded_file = None          if not in_memory_uploaded_file or not detect_face(in_memory_uploaded_file):             messages.add_message(request, messages.WARNING, _(&quot;You can only upload a face photo. Please try to uploading a different photo.&quot;))             return HttpResponseRedirect(reverse(&quot;main:profile_registration&quot;)) <\/code><\/pre>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c \u0432\u0441\u0435. <br \/>  \u041a\u0430\u043a \u0432\u0438\u0434\u0438\u043c, \u0432\u0441\u0435 \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e (\u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043a\u043e\u043d\u0435\u0447\u043d\u043e).<\/p>\n<h3>\u041f\u043e\u043b\u0435\u0437\u043d\u044b\u0435 \u0441\u0441\u044b\u043b\u043a\u0438<\/h3>\n<p>  <a href=\"https:\/\/towardsdatascience.com\/face-detection-in-2-minutes-using-opencv-python-90f89d7c0f81\" rel=\"nofollow\">towardsdatascience.com\/face-detection-in-2-minutes-using-opencv-python-90f89d7c0f81<\/a><br \/>  <a href=\"https:\/\/new-friend.org\/ru\/195\/2800\/12918\/profile-registration\/\" rel=\"nofollow\">new-friend.org\/ru\/195\/2800\/12918\/profile-registration<\/a> (\u043f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0431\u043e\u0442\u044b \u0434\u0430\u043d\u043d\u043e\u0433\u043e \u0440\u0435\u0448\u0435\u043d\u0438\u044f)<\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/504748\/\"> https:\/\/habr.com\/ru\/post\/504748\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/504748\/\">\u0414\u043e\u0431\u0440\u043e\u0433\u043e \u0434\u043d\u044f!<\/p>\n<p>  \u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0421\u043e\u0431\u043e\u043b\u0435\u0432 \u0410\u043d\u0434\u0440\u0435\u0439 \u0438 \u0441\u0435\u0433\u043e\u0434\u043d\u044f \u043c\u044b \u0441 \u0432\u0430\u043c\u0438 \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u00ab\u043f\u043b\u044e\u0448\u043a\u0443\u00bb \u043a Django, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u044f\u0442\u044c, \u0447\u0442\u043e \u043d\u0430 \u0444\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438 \u0438\u043c\u0435\u043d\u043d\u043e \u043b\u0438\u0446\u043e \u0447\u0435\u043b\u043e\u0432\u0435\u043a\u0430 (\u0447\u0442\u043e \u0431\u044b\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0432 \u043a\u0443\u0447\u0435 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439).<\/p>\n<p>  \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f OpenCV \u0438 5 \u043c\u0438\u043d\u0443\u0442 \u0441\u0432\u043e\u0431\u043e\u0434\u043d\u043e\u0433\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438. \u041f\u043e\u0435\u0445\u0430\u043b\u0438.  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-304677","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304677","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=304677"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304677\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=304677"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=304677"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=304677"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}