JQuery+PHP\u7684\u56fe\u50cf\u4eba\u8138\u8bc6\u522b\u6e90\u7801\u4e0b\u8f7d<\/a><\/p>\n<\/p>\n
<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD XHTML 1.0 Transitional\/\/EN" "http:\/\/www.w3.org\/TR\/xhtml1\/DTD\/xhtml1-transitional.dtd">\r\n<html xmlns="http:\/\/www.w3.org\/1999\/xhtml">\r\n<head>\r\n <meta http-equiv="Content-Type" content="text\/html; charset=utf-8" \/>\r\n <title>\u5229\u7528facedetection\u63d2\u4ef6,\u5b9e\u73b0JQuery+PHP\u7684\u56fe\u50cf\u4eba\u8138\u8bc6\u522b<\/title>\r\n <script src="jquery-2.1.4.min.js"><\/script>\r\n <script src="jquery.facedetection.min.js"><\/script>\r\n<\/head>\r\n \r\n<body>\r\n <style>\r\n \/*\u8bc6\u522b\u5230\u4eba\u8138\u540e,\u8fdb\u884c\u753b\u6846\u6807\u8bb0\u7684\u65b9\u6846\u6837\u5f0f*\/\r\n .findface {\r\n border: 2px solid #ff0000;\r\n left: -1000px;\r\n position: absolute;\r\n top: -1000px;\r\n }\r\n <\/style>\r\n \r\n<?php\r\n \/*\r\n \u7167\u7247\u8981\u7528base64\u8f93\u51fa,\u5426\u5219\u62a5\u9519,\u63d0\u793a\u5982\u4e0b:\r\n \r\n "Uncaught DOMException: Failed to execute 'getImageData' on 'CanvasRenderingContext2D': The source width is 0."\r\n \r\n \u539f\u56e0\uff1a\u56fe\u7247\u5b58\u50a8\u5728\u672c\u5730\u65f6\uff0c\u662f\u9ed8\u8ba4\u6ca1\u6709\u57df\u540d\u7684\uff0c\u7528getImageData\u65b9\u6cd5\u65f6\uff0c\u6d4f\u89c8\u5668\u4f1a\u5224\u5b9a\u4e3a\u8de8\u57df\u800c\u62a5\u9519\uff01\r\n \u800cgetImageData\u65b9\u6cd5\u4e0d\u5141\u8bb8\u64cd\u4f5c\u975e\u6b64\u57df\u540d\u5916\u7684\u56fe\u7247\u8d44\u6e90\uff0c\u5373\u4f7f\u662f\u5b50\u57df\u4e5f\u4e0d\u884c(\u672c\u5730host\u4e00\u4e2a\u57df\u540d\u4e5f\u7ecf\u5e38\u8bef\u62a5)\u3002\u89e3\u51b3\u529e\u6cd5\u5c31\u662f\u628a\u56fe\u7247\u4ee5\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u5d4c\u5165\u5728\u7f51\u9875\u5185\u663e\u793a\uff0c\u90a3\u4e48\u4efb\u4f55\u6765\u6e90\u7684\u56fe\u7247\u8d44\u6e90\u5c31\u53d8\u6210\u672c\u5730\u7684,\u95ee\u9898\u89e3\u51b3\u3002\r\n *\/\r\n \r\n $pic = 'uploads\/a.jpg';\r\n $arr = getimagesize($pic);\/\/getimagesize\u51fd\u6570\u7528\u4e8e\u83b7\u53d6\u56fe\u50cf\u5927\u5c0f\u53ca\u76f8\u5173\u4fe1\u606f\uff0c\u6210\u529f\u8fd4\u56de\u4e00\u4e2a\u6570\u7ec4\uff0c\u5931\u8d25\u5219\u8fd4\u56de FALSE \u5e76\u4ea7\u751f\u4e00\u6761 E_WARNING \u7ea7\u7684\u9519\u8bef\u4fe1\u606f\u3002\r\n $pic = "data:{$arr['mime']};base64," . base64_encode(file_get_contents($pic));\r\n?>\r\n \r\n<div class="imgContainer">\r\n <img id="picture" src="<?php echo $pic ?>" \/>\r\n<\/div>\r\n \r\n<script>\r\n \r\n \/*\r\n \r\n facedetection\u4eba\u8138\u8bc6\u522b\u7ed3\u679c,\u8fd4\u56de\u627e\u5230\u5bf9\u8c61\u7684\u6570\u7ec4\u8bf4\u660e\uff1a\r\n \r\n x \u2014\u56fe\u7247\u4e2d\u8138\u90e8\u7684X\u5750\u6807\r\n y-\u56fe\u7247\u4e2d\u4eba\u8138\u7684Y\u5750\u6807\r\n width \u2014\u8138\u7684\u5bbd\u5ea6\r\n \u9ad8\u5ea6 -\u8138\u90e8\u9ad8\u5ea6\r\n positionX \u2014\u76f8\u5bf9\u4e8e\u6587\u6863\u7684X\u4f4d\u7f6e\r\n positionY \u2014\u76f8\u5bf9\u4e8e\u6587\u6863\u7684Y\u4f4d\u7f6e\r\n offsetX \u2014\u76f8\u5bf9\u4e8e\u504f\u79fb\u7236\u7ea7\u7684X\u4f4d\u7f6e\r\n offsetY \u2014\u76f8\u5bf9\u4e8e\u504f\u79fb\u7236\u7ea7\u7684Y\u4f4d\u7f6e\r\n scaleX \u2014\u539f\u59cb\u56fe\u50cf\u5bbd\u5ea6\u548c\u663e\u793a\u5bbd\u5ea6\u4e4b\u95f4\u7684\u6bd4\u7387\r\n scaleY \u2014\u539f\u59cb\u56fe\u50cf\u9ad8\u5ea6\u548c\u663e\u793a\u9ad8\u5ea6\u4e4b\u95f4\u7684\u6bd4\u7387\r\n confidence - \u4fe1\u5fc3\u6c34\u5e73\r\n \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\r\n console.log\u503c\uff1a\r\n 0:\r\n confidence: 0.53963825\r\n height: 96.50000000000009\r\n neighbors: 1\r\n offsetX: 136.5000000000001\r\n offsetY: 104.50000000000009\r\n positionX: 136.5000000000001\r\n positionY: 104.50000000000009\r\n scaleX: 1\r\n scaleY: 1\r\n width: 96.50000000000009\r\n x: 128.5000000000001\r\n y: 96.50000000000009\r\n \u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\r\n \u53c2\u6570\u8bbe\u5b9a\u503c\r\n interval \u2014\u65f6\u95f4\u95f4\u9694\uff08\u9ed8\u8ba4\u4e3a4\uff09\r\n minNeighbors \u2014\u6700\u5c0f\u90bb\u5c45\u9608\u503c\uff0c\u7528\u4e8e\u8bbe\u7f6e\u5c06\u77e9\u5f62\u7ec4\u4f5c\u4e3a\u9762\u4e22\u5f03\u7684\u622a\u6b62\u7ea7\u522b\uff08\u9ed8\u8ba4\u4e3a1\uff09\r\n confidence -\u7f6e\u4fe1\u5ea6 -\u6700\u5c0f\u7f6e\u4fe1\u5ea6\uff08\u9ed8\u8ba4\u4e3anull\uff09\r\n async \u2014\u5f02\u6b65\u6a21\u5f0f\uff08\u5982\u679cWorker\u53ef\u7528\uff09\uff08\u9ed8\u8ba4\u4e3afalse\uff09\u3002\u5f02\u6b65\u6a21\u5f0f\u4f7f\u7528Workers\uff0c\u5e76\u4e14\u9700\u8981\u811a\u672c\u4f4d\u4e8e\u540c\u4e00\u57df\u4e2d\u3002\r\n grayscale \u2014\u7070\u5ea6 \u2014\u5904\u7406\u524d\u8f6c\u6362\u4e3a\u7070\u5ea6\uff08\u9ed8\u8ba4\u4e3atrue\uff09\r\n \r\n complete \u2014\u68c0\u6d4b\u5b8c\u6210\u540e\u89e6\u53d1\u7684\u56de\u8c03\u51fd\u6570\r\n complete: function (faces) {\r\n \/\/ ...\r\n }\r\n \r\n error \u2014\u89e6\u53d1\u4e86\u9519\u8bef\u7684\u56de\u8c03\u51fd\u6570\r\n error: function (code, message) {\r\n \/\/ ...\r\n }\r\n \r\n *\/\r\n \r\n var img = document.getElementById('picture');\r\n \r\n \/\/\u753b\u65b9\u6846\r\n function draw(x, y, w, h) {\r\n var findface = document.createElement('div');\r\n document.querySelector('.imgContainer').appendChild(findface);\r\n findface.classList.add('findface');\r\n findface.style.width = w + 'px';\r\n findface.style.height = h + 'px';\r\n findface.style.left = (img.offsetLeft + x) + 'px';\r\n findface.style.top = (img.offsetTop + y) + 'px';\r\n };\r\n \r\n \/\/\u5bf9\u56fe\u50cf\u4e2d\u4eba\u8138\u7684\u8bc6\u522b\r\n $('#picture').faceDetection({\r\n \/\/confidence:3,\/\/\u7f6e\u4fe1\u5ea6\u8bbe\u7f6e\uff0c0.1\u81f31\u4e4b\u95f4\uff0c\u503c\u8d8a\u5927\u8981\u6c42\u8d8a\u5339\u914d\u5ea6\u8d8a\u4e25\u683c\r\n complete: function (faces) {\r\n if (faces.length == 0) { \/\/\u8bf4\u660e\u6ca1\u6709\u68c0\u6d4b\u5230\u4eba\u8138\r\n alert("\u65e0\u4eba\u8138")\r\n } else {\r\n console.log(faces);\/\/\u8f93\u51fa\u8bc6\u522b\u5230\u7684\u4eba\u8138\u6570\u636e\r\n for (var i in faces) {\r\n \/\/\u5c06\u591a\u4e2a\u88ab\u8bc6\u522b\u5230\u7684\u4eba\u8138\u56fe\u50cf\u8fdb\u884c\u753b\u6846\u6807\u8bb0\r\n draw(faces[i].x, faces[i].y, faces[i].width, faces[i].height);\r\n }\r\n }\r\n }\r\n \r\n });\r\n \r\n<\/script>\r\n<\/body>\r\n<\/html><\/pre>\n<\/p>\n","protected":false},"excerpt":{"rendered":"
\u6700\u8fd1\u60f3\u7740\u7422\u78e8\u4e00\u4e0b\u4eba\u8138\u8bc6\u522b\u529f\u80fd\u80fd\u4e0d\u80fd\u901a\u8fc7web\u7aef\u6765\u5b9e\u73b0\u4e86\uff0c\u5c31\u7b80\u5355\u7f51\u4e0a\u627e\u4e86\u4e00\u4e9b\u8d44\u6599\uff0c\u53ea\u662f\u76f8\u5173\u6e90\u4ee3\u7801\u5e76\u6ca1\u6709\u7ed9\u51fa\u5b8c\u6574\u7684 […]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1,10,49],"tags":[],"class_list":["post-848","post","type-post","status-publish","format-standard","hentry","category-html","category-php","category-web_html"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/848"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=848"}],"version-history":[{"count":3,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/848\/revisions"}],"predecessor-version":[{"id":851,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/848\/revisions\/851"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}