fitness:function(){
var that = this
var camera_ctx = wx.createCameraContext()
const listener = camera_ctx.onCameraFrame((frame) => {
console.log(frame.data instanceof ArrayBuffer, frame.width, frame.height)
console.log("开始处理")
const query = wx.createSelectorQuery()
query.select('#myCanvas')
.fields({ node: true, size: true })
.exec((res) => {
const canvas = res[0].node
canvas.width = frame.width
canvas.height = frame.height
console.log(canvas.width)
console.log(canvas.height)
var data = new Uint8Array(frame.data);
var clamped = new Uint8ClampedArray(data);
console.log("实时帧数据添加到Canvas上")
const context1 = canvas.getContext('2d')
context1.putImageData(clamped, 0, 0, 0, 0, frame.width, frame.height)
wx.canvasToTempFilePath({
x: 0,
y: 0,
width: frame.width,
height: frame.height,
canvas: canvas,
fileType: 'jpg',
destWidth: frame.width,
destHeight: frame.height,
// // 精度修改
// quality:1,
success(res) {
// 临时文件转base64
wx.getFileSystemManager().readFile({
filePath: res.tempFilePath, //选择图片返回的相对路径
encoding: 'base64', //编码格式
success: function(res){
// 保存base64
console.log("获取的base64数据:",res.data)
that.data.mybase64 = res.data;
},
fail:function(error){
console.log("error",error)
}
})
},
fail:function(error) {
console.log("临时文件转base64失败",error);
}
}, that)
console.log("开始传输")
wx.request({
url: 'http://192.168.43.40:8080/predicts' ,
method: 'POST',
data: {base64Img:that.data.mybase64} ,
// dataType:'json',
header: {
'content-type': 'application/x-www-form-urlencoded'//自定义请求头信息
},
success:function(res){
console.log('===result===',res)
},
fail:function(error){
console.log("传输失败",error)
}
})
})
})
listener.start({
success(res){
console.log("开始监听")
}
})
},
请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。