我正在使用反应本土化、反应-本机-摄像机 (与frameProcessor一起)和迈尔吉特来执行设备文本识别。
我的代码在Android上工作,但是我总是在上获得空的结果。
以下是我的目标C:
static inline id scanOCR(Frame* frame, NSArray* args) {
MLKTextRecognizer *textRecognizer = [MLKTextRecognizer textRecognizer];
MLKVisionImage *image = [[MLKVisionImage alloc] initWithBuffer:frame.buffer];
image.orientation = frame.orientation;
NSError *error;
MLKText *result = [textRecognizer resultsInImage:image error:&error];
if (error != nil || result == nil) {
NSLog(@"%@", error); // <- This is NEVER called
} else {
NSLog(@"text: %@", result.text); // <- this is always empty
NSLog(@"blocks lenght: %lu", (unsigned long)result.blocks.count); // <- this is always 0
}
return @{@"text": result.text};
}该项目可以很好地编译,没有错误,但是results.text总是空的,即使摄像机正在为文本设置框架。
我认为MLKit的安装是恰当的。这是我的个人档案
require_relative '../node_modules/react-native/scripts/react_native_pods'
require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules'
platform :ios, '11.0'
target 'com.digitalbore.papertag' do
config = use_native_modules!
use_react_native!(
:path => config[:reactNativePath],
# to enable hermes on iOS, change `false` to `true` and then install pods
:hermes_enabled => false
)
pod 'GoogleMLKit/TextRecognition','2.2.0'
target 'com.digitalbore.papertagTests' do
inherit! :complete
# Pods for testing
pod 'react-native-splash-screen', :path => '../node_modules/react-native-splash-screen'
pod 'react-native-receive-sharing-intent', :path => '../node_modules/react-native-receive-sharing-intent'
end
# Enables Flipper.
#
# Note that if you have use_frameworks! enabled, Flipper will not work and
# you should disable the next line.
use_flipper!()
post_install do |installer|
react_native_post_install(installer)
__apply_Xcode_12_5_M1_post_install_workaround(installer)
end
end发布于 2022-02-07 14:15:24
通过将iPhone iOS版本更新到最后一个版本来解决问题。
发布于 2022-02-07 16:19:14
为了进一步了解这里的情况,您能验证一下您的设备上的Google quickstart视觉应用程序没有收到任何文本结果吗?
https://stackoverflow.com/questions/70987534
复制相似问题