小程序
小游戏
企业微信
微信支付
扫描小程序码分享
- 需求的场景描述(希望解决的问题)
微信小程序调用相机,支持调整相机焦距吗
- 希望提供的能力
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
希望小程序可以通过api自动调整相机焦距
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
是指手指触摸上去放大缩小?
不知道能不能通过代码控制·
现在我试过手指触摸只能放大 不能缩小
目前无相关API支持
有没有间接的办法来解决焦距远近的问题
<
view
class
=
'camera_view'
>
camera
device-position
"front"
flash
"off"
binderror
"error"
"camera"
bindstop
'bindstop'
'binderror'
></
</
//人脸确认
takePhoto: function (e) {
wx.showLoading({
title: '加载中',
})
let that = this
let ctx = wx.createCameraContext()
var account = wx.getStorageSync('account');
ctx.takePhoto({
quality: 'low',
success: (res) => {
console.log(res.tempImagePath)
that.setData({
src: res.tempImagePath
wx.getFileSystemManager().readFile({
filePath: res.tempImagePath, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success: res => { //成功的回调
console.log(1111);
var base64 = res.data; //base64编码
var face_url = app.globalData.urlPath3 + '/avatar/' + account.face;
var info = [
{
"image": face_url,
"image_type": "URL",
"face_type": "LIVE",
"quality_control": "LOW",
"liveness_control": "HIGH"
},
"image": base64,
"image_type": "BASE64",
}
];
console.log(info);
wx.request({
url: 'https://aip.baidubce.com/rest/2.0/face/v3/match?access_token=' + that.data.access_token,
data: info,
method: 'POST',
header: { 'content-type': 'application/json' },
success: function (res) {
console.log(res);
wx.hideLoading();
if (res.data.error_msg != "SUCCESS" || res.data.result.score < 80) {
console.log("识别失败");
wx.showToast({
title: '人脸不一致,不能继续考试!',
icon: "none",
duration: 2000
} else {
camera_comfirm: false,
wrap_hide: false,
var exam_id = that.data.exam_id;
var name = that.data.name;
var exam_score = that.data.exam_score;
var pass_score = that.data.pass_score;
var questionCount = that.data.questionCount;
var time_limit = that.data.time_limit;
var end_time = that.data.end_time;
var start_time = that.data.start_time;
wx.navigateTo({
url: '../exam/examTo?exam_id=' + exam_id + '&name=' + name + '&exam_score=' + exam_score + '&pass_score=' + pass_score + '&questionCount=' + questionCount + '&time_limit=' + time_limit + '&end_time=' + end_time + '&start_time=' + start_time,
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
希望小程序可以通过api自动调整相机焦距
是指手指触摸上去放大缩小?
不知道能不能通过代码控制·
现在我试过手指触摸只能放大 不能缩小
目前无相关API支持
有没有间接的办法来解决焦距远近的问题
<
view
class
=
'camera_view'
>
<
camera
device-position
=
"front"
flash
=
"off"
binderror
=
"error"
class
=
"camera"
bindstop
=
'bindstop'
binderror
=
'binderror'
></
camera
>
</
view
>
//人脸确认
takePhoto: function (e) {
wx.showLoading({
title: '加载中',
})
let that = this
let ctx = wx.createCameraContext()
var account = wx.getStorageSync('account');
ctx.takePhoto({
quality: 'low',
success: (res) => {
console.log(res.tempImagePath)
that.setData({
src: res.tempImagePath
})
wx.getFileSystemManager().readFile({
filePath: res.tempImagePath, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success: res => { //成功的回调
console.log(1111);
var base64 = res.data; //base64编码
var face_url = app.globalData.urlPath3 + '/avatar/' + account.face;
var info = [
{
"image": face_url,
"image_type": "URL",
"face_type": "LIVE",
"quality_control": "LOW",
"liveness_control": "HIGH"
},
{
"image": base64,
"image_type": "BASE64",
"face_type": "LIVE",
"quality_control": "LOW",
"liveness_control": "HIGH"
}
];
console.log(info);
wx.request({
url: 'https://aip.baidubce.com/rest/2.0/face/v3/match?access_token=' + that.data.access_token,
data: info,
method: 'POST',
header: { 'content-type': 'application/json' },
success: function (res) {
console.log(res);
wx.hideLoading();
if (res.data.error_msg != "SUCCESS" || res.data.result.score < 80) {
console.log("识别失败");
wx.showToast({
title: '人脸不一致,不能继续考试!',
icon: "none",
duration: 2000
})
} else {
that.setData({
camera_comfirm: false,
wrap_hide: false,
})
var exam_id = that.data.exam_id;
var name = that.data.name;
var exam_score = that.data.exam_score;
var pass_score = that.data.pass_score;
var questionCount = that.data.questionCount;
var time_limit = that.data.time_limit;
var end_time = that.data.end_time;
var start_time = that.data.start_time;
wx.navigateTo({
url: '../exam/examTo?exam_id=' + exam_id + '&name=' + name + '&exam_score=' + exam_score + '&pass_score=' + pass_score + '&questionCount=' + questionCount + '&time_limit=' + time_limit + '&end_time=' + end_time + '&start_time=' + start_time,
})
}
},
})
}
})
}
})
},