首页 > 解决方案 > Nativescript : 带有 nativescript-ocr 的相机照片资源

问题描述

我正在尝试使用 nativescript 相机模块拍照并在其上运行 nativescript-ocr 模块(https://github.com/EddyVerbruggen/nativescript-ocr)。

这是我的代码:

public saveToGallery: boolean = true;
public keepAspectRatio: boolean = true;
public width: number = 300;
public height: number = 300;
private ocr: OCR;

constructor() {
    this.ocr = new OCR();

}

ngOnInit(): void { 
}


onTakePhoto() {
    let options = {
        width: this.width,
        height: this.height,
        keepAspectRatio: this.keepAspectRatio,
        saveToGallery: this.saveToGallery
    };
    takePicture(options).
        then((imageAsset) => {
            console.log("Result is an image asset instance");

            let img: ImageSource = new ImageSource();

            img.fromAsset(imageAsset).then((success) => {
                if (success) {
                    this.ocr.retrieveText({
                        image: img,
                        whitelist: "ABCDEF",
                        blacklist: "0123456789",
                        onProgress: (percentage: number) => {
                            console.log(`Decoding progress: ${percentage}%`);
                        }
                    }).then(
                        (result: RetrieveTextResult) => {

                            console.log(`Result: ${result.text}`);
                        }, (error: string) => {
                            console.log(`Error: ${error}`);
                        })
                }
            });
        }).catch((err) => {
            console.log("Error -> " + err.message);
        });
}

onRequestPermissions() {
    requestPermissions();
}
}

相机插件工作正常,拍摄并保存照片,但是当我运行 onTakePhoto 时,我收到以下错误消息:

“ocr.retrieveText 中的错误:错误:java.lang.IllegalArgumentException:数据路径不存在!”

我不确定以正确的方式使用 .fromAsset,但我尝试了很多方法来解决这个问题

我做错了什么?

解决:我没有正确创建我的 tesseract/tessdata 文件夹

标签: ocrnativescriptangular2-nativescript

解决方案


推荐阅读