首页 > 解决方案 > 有没有办法可以使用 Expo React Native 从图像中检测文本?

问题描述

我正在使用ExpoReact Native我希望能够从图像中检测文本。有没有我可以使用的软件包来实现这一目标?

我正在使用Expo camera module拍摄图片并将 URI 提供给我尝试使用 react-native-text-detector 的文本检测器,但我收到未定义函数 detectFromUri 的错误。我也尝试过使用 tesserect.js,但导入失败并显示“无法解析变量位置”。

await this.camera.takePictureAsync(options).then(photo => {
       photo.exif.Orientation = 1;
                //console.log(photo.uri);
        const visionResp = await RNTextDetector.detectFromUri(photo.uri);
        if (!(visionResp && visionResp.length > 0)) {
            throw "UNMATCHED";
        }
        console.log(visionResp);
});

我期待 visionResp 记录从检测返回的结果,但我得到了undefined is not an object (evaluating '_reactNativeTextDetector.default.detectFromUri')

标签: react-nativecameratesseractexpo

解决方案


您的项目是用创建的expo-cli吗?

如果是,Expo 目前不支持 OCR。canny.io上有一个功能请求,但您无法确定它何时可用。您唯一的选择是使用像这样的 OCR 服务。需要 Internet 连接。

如果没有,(并且该项目是用创建的react-native-cli)您应该能够成功使用react-native-text-detector. 只要确保正确链接包即可。文档在这里


推荐阅读