康巴易测肤/伤疤uniapp小程序类
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

pirms 1 mēnesi
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. # props
  2. |参数名|类型|默认值|可选择值|描述|
  3. |----|----|----|---|---|
  4. |buildActionContainer|Function|null|""|创建ActionContainer类的函数,要求返回值必需是ActionContainer类|
  5. |actions|Function|(takePhoto)=>return [straightenHead2, nodHead, shakeHead, straightenHead]|""|动作组(目前已有动作:点头,摇头,平视)|
  6. |isDev|boolen|false|true|是否是开发者模式,开启后可显示人脸的三个角度|
  7. |hasSwitch|boolen|false|true|默认只有前置摄像头,开启后可切换摄像头
  8. # emits
  9. |方法名|参数|描述|
  10. |----|---|---|
  11. |detectFailed|[]|核验失败|
  12. |photoChange|[url:'照片路径']|拍照后的回调|
  13. |detectOver|[]|检测完成|
  14. |showData|[faceData:'人脸数据']|每一帧的人脸数据|
  15. # slots
  16. |插槽名|参数|描述|
  17. |----|---|---|
  18. |default|无|用户可配合showData钩子展示人脸数据方便调试|
  19. # 方法
  20. ## initData
  21. 开始进行人脸核验 使用案例:
  22. ```
  23. //html
  24. <face-bio-assay ref="faceDetect" ></face-bio-assay>
  25. //js
  26. //调用
  27. this.$refs.faceDetect.initData()
  28. ```
  29. ## takePhoto
  30. 拍照获取照片,配合动作使用:
  31. ```
  32. 在每个动作创建时第二个参数是动作完成的回调 如平视动作的使用:
  33. const fun = (state) => {
  34. //state 有成功success和fail,ing(进行时不会触发该函数,忽略)
  35. if (state === 'success') {
  36. this.$refs.faceDetect.takePhoto() //调用拍照方法
  37. }
  38. }
  39. let straightenHead = new StraightenHead(10, fun)
  40. ```
  41. # 使用建议
  42. ```
  43. ios中bug解决方案:
  44. 在ios中,二次进入使用该组件有问题,解决办法:单独将该组件作为一个页面(或者下载demo查看),代码如下:
  45. //主页面
  46. <template>
  47. <view>
  48. <button type="default" @click="init">人脸检测</button>
  49. <image mode="aspectFit" :src="imgSrc" />
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. imgSrc: '',
  57. }
  58. },
  59. methods: {
  60. init(){
  61. uni.navigateTo({
  62. url:"/pages/face/face",
  63. events:{
  64. data: (path) => {
  65. this.imgSrc = path
  66. }
  67. }
  68. })
  69. }
  70. }
  71. }
  72. </script>
  73. //face.vue页 demo1
  74. <template>
  75. <view>
  76. <face-bio-assay :isDev="false" ref="faceDetect" @detectFailed="detectFailed" @photoChange="photoChange">
  77. </face-bio-assay>
  78. </view>
  79. </template>
  80. <script>
  81. import faceBioAssay from '@/uni_modules/face-bio-assay/components/face-bio-assay/face-bio-assay.vue'
  82. export default {
  83. components: {
  84. faceBioAssay,
  85. },
  86. onLoad(option) { //一定要onLoad,onShow在进入相机授权页面退回时会再次触发
  87. this.$refs.faceDetect.initData()
  88. },
  89. methods: {
  90. detectFailed() {
  91. uni.showToast({
  92. title: "人脸核验失败~",
  93. icon: 'none'
  94. })
  95. uni.navigateBack()
  96. },
  97. photoChange(path) {
  98. uni.navigateBack()
  99. this.getOpenerEventChannel().emit('data',path);
  100. }
  101. }
  102. }
  103. </script>
  104. //face demo2
  105. actions 本版本改用funaction否则action子类继承的父类信息在prop中会丢失.
  106. <template>
  107. <view>
  108. <face-bio-assay :hasSwitch="false" :actions="actions" :isDev="false" ref="faceDetect"
  109. @detectFailed="detectFailed" @photoChange="photoChange">
  110. </face-bio-assay>
  111. </view>
  112. </template>
  113. <script>
  114. import faceBioAssay from '@/uni_modules/face-bio-assay/components/face-bio-assay/face-bio-assay.vue'
  115. import StraightenHead from '@/uni_modules/face-bio-assay/components/face-bio-assay/actions/StraightenHead.js'
  116. export default {
  117. components: {
  118. faceBioAssay,
  119. },
  120. onLoad(option) {
  121. this.$refs.faceDetect.initData()
  122. },
  123. data() {
  124. return {
  125. actions: (takePhoto) => {
  126. return [new StraightenHead(10, (state) => {
  127. if (state === 'success') {
  128. takePhoto()
  129. }
  130. })]
  131. }
  132. }
  133. },
  134. methods: {
  135. detectFailed() {
  136. uni.showToast({
  137. title: "人脸核验失败~",
  138. icon: 'none'
  139. })
  140. uni.navigateBack()
  141. },
  142. photoChange(path) {
  143. uni.navigateBack()
  144. this.getOpenerEventChannel().emit('data', path);
  145. }
  146. }
  147. }
  148. </script>
  149. <style>
  150. </style>
  151. ```
  152. # 类的使用
  153. ## Action
  154. 动作类,开发者可继承该类重写 takeFrame 方法 如:
  155. ```
  156. //点头动作
  157. import Action from "./Action.js"
  158. class NodHead extends Action {
  159. constructor(second=10,fun) {
  160. //时间限制(s),结束时回调,完成次数(limit),基本提示
  161. super(second,fun,1,'请点头')
  162. this.maxPitch = 0
  163. this.minPitch = 0
  164. }
  165. takeFrame(faceData){
  166. let face = faceData.faceInfo[0]
  167. if(face.angleArray.pitch>this.maxPitch){
  168. this.maxPitch = face.angleArray.pitch
  169. }
  170. if(face.angleArray.pitch<this.minPitch){
  171. this.minPitch = face.angleArray.pitch
  172. }
  173. if(Math.abs(this.minPitch-this.maxPitch)>0.45 && (this.minPitch || this.maxPitch) ){
  174. this.frames.push('点头') //frames 完成的帧数组 根据该数组长度和limit判断是否完成
  175. this.maxPitch = 0
  176. this.minPitch = 0
  177. }
  178. }
  179. }
  180. export default NodHead
  181. ```
  182. ## ActionContainer
  183. 动作容器的使用案例
  184. ```
  185. buildActions() {
  186. if (this.buildActionContainer) {
  187. return this.buildActionContainer()
  188. }
  189. let actions = []
  190. if (!this.actions?.length) {
  191. let nodHead = new NodHead()
  192. const fun = (state) => {
  193. if (state === 'success') {
  194. this.takePhoto() //拍照
  195. }
  196. }
  197. let straightenHead = new StraightenHead(10, fun) //平视 结束拍照
  198. let straightenHead2 = new StraightenHead(10) //平视
  199. let shakeHead = new ShakeHead()
  200. actions = [straightenHead2, nodHead, shakeHead, straightenHead]
  201. } else {
  202. actions = this.actions
  203. }
  204. //new ActionContainer(actions,...)
  205. //动作组 actions
  206. //起始动作下标 index
  207. //初始提示 tip
  208. //绑定 完成所有动作的回调 endFun
  209. //绑定 动作进行中 ingFun
  210. //绑定 动作完成时 successFun
  211. //绑定 动作失败时 failFun
  212. let act = new ActionContainer(actions)
  213. act.end(() => { //也可用该方法绑定endFun方法
  214. this.detectOver()
  215. }).fail(() => { //也可用该方法绑定failFun方法
  216. this.cameraError()
  217. })
  218. //....其他方法类似
  219. return act
  220. }
  221. ```