提交 622a64cb authored 作者: 羊富学's avatar 羊富学

贝因美优化

上级 cf87ee39
...@@ -11,9 +11,11 @@ Page({ ...@@ -11,9 +11,11 @@ Page({
* 页面的初始数据 * 页面的初始数据
*/ */
data: { data: {
src:'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg', src: 'https://res.wx.qq.com/wxdoc/dist/assets/img/0.4cb08bb4.jpg',
height: 0, height: 0,
width: 0, width: 0,
frame: {},
tag: false,
showPage: '' // '' 为拍照 ,'error'为不通过,'success' 为通过 showPage: '' // '' 为拍照 ,'error'为不通过,'success' 为通过
}, },
...@@ -21,12 +23,127 @@ Page({ ...@@ -21,12 +23,127 @@ Page({
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
onLoad(options) { onLoad(options) {
this.cameraContext = wx.createCameraContext() // this.cameraContext = wx.createCameraContext()
// this.cameraContext.setZoom({ // this.cameraContext.setZoom({
// zoom: 1 // zoom: 1
// }) // })
this.cameraFrame() // this.cameraFrame()
// this.cameraFrameApi() // this.cameraFrameApi()
var nCounter = 0
var that = this
var tag = true
this.ctx = wx.createCameraContext()
this.listener = this.ctx.onCameraFrame((frame) => {
if (nCounter == 25 && tag) {
tag = false
// if (this.data.tag) return
// this.data.tag = true
// setTimeout(() => {
// this.data.tag = false
// }, 1000)
this.setData({
['frame.width']: frame.width,
['frame.height']: frame.height
})
var data = new Uint8Array(frame.data)
var clamped = new Uint8ClampedArray(data)
wx.canvasPutImageData({
canvasId: 'myCanvas',
x: 0,
y: 0,
width: frame.width, //288 288
height: frame.height, //512 381
data: clamped,
success: () => {
wx.canvasToTempFilePath({
canvasId: 'myCanvas',
x: 0,
y: (frame.height - frame.width) / 2,
width: frame.width, //288
height: frame.width, //352
fileType: 'jpg',
destWidth: frame.width,
destHeight: frame.width,
// 精度修改
quality: 'high',
success: (res) => {
const base = wx
.getFileSystemManager()
.readFileSync(res.tempFilePath, 'base64')
// console.log('base',base)
that.setData({
src: res.tempFilePath
})
wx.request({
url: 'https://www.7856.work:4433/clear_fuzzy_detect/', //目标检测+判断清晰模糊接口 测试地址
// url: 'https://tj5.cc:4433/object/',
// url:'https://ai.china315net.com:35437/object/',
method: 'POST',
data: {
base
},
success: async()=> {
console.log('识别二维码成功');
// 原图(默认放大两倍)
const photo1 = await that.handleTakePoto(wx.createCameraContext(), 1)
// 放大图(四倍)
// await new Promise((resovle) => {
// setTimeout(() => {
// resovle()
// },300)
// })
console.log('5555');
const photo2 = await that.handleTakePoto(wx.createCameraContext(), 4, {
flash: 'on'
})
console.log(photo2.tempImagePath, 'photo1');
// this.setData({
// src:photo2.tempImagePath
// })
// 原图base64
const base64_1 = wx
.getFileSystemManager().readFileSync(photo1.tempImagePath, 'base64')
// 放大四倍图 base64
const base64_2 = wx
.getFileSystemManager().readFileSync(photo2.tempImagePath, 'base64')
// 请求接口
Promise.all([that.handleApiCheck(base64_1, 'small'), that.handleApiCheck(base64_2, 'big')])
.then(value => {
let pageType = 'error'
const result1 = value[0],
result2 = value[1]
// data.result == 2 为真
if (result1.data.result == 2 && result2.data.result == 2) {
pageType = 'success'
}
that.setData({
showPage: pageType
})
})
},
fail(err) {
tag = true
console.log(err);
}
})
},
fail: (error) => {
console.log('转换临时文件失败:', error)
}
})
},
fail: (error) => {
console.log('绘制图像数据失败', error)
}
})
}
nCounter++
if (nCounter >= 50) {
nCounter = 0
}
}, 100)
this.listener.start()
}, },
...@@ -35,7 +152,7 @@ Page({ ...@@ -35,7 +152,7 @@ Page({
let flag = true let flag = true
const that = this const that = this
const listener = this.cameraContext.onCameraFrame(async (frame) => { const listener = this.cameraContext.onCameraFrame(async (frame) => {
console.log(frame.width,frame.height); console.log(frame.width, frame.height);
if (flag) { if (flag) {
flag = false flag = false
// 文件系统 // 文件系统
...@@ -47,8 +164,8 @@ Page({ ...@@ -47,8 +164,8 @@ Page({
// 实时帧渲染到canvas // 实时帧渲染到canvas
await wx.canvasPutImageData({ await wx.canvasPutImageData({
canvasId: 'myCanvas', canvasId: 'myCanvas',
x:-frame.width / 4, x: -frame.width / 4,
y:-frame.height / 4, y: -frame.height / 4,
width: frame.width, width: frame.width,
height: frame.height, height: frame.height,
data: new Uint8ClampedArray(frame.data), data: new Uint8ClampedArray(frame.data),
...@@ -66,13 +183,13 @@ Page({ ...@@ -66,13 +183,13 @@ Page({
}) })
this.setData({ this.setData({
src:fileData.tempFilePath src: fileData.tempFilePath
}) })
const base = fileSystem.readFileSync(fileData.tempFilePath, 'base64') const base = fileSystem.readFileSync(fileData.tempFilePath, 'base64')
// console.log('qr_result',flag,5555,base); // console.log('qr_result',flag,5555,base);
const qr_result = await that.handleCodeAnalysis(base) const qr_result = await that.handleCodeAnalysis(base)
console.log('qr_result',flag,5555,qr_result.data); console.log('qr_result', flag, 5555, qr_result.data);
// 前端校验取消 // 前端校验取消
// const data = new Uint8ClampedArray(frame.data); // const data = new Uint8ClampedArray(frame.data);
// // const nData = data.slice(data.length / 4, data.length / 4 * 3) // // const nData = data.slice(data.length / 4, data.length / 4 * 3)
...@@ -80,7 +197,7 @@ Page({ ...@@ -80,7 +197,7 @@ Page({
// console.log('qe_result',qian_result,999) // console.log('qe_result',qian_result,999)
// console.log('qr_result.data.codeinfo',qr_result.data.codeinfo) // console.log('qr_result.data.codeinfo',qr_result.data.codeinfo)
if (qr_result.data.codeinfo) { if (qr_result.data.codeinfo) {
// 原图(默认放大两倍) // 原图(默认放大两倍)
const photo1 = await that.handleTakePoto(that.cameraContext, 1) const photo1 = await that.handleTakePoto(that.cameraContext, 1)
// 放大图(四倍) // 放大图(四倍)
...@@ -90,8 +207,10 @@ Page({ ...@@ -90,8 +207,10 @@ Page({
// },300) // },300)
// }) // })
console.log('5555'); console.log('5555');
const photo2 = await that.handleTakePoto(that.cameraContext, 4,{flash:'on'}) const photo2 = await that.handleTakePoto(that.cameraContext, 4, {
console.log(photo2.tempImagePath,'photo1'); flash: 'on'
})
console.log(photo2.tempImagePath, 'photo1');
// this.setData({ // this.setData({
// src:photo2.tempImagePath // src:photo2.tempImagePath
// }) // })
...@@ -101,7 +220,7 @@ Page({ ...@@ -101,7 +220,7 @@ Page({
const base64_2 = fileSystem.readFileSync(photo2.tempImagePath, 'base64') const base64_2 = fileSystem.readFileSync(photo2.tempImagePath, 'base64')
// 请求接口 // 请求接口
Promise.all([that.handleApiCheck(base64_1,'small'), that.handleApiCheck(base64_2,'big')]) Promise.all([that.handleApiCheck(base64_1, 'small'), that.handleApiCheck(base64_2, 'big')])
.then(value => { .then(value => {
let pageType = 'error' let pageType = 'error'
const result1 = value[0], const result1 = value[0],
...@@ -117,7 +236,7 @@ Page({ ...@@ -117,7 +236,7 @@ Page({
} else { } else {
setTimeout(() => { setTimeout(() => {
flag = true flag = true
},750) }, 750)
} }
} }
...@@ -155,12 +274,12 @@ Page({ ...@@ -155,12 +274,12 @@ Page({
await new Promise((resovle) => { await new Promise((resovle) => {
setTimeout(() => { setTimeout(() => {
resovle() resovle()
},300) }, 300)
}) })
} }
return await context.takePhoto({ return await context.takePhoto({
flash:param?.flash || 'off', flash: param?.flash || 'off',
quality:'high', quality: 'high',
selfieMirror: param?.selfieMirror || false, selfieMirror: param?.selfieMirror || false,
// success(res) { // success(res) {
// console.log(res,zoom,222222); // console.log(res,zoom,222222);
...@@ -169,7 +288,7 @@ Page({ ...@@ -169,7 +288,7 @@ Page({
}, },
// 接口请求 // 接口请求
handleApiCheck(base64,type) { handleApiCheck(base64, type) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
wx.request({ wx.request({
url: 'https://www.7856.work:4433/api/Bym_classfily_post/', url: 'https://www.7856.work:4433/api/Bym_classfily_post/',
......
<!--pages/beiyinmei/beiyinmei.wxml--> <!--pages/beiyinmei/beiyinmei.wxml-->
<view wx:if="{{!showPage}}" style="height: 100vh;width: 100vw;position: relative;z-index: 99;"> <view wx:if="{{!showPage}}" style="height: 100vh;width: 100vw;position: relative;z-index: 99;">
<!-- <image src="{{src}}" mode="widthFix" style="position: absolute;top: 0px;left: 0px;z-index: 9999;"/> --> <!-- <image src="{{src}}" mode="widthFix" style="position: absolute;top: 0px;left: 0px;z-index: 9999;"/> -->
<camera device-position="back" frame-size="high" flash="on" style="width: 100%; height: 100%;" mode="normal"> <camera style="height: 100%;width: 100%;" flash="on" devic-position="back" frame-size="large" resolution="high">
<view class="prompt" style="position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);z-index: 999999;">
<image src="/assets/imgs/拍照框.png" style="position: relative;z-index: 99999999;" style="width: 25%;" mode="widthFix" />
<text>请把二维码放置拍照框内</text>
</view>
</camera> </camera>
<view class="prompt" style="position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);z-index: 999999;">
<image src="/assets/imgs/拍照框.png" style="position: relative;z-index: 99999999;" style="width: 25%;" mode="widthFix" />
<text>请把二维码放置拍照框内</text>
</view>
</view> </view>
<view wx:if="{{showPage == 'success'}}" class="success-content full"> <view wx:if="{{showPage == 'success'}}" class="success-content full">
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
</view> </view>
</view> </view>
<view style="visibility: hidden;position: fixed;top: 99999px;left: 0px;"> <view style="visibility:hidden; position:fixed;top: 9999px;left: 0;">
<canvas canvas-id="myCanvas" id="myCanvas" style="width:{{500}}px;height:{{500}}px;" /> <canvas canvas-id="myCanvas" style='width:{{frame.width}}px; height:{{frame.height}}px;'></canvas>
</view> <image src="{{src}}" mode="widthFix" style='width: {{windowWidth}}px; height: {{windowWidth}}px;border: 1px solid red; '></image>
</view>
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论