rc-virtual-keyboard
Version:
38 lines (36 loc) • 903 B
JavaScript
import Tesseract from 'tesseract.js';
/**
* 简易的图片转文字方法
*
* @export
* @param {string} img
* @return {*} {Promise<string[]>}
*/
export function imgToWordV1(img) {
return new Promise(function (resolve) {
var str = [];
Promise.allSettled([Tesseract.recognize(img, 'chi_sim').then(function (result) {
console.log('result: ', result);
result.data.words.forEach(function (item) {
str.push(item.text);
});
}), Tesseract.recognize(img).then(function (result) {
console.log('result: ', result);
result.data.words.forEach(function (item) {
str.push(item.text);
});
})]).then(function () {
resolve(str);
});
});
}
/**
* TODO: 图片转文字方法
*
* @export
* @param {string} img
* @return {*} {Promise<string[]>}
*/
export function imgToWordV2(img) {
return Promise.resolve([]);
}