微信小程序实现人脸识别

目前项目有个需求,需要在微信小程序里实现一个自定义相机,然后用户可操作来拍照,最后将拍出来的照片进行人脸识别

<template>
  <view>
    <camera :device-position="devicePosition" flash="off" @error="error" style="width: 100%; height: 300px;">camera>
    <button type="primary" @click="takePhoto">拍照button>
    <button type="primary" @click="toggleDevicePosition">翻转摄像头button>
    <view>预览view>
    <image mode="widthFix" :src="src">image>
  view>
template>

<script>
export default {
  data () {
    return {
      src: "",
      cameraCtx: null,
      devicePosition: 'backs' //前置或后置摄像头,值为front, back
    }
  },
  onLoad () {
    this.cameraCtx = uni.createCameraContext();

  },
  methods: {
    takePhoto () {
      this.cameraCtx.takePhoto({
        quality: 'high',
        success: (res) => {
          this.src = res.tempImagePath
        }
      });
    },
    toggleDevicePosition () {
      this.devicePosition = this.devicePosition == 'back' ? 'front' : 'back'
    },
    error (e) {
      console.log(e.detail);
    }
  }
}
script>

```

最后将拍摄到的图片通过人脸识别接口请求对比一下就行了

你可能感兴趣的:(技术点,微信小程序,小程序)