index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>人脸识别</title>
  6. <script type="text/javascript" src="./js/tracking-min.js"></script>
  7. <script type="text/javascript" src="./js/face-min.js"></script>
  8. <script type="text/javascript" src="./js/jquery-2.2.1.min.js"></script>
  9. <!-- uni 的 SDK -->
  10. <!-- 需要把 uni.webview.1.5.4.js 下载到自己的服务器 -->
  11. <script type="text/javascript" src="./js/uni.webview.1.5.4.js"></script>
  12. <style>
  13. html,
  14. body {
  15. width: 100%;
  16. height: 100%;
  17. margin: 0;
  18. /* Safari */
  19. -webkit-user-select: none;
  20. /* Firefox */
  21. -moz-user-select: none;
  22. /* IE10+/Edge */
  23. -ms-user-select: none;
  24. /* Standard syntax */
  25. user-select: none;
  26. ::-webkit-scrollbar {
  27. display: none;
  28. }
  29. }
  30. video,
  31. canvas {
  32. position: absolute;
  33. left: 0;
  34. top: 0;
  35. }
  36. .home-card-one,
  37. .home-card-two,
  38. .home-card-three {
  39. display: flex;
  40. flex-wrap: wrap;
  41. overflow: auto;
  42. color: #000;
  43. padding: 20px 20px 50px 20px;
  44. width: calc(100% - 40px);
  45. height: calc(100% - 70px);
  46. text-align: center;
  47. background-color: #fff;
  48. }
  49. .home-card-left {
  50. display: flex;
  51. flex-wrap: wrap;
  52. width: calc(50% - 10px);
  53. margin-right: 10px;
  54. }
  55. .home-card-left-image {
  56. max-height: auto;
  57. }
  58. .home-card-left-header {
  59. width: 100%;
  60. clear: both;
  61. font-size: 30px;
  62. color: #409eff;
  63. margin: 30px 0 30px 0;
  64. }
  65. .home-card-left-content {
  66. width: 100%;
  67. font-size: 18px;
  68. padding: 10px;
  69. background-color: #dfdfdf;
  70. border-radius: 15px;
  71. }
  72. /* .home-card-left-content>div:last-child {
  73. margin-bottom: 30px;
  74. } */
  75. .home-card-left-content>div {
  76. margin-bottom: 20px;
  77. }
  78. .home-card-left-content>div:first-child {
  79. text-align: left;
  80. margin-bottom: 30px;
  81. }
  82. .home-card-right {
  83. display: flex;
  84. flex-wrap: wrap;
  85. width: calc(50% - 10px);
  86. text-align: center;
  87. justify-content: center;
  88. background-color: #409eff;
  89. border-radius: 15px;
  90. color: white;
  91. margin-left: 10px;
  92. }
  93. .home-card-right-header {
  94. display: flex;
  95. justify-content: center;
  96. max-height: 36px;
  97. margin-bottom: 30px;
  98. }
  99. .home-card-right-header-center {
  100. padding: 10px;
  101. font-size: 12px;
  102. background: rgb(255 255 255 / 10%);
  103. border-radius: 5px;
  104. }
  105. .home-card-right-header-title {
  106. font-size: 18px;
  107. margin: auto 0;
  108. }
  109. .home-card-right-content {
  110. width: 100%;
  111. }
  112. .home-card-right-footer {
  113. position: relative;
  114. width: 320px;
  115. height: 240px;
  116. }
  117. .home-card-bottom {
  118. width: 100%;
  119. position: absolute;
  120. left: 0;
  121. bottom: 0;
  122. display: flex;
  123. overflow: auto;
  124. height: 31px;
  125. margin-top: 20px;
  126. }
  127. .home-card-bottom>div {
  128. padding: 6px;
  129. font-size: 13px;
  130. color: #fff;
  131. border-left: 1.5px #fff solid;
  132. white-space: nowrap;
  133. }
  134. .home-card-bottom>div:first-child {
  135. border: 0px;
  136. }
  137. @media (max-width: 768px) {
  138. .home-card-left,
  139. .home-card-right {
  140. width: 100% !important;
  141. margin: 0 !important;
  142. }
  143. .home-card-left {
  144. margin-bottom: 20px !important;
  145. }
  146. }
  147. </style>
  148. </head>
  149. <body>
  150. <div id="face-container" class="face-container home-card-two">
  151. <div id="home-card-left" class="home-card-left"></div>
  152. <div id="home-card-right" class="home-card-right"></div>
  153. <div id="home-card-bottom" class="home-card-bottom"></div>
  154. </div>
  155. <script type="text/javascript">
  156. var state = {
  157. dataAll: {},
  158. thisVenueData: [],
  159. thisVenueTime: {},
  160. nextSceneData: [],
  161. nextSceneTime: {},
  162. timeList: []
  163. }
  164. var timeOutEvent = 0;
  165. // 初始化
  166. function initData() {
  167. $(`#home-card-left`).append(`
  168. <image id="home-card-left-image" class="home-card-left-image" src="./img/logo.png" width="125px" height="60px" mode="aspectFill"></image>
  169. <div class="home-card-left-header">${state.dataAll?.roomName || "请配置会议室"}</div>
  170. <div class="home-card-left-content" style="margin-bottom: 20px;">
  171. <div>本场会议</div>
  172. <div>${state.thisVenueData[0]?.meetingName || "空闲中"}</div>
  173. <div>${state.thisVenueTime.startTime || "00:00"} — ${state.thisVenueTime.endTime || "00:00"}</div>
  174. </div>
  175. <div class="home-card-left-content">
  176. <div>下场会议</div>
  177. <div>${state.nextSceneData[0]?.meetingName || "空闲中"}</div>
  178. <div>${state.nextSceneTime.startTime || "00:00"} — ${state.nextSceneTime.endTime || "00:00"}</div>
  179. </div>
  180. `)
  181. $(`#home-card-right`).append(`
  182. <div class="home-card-right-header">
  183. <div class="home-card-right-header-center">
  184. <span style="padding: 0 5px 0 0; border-right: 1px #fff solid">温度:80℃</span>
  185. <span style="padding: 0px 5px; border-right: 1px #fff solid">湿度:80%</span>
  186. <span style="padding: 0px 5px; border-right: 1px #fff solid">PM2.5:10μg/m3</span>
  187. <span style="padding: 0 0 0 5px">甲醛:0ppm</span>
  188. </div>
  189. <div class="home-card-right-header-title">${state.thisVenueData[0] ? "&nbsp;&nbsp;会议进行中" : "&nbsp;"}</div>
  190. </div>
  191. <div class="home-card-right-content">
  192. <div style="font-size: 20px; margin-bottom: 15px;">${state.thisVenueData[0]?.meetingName || "空闲中"}</div>
  193. <div style="font-size: 18px; margin-bottom: 15px;">
  194. ${state.thisVenueTime.startTime || "00:00"} — ${state.thisVenueTime.endTime || "00:00"}
  195. </div>
  196. <div style="font-size: 14px; margin-bottom: 15px;">${state.msg || "&nbsp;"}</div>
  197. </div>
  198. <div class="home-card-right-footer" id="home-card-right-footer">
  199. <video id="video" width="320" height="240" preload autoplay loop muted></video>
  200. <canvas id="canvas" width="320" height="240"></canvas>
  201. </div>
  202. `)
  203. var html = ``
  204. state.timeList.forEach((item, timeIndex) => {
  205. html += `
  206. <div id="timeScorll${timeIndex}" style="background-color: ${item.isEnd === 1 ? "#909399" : item.isHave === 1 ? "#fa3534" : item.isReservation === 1 ? "#ff9900" : "#409eff"}">
  207. ${item.isEnd != 0 || item.isHave != 0 || item.isReservation != 0 ? item.startTime + " —— " + item.endTime : item.startTime}
  208. </div >
  209. `
  210. });
  211. $(`#home-card-bottom`).append(html)
  212. var video = document.getElementById("video");//视频dom
  213. video.style.transform = 'scaleX(-1)';//视频翻转(1.水平翻转-scaleX(-1) 2.垂直翻转-scaleY(-1))
  214. var canvas = document.getElementById('canvas');//画布dom
  215. canvas.style.transform = 'scaleX(-1)';//画布翻转(1.水平翻转-scaleX(-1) 2.垂直翻转-scaleY(-1))
  216. var context = canvas.getContext('2d');
  217. var time = 5000;
  218. var tracker = new tracking.ObjectTracker('face');
  219. tracker.setInitialScale(4); //设置识别的放大比例
  220. tracker.setStepSize(2);//设置步长
  221. tracker.setEdgesDensity(0.1);//边缘密度
  222. //启动摄像头,并且识别视频内容
  223. var trackerTask = tracking.track('#video', tracker, {
  224. camera: true
  225. });
  226. var flag = true;
  227. tracker.on('track', function (event) {
  228. if (event.data.length === 0) {
  229. // console.log('未检测到人脸')
  230. context.clearRect(0, 0, canvas.width, canvas.height);
  231. } else if (event.data.length > 1) {
  232. // console.log('检测到多张人脸')
  233. } else {
  234. context.clearRect(0, 0, canvas.width, canvas.height);
  235. event.data.forEach(function (rect) {
  236. context.strokeStyle = '#409eff';
  237. context.strokeRect(rect.x, rect.y, rect.width, rect.height);
  238. context.fillStyle = "#409eff";
  239. context.lineWidth = 1.5;
  240. });
  241. if (flag) {
  242. console.log("拍照");
  243. context.drawImage(video, 0, 0, video.width, video.height);
  244. saveAsLocalImage();
  245. context.clearRect(0, 0, canvas.width, canvas.height);
  246. flag = false;
  247. setTimeout(function () {
  248. flag = true;
  249. }, time);
  250. } else {
  251. //console.log("冷却中");
  252. }
  253. }
  254. });
  255. $("#home-card-left-image").on({
  256. touchstart: function (e) {
  257. timeOutEvent = setTimeout("longPress()", 500);
  258. e.preventDefault();
  259. },
  260. touchmove: function () {
  261. clearTimeout(timeOutEvent);
  262. timeOutEvent = 0;
  263. },
  264. touchend: function () {
  265. clearTimeout(timeOutEvent);
  266. if (timeOutEvent != 0) {
  267. console.log("你这是点击,不是长按");
  268. }
  269. return false;
  270. }
  271. })
  272. }
  273. // 长按事件
  274. function longPress() {
  275. timeOutEvent = 0
  276. parentMessage('打开配置')
  277. }
  278. /**
  279. * 解析数据
  280. */
  281. function analysisData(event) {
  282. console.log(event.funcName)
  283. if ("funcName" in event) {
  284. if (event.funcName == "初始化") {
  285. $(`#home-card-left`).empty();//删除dom下的所有子元素
  286. $("#home-card-right").empty();//删除dom下的所有子元素
  287. $(`#home-card-bottom`).empty();//删除dom下的所有子元素
  288. state.dataAll = JSON.parse(event.data).dataAll
  289. state.thisVenueData = JSON.parse(event.data).thisVenueData
  290. state.thisVenueTime = JSON.parse(event.data).thisVenueTime
  291. state.nextSceneData = JSON.parse(event.data).nextSceneData
  292. state.nextSceneTime = JSON.parse(event.data).nextSceneTime
  293. state.timeList = JSON.parse(event.data).timeList
  294. initData();
  295. } else if (event.funcName == "撒点") {
  296. }
  297. }
  298. }
  299. // 获取图片bold
  300. function saveAsLocalImage() {
  301. var myCanvas = document.getElementById("canvas");
  302. var image = myCanvas.toDataURL("image/png").replace("image/png", "image/octet-stream");
  303. parentMessage('人脸识别', { imageBase: image })
  304. }
  305. // 向父页面发送数据
  306. function parentMessage(type, data) {
  307. var message = {
  308. funcName: type,
  309. data: data,
  310. };
  311. //APP-PLUS
  312. uni.postMessage({
  313. data: message
  314. });
  315. //H5
  316. if (window.parent) {
  317. window.parent.postMessage(message, '*');
  318. }
  319. }
  320. /**
  321. * APP-PLUS || H5
  322. * 接收父页面传过来的值
  323. */
  324. window.receiveData = function (msg) {
  325. analysisData(msg)
  326. }
  327. window.addEventListener("message", function (event) {
  328. analysisData(event.data)
  329. });
  330. window.onload = function () {
  331. initData();
  332. };
  333. </script>
  334. </body>
  335. </html>