openInstrFace.nvue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <template>
  2. <view class="face-container">
  3. <leven-arcFace
  4. ref="refLevenArcFace"
  5. style="width: 100%; flex: 1"
  6. :camera="camera"
  7. :video="video"
  8. @onError="onError"
  9. @onCameraOpened="onCameraOpened"
  10. @onCameraClosed="onCameraClosed"
  11. @onFaceResult="onFaceResult"
  12. ></leven-arcFace>
  13. <view class="back-btn" @click="backMain">
  14. <text class="back-val">返回</text>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. const module = uni.requireNativePlugin("leven-arcFace-ArcFaceModule");
  20. export default {
  21. data() {
  22. return {
  23. num: 0,
  24. // 摄像机配置,所有的参数都可以不传,不传则按默认的
  25. camera: {
  26. // 相机预览旋转角度
  27. rotation: 360,
  28. //相机预览模式,0:后置,1:前置(默认)
  29. facing: 1,
  30. //预览分辨率
  31. // size: [800, 600],
  32. // 摄像机预览圆角
  33. radius: 0,
  34. // 是否开启预览,默认:true
  35. preview: true,
  36. },
  37. // 视频检测配置,所有参数都可以不传,不传则按默认的
  38. video: {
  39. // 视频检测角度,可接收参数,0,90,180,270(默认),360(全方位检测)
  40. orient: 360,
  41. // 是否进行活体检测(默认为true)
  42. liveness: true,
  43. // 人脸注册同一人是否可以多次注册(默认:true)
  44. registerMultiple: true,
  45. // 人脸识别成功后是否展示左上角人脸识别图片(默认:true)
  46. showIdentifyImage: false,
  47. // 人脸框是否处于X反向状态,如果未设置该参数人脸框和人脸处于反向请将该参数设置为true
  48. isContraryX: false,
  49. // 人脸框是否处于Y反向状态,如果未设置该参数人脸框和人脸处于反向请将该参数设置为true
  50. isContraryY: false,
  51. // 识别阈值
  52. similar: 0.8,
  53. // 识别的最小人脸比例,如果失败比较敏感可以适当调小,默认:16
  54. detectFaceScaleVal: 10,
  55. showIdentifyText: false,
  56. },
  57. };
  58. },
  59. onLoad() {},
  60. onHide() {
  61. this.closeFace();
  62. },
  63. onShow() {
  64. console.log("开启人脸检查");
  65. this.openFace();
  66. },
  67. mounted() {},
  68. methods: {
  69. backMain() {
  70. uni.redirectTo({
  71. url: "/pages/home/index",
  72. });
  73. },
  74. // 注册人脸
  75. register() {
  76. if (this.$refs.refLevenArcFace) {
  77. console.log("开始注册人脸");
  78. const num = this.num++;
  79. this.$refs.refLevenArcFace.register(
  80. {
  81. // 注册后保存的id(可以不传该参数,默认时间戳)
  82. // id: "456",
  83. //注册后保存的名字(可以不传该参数,默认时间戳)
  84. name: "用户" + num,
  85. },
  86. (res) => {
  87. console.log(res);
  88. }
  89. );
  90. }
  91. },
  92. // 切换相机
  93. switchCamera() {
  94. if (this.$refs.refLevenArcFace) {
  95. this.$refs.refLevenArcFace.switchCamera((res) => {
  96. console.log(res);
  97. });
  98. }
  99. },
  100. // 关闭预览
  101. stop() {
  102. if (this.$refs.refLevenArcFace) {
  103. this.$refs.refLevenArcFace.stop((res) => {
  104. console.log(res);
  105. });
  106. }
  107. },
  108. // 开启预览
  109. start() {
  110. if (this.$refs.refLevenArcFace) {
  111. this.$refs.refLevenArcFace.start((res) => {
  112. console.log(res);
  113. });
  114. }
  115. },
  116. // 关闭人脸检测
  117. closeFace() {
  118. if (this.$refs.refLevenArcFace) {
  119. this.$refs.refLevenArcFace.closeFace((res) => {
  120. console.log(res);
  121. });
  122. }
  123. },
  124. // 开启人脸检测
  125. openFace() {
  126. if (this.$refs.refLevenArcFace) {
  127. this.$refs.refLevenArcFace.openFace((res) => {
  128. console.log("开启人脸检查", res);
  129. });
  130. }
  131. },
  132. // 错误事件
  133. onError(e) {
  134. console.log("错误信息", e);
  135. },
  136. // 相机打开事件
  137. onCameraOpened(e) {
  138. console.log("相机打开事件", e);
  139. },
  140. // 相机关闭事件
  141. onCameraClosed(e) {
  142. console.log("相机关闭事件", e);
  143. },
  144. // 相机配置改变事件
  145. onCameraConfigurationChanged(e) {
  146. console.log(e);
  147. },
  148. // 人脸识别结果
  149. onFaceResult(e) {
  150. console.log("人脸识别结果", e.detail);
  151. if (e.detail.status == "1") {
  152. uni.showToast({
  153. title: "人脸识别成功",
  154. icon: "success",
  155. duration: 1000,
  156. });
  157. setTimeout(() => {
  158. uni.setStorageSync("handleType", "openInstr");
  159. uni.redirectTo({
  160. url: `/pages/home/index?id=${e.detail.id}`,
  161. });
  162. }, 1000);
  163. }
  164. },
  165. },
  166. };
  167. </script>
  168. <style>
  169. .face-container {
  170. width: 750rpx;
  171. height: 100vh;
  172. flex: 1;
  173. background: skyblue;
  174. }
  175. .back-btn {
  176. position: fixed;
  177. right: 30px;
  178. bottom: 30px;
  179. width: 100px;
  180. height: 40px;
  181. border-radius: 4px;
  182. background: #ecf5ff;
  183. display: flex;
  184. justify-content: center;
  185. align-items: center;
  186. }
  187. .back-val {
  188. color: #606266;
  189. font-size: 18px;
  190. }
  191. </style>