platForm.html 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. {% extends "base.html" %}
  2. {% load static %}
  3. {% block title %}
  4. 人脸识别开放平台
  5. {% endblock %}
  6. {% block content %}
  7. <link href="{% static 'css/news.css' %}" rel="stylesheet">
  8. <link rel="stylesheet" href="{% static 'css/codemirror.css' %}">
  9. <script src="{% static 'js/codemirror.js' %}"></script>
  10. <script src="{% static 'js/python.js' %}"></script>
  11. <style type="text/css">
  12. .CodeMirror {
  13. border-top: 1px solid black;
  14. border-bottom: 1px solid black;
  15. }
  16. </style>
  17. <!-- 广告横幅 -->
  18. <div class="container-fluid">
  19. <div class="row">
  20. <img class="img-responsive model-img" src="{% static 'img/service.jpg' %}">
  21. </div>
  22. </div>
  23. <!-- 主体内容 -->
  24. <div class="container">
  25. <div class="row row-3">
  26. <!-- 侧边导航栏 -->
  27. <div class="col-md-3">
  28. <div class="model-title">
  29. 服务支持
  30. </div>
  31. <div class="model-list">
  32. <ul class="list-group">
  33. <li class="list-group-item" id='download'>
  34. <a href="{% url 'serviceApp:download' %}">资料下载</a>
  35. </li>
  36. <li class="list-group-item" id='platform'>
  37. <a href="{% url 'serviceApp:platform' %}">人脸识别开放平台</a>
  38. </li>
  39. </ul>
  40. </div>
  41. </div>
  42. <!-- 说明文字和图片 -->
  43. <div class="col-md-9">
  44. <div class="model-details-title">
  45. 人脸识别接口文档
  46. </div>
  47. <div class="model-details">
  48. <h3>一. 体验产品</h3>
  49. </br>
  50. <!-- 按钮触发模态框 -->
  51. <button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  52. 人脸检测
  53. </button>
  54. <!-- 模态框(Modal) -->
  55. <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
  56. aria-hidden="true">
  57. <div class="modal-dialog">
  58. <div class="modal-content">
  59. <div class="modal-header">
  60. <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
  61. &times;
  62. </button>
  63. <h4 class="modal-title" id="myModalLabel">
  64. 在线人脸检测
  65. </h4>
  66. </div>
  67. <div class="modal-body">
  68. <img id="photoIn" src="{% static 'img/sample.png' %}" class="img-responsive"
  69. style="max-width:250px">
  70. <input type="file" id="photo" name="photo" />
  71. </div>
  72. <div class="modal-footer">
  73. <button type="button" class="btn btn-default" data-dismiss="modal">关闭
  74. </button>
  75. <button type="button" id="compute" class="btn btn-primary">
  76. 开始检测
  77. </button>
  78. </div>
  79. </div><!-- /.modal-content -->
  80. </div><!-- /.modal -->
  81. </div>
  82. <script>
  83. $(function () {
  84. $('#photo').on('change', function () {
  85. var r = new FileReader();
  86. f = document.getElementById('photo').files[0];
  87. r.readAsDataURL(f);
  88. r.onload = function (e) {
  89. document.getElementById('photoIn').src = this.result;
  90. };
  91. });
  92. });
  93. </script>
  94. <script>
  95. $('#compute').click(function () {
  96. formdata = new FormData();
  97. var file = $("#photo")[0].files[0];
  98. formdata.append("image", file);
  99. $.ajax({
  100. url: '/serviceApp/facedetectDemo/', // 调用Django服务器计算函数
  101. type: 'POST', // 请求类型
  102. data: formdata,
  103. dataType: 'json', // 期望获得的响应类型为json
  104. processData: false,
  105. contentType: false,
  106. success: ShowResult // 在请求成功之后调用该回调函数输出结果
  107. })
  108. })
  109. </script>
  110. <script>
  111. function ShowResult(data) {
  112. var v = data['img64'];
  113. document.getElementById('photoIn').src = "data:image/jpeg;base64, " + v;
  114. }
  115. </script>
  116. <h3>二. API接口说明</h3>
  117. </br>
  118. <h4><strong>基本信息:</strong></h4>
  119. <p>
  120. 请求类型:HTTP/HTTPS。请求方式:POST
  121. </p>
  122. <p>
  123. 接口地址:http://myhengda.cn/serviceApp/facedetect/
  124. </p>
  125. </br>
  126. <h4><strong>接口描述:</strong></h4>
  127. <p>
  128. 人脸检测,此接口多用于调用人脸识别、人脸比对的接口之前,用于从图像数据中检测出人脸区域,并以
  129. 矩形框形式返回人脸检测结果。目前该接口仅供测试使用,调用该接口暂时不限制调用次数。
  130. </p>
  131. </br>
  132. <h4><strong>本地调用示例:</strong></h4>
  133. <div><textarea id="code" name="code">
  134. import cv2, requests
  135. # web地址(http://localhost:8000)+访问接口(facedetect)
  136. url = "http://localhost:8000/serviceApp/facedetect/"
  137. # 上传图像并检测
  138. tracker = None
  139. imgPath = "face.jpg" #图像路径
  140. files = {
  141. "image": ("filename2", open(imgPath, "rb"), "image/jpeg"),
  142. }
  143. req = requests.post(url, data=tracker, files=files).json()
  144. print("获取信息: {}".format(req))
  145. # 将检测结果框显示在图像上
  146. img = cv2.imread(imgPath)
  147. for (w, x, y, z) in req["faces"]:
  148. cv2.rectangle(img, (w, x), (y, z), (0, 255, 0), 2)
  149. cv2.imshow("face detection", img)
  150. cv2.waitKey(0)
  151. </textarea></div>
  152. </br>
  153. <h4><strong>调用结果:</strong></h4>
  154. <img class="img-responsive" style="max-width:200px;" src="{% static 'img/facedetect.png' %}">
  155. </div>
  156. </div>
  157. </div>
  158. </div>
  159. <script>
  160. var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
  161. mode: {
  162. name: "python",
  163. version: 3,
  164. singleLineStringErrors: false
  165. },
  166. lineNumbers: true,
  167. indentUnit: 4,
  168. tabMode: "shift",
  169. matchBrackets: true
  170. });
  171. </script>
  172. {% endblock %}