|
本帖最后由 52yaoer 于 2022-7-26 09:08 编辑
封装了软虹人脸识别功能
- <!DOCTYPE html>
- <html>
- <head>
- <title>Module Develop</title>
- <meta charset="utf-8">
- <meta name="viewport"
- content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
- <style type="text/css">
- html,
- body {
- height: 100%
- }
- body {
- background-color: #fff;
- margin: 0;
- }
- #wrap {
- height: 100%;
- position: relative;
- }
- #header {
- padding-top: 20px;
- background-color: #5082c2;
- height: 44px;
- position: relative;
- }
- #header h1 {
- font-size: 20px;
- height: 44px;
- line-height: 44px;
- margin: 0em;
- color: #fff;
- margin-left: 100px;
- margin-right: 100px;
- text-align: center;
- }
- #main {
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-box-pack: center;
- }
- a.button {
- display: -webkit-box;
- -webkit-box-orient: vertical;
- -webkit-box-pack: center;
- -webkit-box-align: center;
- height: 32px;
- margin: 8px;
- background-color: rgba(240, 240, 240, 1.0);
- border-color: rgba(220, 220, 220, 1.0);
- border-width: 2px;
- border-style: solid;
- }
- a.active {
- background-color: rgba(240, 240, 240, 0.7);
- }
- </style>
- </head>
- <body>
- <div id="wrap">
- <div id="main">
- <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
- <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
- <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
- <a class="button" tapmode="active" onclick="requestPermission()">权限动态申请(系统API)</a>
- <a class="button" tapmode="active" onclick="active()">激活引擎</a>
- <a class="button" tapmode="active" onclick="addUser()">添加本地用户</a>
- <a class="button" tapmode="active" onclick="countUser()">统计本地注册用户数</a>
- <a class="button" tapmode="active" onclick="clearAllUser()">清空所有本地注册用户</a>
- <a class="button" tapmode="active" onclick="removeUser()">移除指定的本地注册用户 </a>
- <a class="button" tapmode="active" onclick="getUser()">取得指定本地注册用户 </a>
- <a class="button" tapmode="active" onclick="listUser()">取得本地所有注册用户 </a>
- <br><br><br><br>
- <a class="button" tapmode="active" onclick="setFaceConfig()">设置人脸识别配置参数</a>
- <a class="button" tapmode="active" onclick="openCompare()">打开自定义人脸对比界面</a>
- <a class="button" tapmode="active" onclick="closeCompare()">关闭自定义人脸对比界面</a>
- <a class="button" tapmode="active" onclick="addFacepassListener()">设置人脸对比结果监听</a>
- <a class="button" tapmode="active" onclick="takePhoto()">抓拍图片</a>
- <a class="button" tapmode="active" onclick="registerUser()">注册用户</a>
- <br><br><br><br>
- <a class="button" tapmode="active" onclick="changeDisplayOrientation(0)">改变角度0</a>
- <a class="button" tapmode="active" onclick="changeDisplayOrientation(90)">改变角度90</a>
- <a class="button" tapmode="active" onclick="changeDisplayOrientation(180)">改变角度180</a>
- <a class="button" tapmode="active" onclick="changeDisplayOrientation(270)">改变角度270</a>
- <a class="button" tapmode="active" onclick="getSupportedPreviewSizes()">获取原始可支持的相机分辨率列表</a>
- <a class="button" tapmode="active" onclick="getCommonSupportedPreviewSize()">获取处理后可支持的相机分辨率列表</a>
- <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
- <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
- <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
- <br>
- </div>
- </div>
- </body>
- <script type="text/javascript">
- var demo = null;
- var picPath;
- var flag = true;
- apiready = function () {
- demo = api.require('arcFacePlus');
- if (!demo) {
- alert("请添加模块后编译");
- return;
- }
- api.setKeepScreenOn({
- keepOn: true
- });
- }
- function requestPermission() {
- api.requestPermission({
- list: ['camera', 'storage', 'phone-r'],
- }, function (ret, err) {
- api.alert({
- msg: JSON.stringify(ret)
- });
- });
- }
- function active() {
- demo.active({
- // activeKey: '8581-112D-H11R-BTGT1',
- // appId: '2dUKa3iu5taPPdLVuX1EBjG4z9RWQ9nv14TUYrPoxCWB',
- // sdkKey: '7qZWCU6xheFuU7y55iiSRy5v3MRVdUksnHDuxkv4f5rQ'
- activeKey: '085T-1131-T1R5-AXWW',
- appId: 'AsabgmoAxZMxkB3kDZCzQvnXECKVFnLhmsviVBhUwFfW',
- sdkKey: '73pfJnCNXYji7R5rj6UR9M7mtW9AXxzajTa765NK5xrS'
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function addUser() {
- // if (!picPath) {
- // alert("注册图片路径为空");
- // return;
- // }
- demo.addUser({
- userId: '12222222',
- faceImage: 'http://a06b9b3423f3cd5b8bee.qiniucdn.apicloud**.**/apicloud/699f1793405ddd92167c6c94d005371d.jpg'
- // faceImage: picPath
- //faceImage: 'widget://image/WechatIMG1319.jpeg'
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function countUser() {
- demo.countUser(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function clearAllUser() {
- demo.clearAllUser(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function removeUser() {
- demo.removeUser({
- userId: '12222222'
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function getUser() {
- demo.getUser({
- userId: '12222222'
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function listUser() {
- demo.listUser(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function setFaceConfig() {
- var ret = demo.setFaceConfig({
- //rotation : 2,
- //cameraId : 0,
- //rotate : 2,
- });
- alert(JSON.stringify(ret));
- }
- function openCompare() {
- demo.openCompare({
- rect: {
- x: 0,
- y: 0,
- w: api.frameWidth,
- h: api.frameHeight / 2,
- // marginTop: 400,
- // marginBottom: 400
- },
- fixedOn: api.frameName,
- fixed: true,
- }, function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function closeCompare() {
- demo.closeCompare(function (ret, err) {
- //alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function addFacepassListener() {
- demo.addFacepassListener(function (ret, err) {
- console.log(JSON.stringify(ret) + " " + JSON.stringify(err));
- if (ret.status) {
- //alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- api.toast({
- msg: JSON.stringify(ret) + " " + JSON.stringify(err)
- });
- } else {
- api.toast({
- msg: JSON.stringify(ret) + " " + JSON.stringify(err)
- });
- }
- });
- }
- function takePhoto() {
- demo.takePhoto(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- if (ret.status) {
- picPath = ret.imagePath;
- }
- });
- }
- function registerUser() {
- demo.registerUser(function (ret, err) {
- alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function changeDisplayOrientation(orientation) {
- demo.changeDisplayOrientation({
- displayOrientation: orientation
- }, function (ret, err) {
- //alert(JSON.stringify(ret) + " " + JSON.stringify(err));
- });
- }
- function getSupportedPreviewSizes() {
- var ret = demo.getSupportedPreviewSizes();
- alert(JSON.stringify(ret));
- }
- function getCommonSupportedPreviewSize() {
- var ret = demo.getCommonSupportedPreviewSize();
- alert(JSON.stringify(ret));
- }
- </script>
- </html>
复制代码
|
|