在index.html中引入tesseract.min.js
<script src="<%=BASE_URL%>tesseract/tesseract.min.js"></script>
console.log("开始识别图片:",file, fileList,index)
this.$message({message: '图片识别中,请稍等...', type: 'success'});
this.picLoading = true
const worker = await Tesseract.createWorker('chi_sim',1,{
//配置本地资源路径,语言包的实际位置是通过langPath+'/'+lang+'.traineddata.gz'得到的,所以不要改语言包文件名
workerPath: './tesseract/worker.min.js',
corePath: './tesseract/tesseract-core.wasm.js',
langPath: './tesseract/lang-data',
});
await (async () => {
const img = URL.createObjectURL(file.raw);
await worker.load();
await worker.loadLanguage('chi_sim');
await worker.initialize('chi_sim', Tesseract.OEM.LSTM_ONLY);
const {data: {text}} = await worker.recognize(img, {rotateAuto: true}, {
imageColor: true,
imageGrey: true,
imageBinary: true
});
const result = text.replace(/\s*/g, "")
console.log('图片识别结果:',result)
this.picLoading = false
<el-upload
action="https://jsonplaceholder.typicode.com/posts/"
list-type="picture-card"
:auto-upload="false"
class="my-upload"
multiple
:file-list="fileList"
accept=".jpg,.jpeg,.png,.svg"
:on-change="(file, fileList) => {picHandleChange(file, fileList)}"
:on-remove="(file, fileList) => {handleRemove(file, fileList)}"
:on-preview="handlePictureCardPreview">
<i class="el-icon-plus"></i>
</el-upload>