帖子
帖子
用户
博客
课程
显示全部楼层
216
帖子
5
勋章
5893
Y币

arcFacePlus模块demo示例

[复制链接]
发表于 2022-7-26 08:36:14
本帖最后由 52yaoer 于 2022-7-26 09:08 编辑


封装了软虹人脸识别功能


  1. <!DOCTYPE html>
  2. <html>

  3. <head>
  4.         <title>Module Develop</title>
  5.         <meta charset="utf-8">
  6.         <meta name="viewport"
  7.                 content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
  8.         <style type="text/css">
  9.                 html,
  10.                 body {
  11.                         height: 100%
  12.                 }

  13.                 body {
  14.                         background-color: #fff;
  15.                         margin: 0;
  16.                 }

  17.                 #wrap {
  18.                         height: 100%;
  19.                         position: relative;
  20.                 }

  21.                 #header {
  22.                         padding-top: 20px;
  23.                         background-color: #5082c2;
  24.                         height: 44px;
  25.                         position: relative;
  26.                 }

  27.                 #header h1 {
  28.                         font-size: 20px;
  29.                         height: 44px;
  30.                         line-height: 44px;
  31.                         margin: 0em;
  32.                         color: #fff;
  33.                         margin-left: 100px;
  34.                         margin-right: 100px;
  35.                         text-align: center;
  36.                 }

  37.                 #main {
  38.                         display: -webkit-box;
  39.                         -webkit-box-orient: vertical;
  40.                         -webkit-box-pack: center;
  41.                 }

  42.                 a.button {
  43.                         display: -webkit-box;
  44.                         -webkit-box-orient: vertical;
  45.                         -webkit-box-pack: center;
  46.                         -webkit-box-align: center;
  47.                         height: 32px;
  48.                         margin: 8px;
  49.                         background-color: rgba(240, 240, 240, 1.0);
  50.                         border-color: rgba(220, 220, 220, 1.0);
  51.                         border-width: 2px;
  52.                         border-style: solid;
  53.                 }

  54.                 a.active {
  55.                         background-color: rgba(240, 240, 240, 0.7);
  56.                 }
  57.         </style>
  58. </head>

  59. <body>
  60.         <div id="wrap">
  61.                 <div id="main">
  62.                         <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  63.                         <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  64.                         <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  65.                         <a class="button" tapmode="active" onclick="requestPermission()">权限动态申请(系统API)</a>
  66.                         <a class="button" tapmode="active" onclick="active()">激活引擎</a>
  67.                         <a class="button" tapmode="active" onclick="addUser()">添加本地用户</a>
  68.                         <a class="button" tapmode="active" onclick="countUser()">统计本地注册用户数</a>
  69.                         <a class="button" tapmode="active" onclick="clearAllUser()">清空所有本地注册用户</a>
  70.                         <a class="button" tapmode="active" onclick="removeUser()">移除指定的本地注册用户 </a>
  71.                         <a class="button" tapmode="active" onclick="getUser()">取得指定本地注册用户 </a>
  72.                         <a class="button" tapmode="active" onclick="listUser()">取得本地所有注册用户 </a>
  73.                         <br><br><br><br>
  74.                         <a class="button" tapmode="active" onclick="setFaceConfig()">设置人脸识别配置参数</a>
  75.                         <a class="button" tapmode="active" onclick="openCompare()">打开自定义人脸对比界面</a>
  76.                         <a class="button" tapmode="active" onclick="closeCompare()">关闭自定义人脸对比界面</a>
  77.                         <a class="button" tapmode="active" onclick="addFacepassListener()">设置人脸对比结果监听</a>
  78.                         <a class="button" tapmode="active" onclick="takePhoto()">抓拍图片</a>
  79.                         <a class="button" tapmode="active" onclick="registerUser()">注册用户</a>
  80.                         <br><br><br><br>
  81.                         <a class="button" tapmode="active" onclick="changeDisplayOrientation(0)">改变角度0</a>
  82.                         <a class="button" tapmode="active" onclick="changeDisplayOrientation(90)">改变角度90</a>
  83.                         <a class="button" tapmode="active" onclick="changeDisplayOrientation(180)">改变角度180</a>
  84.                         <a class="button" tapmode="active" onclick="changeDisplayOrientation(270)">改变角度270</a>
  85.                         <a class="button" tapmode="active" onclick="getSupportedPreviewSizes()">获取原始可支持的相机分辨率列表</a>
  86.                         <a class="button" tapmode="active" onclick="getCommonSupportedPreviewSize()">获取处理后可支持的相机分辨率列表</a>
  87.                         <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  88.                         <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  89.                         <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  90.                         <br>
  91.                 </div>
  92.         </div>
  93. </body>
  94. <script type="text/javascript">
  95.         var demo = null;
  96.         var picPath;
  97.         var flag = true;
  98.         apiready = function () {
  99.                 demo = api.require('arcFacePlus');
  100.                 if (!demo) {
  101.                         alert("请添加模块后编译");
  102.                         return;
  103.                 }
  104.                 api.setKeepScreenOn({
  105.                         keepOn: true
  106.                 });
  107.         }

  108.         function requestPermission() {
  109.                 api.requestPermission({
  110.                         list: ['camera', 'storage', 'phone-r'],
  111.                 }, function (ret, err) {
  112.                         api.alert({
  113.                                 msg: JSON.stringify(ret)
  114.                         });
  115.                 });
  116.         }

  117.         function active() {
  118.                 demo.active({
  119.                         // activeKey: '8581-112D-H11R-BTGT1',
  120.                         // appId: '2dUKa3iu5taPPdLVuX1EBjG4z9RWQ9nv14TUYrPoxCWB',
  121.                         // sdkKey: '7qZWCU6xheFuU7y55iiSRy5v3MRVdUksnHDuxkv4f5rQ'
  122.                         activeKey: '085T-1131-T1R5-AXWW',
  123.                         appId: 'AsabgmoAxZMxkB3kDZCzQvnXECKVFnLhmsviVBhUwFfW',
  124.                         sdkKey: '73pfJnCNXYji7R5rj6UR9M7mtW9AXxzajTa765NK5xrS'
  125.                 }, function (ret, err) {
  126.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  127.                 });
  128.         }


  129.         function addUser() {
  130.                 // if (!picPath) {
  131.                 //         alert("注册图片路径为空");
  132.                 //         return;
  133.                 // }
  134.                 demo.addUser({
  135.                         userId: '12222222',
  136.                         faceImage: 'http://a06b9b3423f3cd5b8bee.qiniucdn.apicloud**.**/apicloud/699f1793405ddd92167c6c94d005371d.jpg'
  137.                         // faceImage: picPath
  138.                         //faceImage: 'widget://image/WechatIMG1319.jpeg'
  139.                 }, function (ret, err) {
  140.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  141.                 });
  142.         }

  143.         function countUser() {
  144.                 demo.countUser(function (ret, err) {
  145.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  146.                 });
  147.         }

  148.         function clearAllUser() {
  149.                 demo.clearAllUser(function (ret, err) {
  150.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  151.                 });
  152.         }

  153.         function removeUser() {
  154.                 demo.removeUser({
  155.                         userId: '12222222'
  156.                 }, function (ret, err) {
  157.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  158.                 });
  159.         }

  160.         function getUser() {
  161.                 demo.getUser({
  162.                         userId: '12222222'
  163.                 }, function (ret, err) {
  164.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  165.                 });
  166.         }

  167.         function listUser() {
  168.                 demo.listUser(function (ret, err) {
  169.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  170.                 });
  171.         }

  172.         function setFaceConfig() {
  173.                 var ret = demo.setFaceConfig({
  174.                         //rotation : 2,
  175.                         //cameraId : 0,
  176.                         //rotate : 2,
  177.                 });
  178.                 alert(JSON.stringify(ret));
  179.         }

  180.         function openCompare() {
  181.                 demo.openCompare({
  182.                         rect: {
  183.                                 x: 0,
  184.                                 y: 0,
  185.                                 w: api.frameWidth,
  186.                                 h: api.frameHeight / 2,
  187.                                 // marginTop: 400,
  188.                                 // marginBottom: 400
  189.                         },
  190.                         fixedOn: api.frameName,
  191.                         fixed: true,
  192.                 }, function (ret, err) {
  193.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  194.                 });

  195.         }


  196.         function closeCompare() {
  197.                 demo.closeCompare(function (ret, err) {
  198.                         //alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  199.                 });
  200.         }

  201.         function addFacepassListener() {
  202.                 demo.addFacepassListener(function (ret, err) {
  203.                         console.log(JSON.stringify(ret) + "  " + JSON.stringify(err));
  204.                         if (ret.status) {
  205.                                 //alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  206.                                 api.toast({
  207.                                         msg: JSON.stringify(ret) + "  " + JSON.stringify(err)
  208.                                 });
  209.                         } else {
  210.                                 api.toast({
  211.                                         msg: JSON.stringify(ret) + "  " + JSON.stringify(err)
  212.                                 });
  213.                         }
  214.                 });
  215.         }

  216.         function takePhoto() {
  217.                 demo.takePhoto(function (ret, err) {
  218.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  219.                         if (ret.status) {
  220.                                 picPath = ret.imagePath;
  221.                         }
  222.                 });
  223.         }

  224.         function registerUser() {
  225.                 demo.registerUser(function (ret, err) {
  226.                         alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  227.                 });
  228.         }


  229.         function changeDisplayOrientation(orientation) {
  230.                 demo.changeDisplayOrientation({
  231.                         displayOrientation: orientation
  232.                 }, function (ret, err) {
  233.                         //alert(JSON.stringify(ret) + "  " + JSON.stringify(err));
  234.                 });
  235.         }

  236.         function getSupportedPreviewSizes() {
  237.                 var ret = demo.getSupportedPreviewSizes();
  238.                 alert(JSON.stringify(ret));
  239.         }


  240.         function getCommonSupportedPreviewSize() {
  241.                 var ret = demo.getCommonSupportedPreviewSize();
  242.                 alert(JSON.stringify(ret));
  243.         }


  244. </script>

  245. </html>
复制代码


您需要登录后才可以回帖 登录

本版积分规则