微信小程序,与百度人脸库对比,并读出用户数据

这是微信wxml的代码,构建出一个照相机,并且可以实现前后转换摄像头

<!--pages/camera/camera.wxml-->
<!-- <text>pages/camera/camera.wxml</text> -->
 <camera device-position="{
  {status}}" flash="off" binderror="error" style="width: 100%; height: 300px;"></camera>
 <view class="weui-btn-area">
          <button class="weui-btn" type="primary" bindtap="takePhoto">拍照                   </button>
</view> 
<switch checked  bindchange='switch1Change'/>
 

以下是js代码,实现转换摄像头与访问接口

// pages/camera/camera.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    path:null,
    status:'front'
  },
  switch1Change:function(e){
    if (e.detail.value) {
      this.setData({ status: 'back' })
    } else {
      this.setData({ status: 'front'})
    }
  
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.ctx=wx.createCameraContext()
  },
  takePhoto(){
    this.ctx.takePhoto({
      quality: 'high',
      success: (res) => {
        console.log(res.tempImagePath);
        this.setData({ path: res.tempImagePath})
        wx.uploadFile({
          url: 'login', //仅为示例,非真实的接口地址
          filePath: this.data.path,
          name: 'file',
         
          success: (res)=> {
            // var data = res.data;
            // var msg=JSON.parse(data);
            // console.log(msg);
            wx.showModal({
              title: '提示',
              content: res.data,
            })
          }
        })
      }
    })
  },
  startRecord(){
    this.ctx.startRecord({
      success: (res) => {
        console.log('startRecord')
      }
    })
  },
  stopRecord(){
    this.ctx.stopRecord({
      success: (res) => {
        this.setData({
          src: res.tempThumbPath,
          videoSrc:res.tempVideoPath
        })
      }
    })
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值