硬件:红米5plus
系统:PixelExperience
试用模式在调试基座
加入了需要的权限
代码完全从页面复制粘贴
TypeError: Cannot read property 'ocr' of undefined
有什么需要注意的吗?
第一次使用原生插件
<template>
<view class="content">
<button type="default" @click="ocr">传图片文件进行ocr识别</button>
<button type="default" @click="base64ocr">传base64图片进行OCR识别 </button>
<image :src="imgsrc"></image>
<view style="padding: 10px;margin: 10px;word-break: break-all;">
{{ocrresult}}
</view>
</view>
</template>
<script>
export default {
data() {
return {
ocrresult:'识别结果',
imgsrc:''
}
},
onLoad() {
},
methods: {
ocr()
{
var that=this;
let ocrmodule = uni.requireNativePlugin('guang-ocrmodule');
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album','camera'],
success: function (res) {
let filepath= res.tempFilePaths[0];
let fullpath = plus.io.convertLocalFileSystemURL(filepath);
console.log(JSON.stringify(res.tempFilePaths))
console.log(fullpath);
that.imgsrc=fullpath;
uni.showLoading({
title: '识别中'
});
var ret = ocrmodule.ocr({
"file":fullpath,
},e=>{
console.log(JSON.stringify(e));
that.ocrresult=JSON.stringify(e);
uni.hideLoading();
})
}
});
},
base64ocr()
{
var that=this;
let ocrmodule = uni.requireNativePlugin('guang-ocrmodule');
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success(res) {
let path= res.tempFilePaths[0];
var bitmap = new plus.nativeObj.Bitmap("test");
bitmap.load(path,function(){
var base64=bitmap.toBase64Data();
that.imgsrc=base64
uni.showLoading({
title: '识别中'
});
var ret = ocrmodule.ocr({
"base64":base64,
},e=>{
that.ocrresult=JSON.stringify(e);
console.log(JSON.stringify(e));
uni.hideLoading();
})
})
}
});
}
}
}
</script>
<style>
.content {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.logo {
height: 200rpx;
width: 200rpx;
margin-top: 200rpx;
margin-left: auto;
margin-right: auto;
margin-bottom: 50rpx;
}
.text-area {
display: flex;
justify-content: center;
}
.title {
font-size: 36rpx;
color: #8f8f94;
}
</style>
1 个回复
zzguang
插件的使用:在manifest中,点“App原生插件配置”,点“云端插件”,选择“离线OCR文字识别“插件
然后打包自定义基座(原生APP云打包->打自定义调试基座),
打包完成,点运行到手机->运行基座选择-> 选择自定义调试基座, 再点运行->运行到安卓APP基座