【问题标题】:RNCamera text recognition fails on Portrait modeRNCamera 文本识别在纵向模式下失败
【发布时间】:2019-01-08 11:28:09
【问题描述】:

我正在使用 react-native-camera RNCamera 在弹出模式下开发应用程序。

顺便说一句,文本识别功能应该只适用于 Android。

在纵向模式下,它仅在每个检测事件中检测单个或两个字符,例如“O”、“IC”。

当我旋转到横向模式时,它工作得很好。

以下是我处理事件并呈现它的方式:

onTextRecognized = ({textBlocks}) => this.setState({ detectedTexts: textBlocks.map(b => b.value) })

renderDetectedText() {
    return (
      <View style={[styles.facesContainer,{left: 10, top:"50%"}]}>
        <Text style={styles.flipText}>{this.state.detectedTexts.join("\n")}</Text>
      </View>
    )
  }
renderCamera() {
<RNCamera
  ref={ref => {this.camera = ref;}}
  style={{flex: 1}}
  type={this.state.type}
  flashMode={this.state.flash}
  autoFocus={this.state.autoFocus}
  zoom={this.state.zoom}
  whiteBalance={this.state.whiteBalance}
  ratio={this.state.ratio}
  onTextRecognized={this.onTextRecognized}
  focusDepth={this.state.depth}
  permissionDialogTitle={'Permission to use camera'}
  permissionDialogMessage={'We need your permission to use your camera phone'}>
  {this.renderDetectedText()}
</RNCamera>
}

我正在使用真正的 Android 7.0 设备测试 int

这是 React-native-community 问题 gitHub 页面的 link

【问题讨论】:

    标签: android react-native text-recognition react-native-camera


    【解决方案1】:

    我能够通过修改一些 Java 代码来解决这个问题。 我注意到它与旋转有关。它试图自下而上地阅读文本。

    当我将手机从纵向旋转到横向时,它仍然会尝试从手机的自下而上进行识别,现在是从左到右。

    org.reactnative.camera.RNCameraView,(位于 node_modules/react-native-camera/android/src 上)我更改了 onFramePreview 方法以删除以下代码(已注释掉):

      @Override
      public void onFramePreview(CameraView cameraView, byte[] data, int width, int height, int rotation) {
        int correctRotation = RNCameraViewHelper.getCorrectCameraRotation(rotation, getFacing());
        int correctWidth = width;
        int correctHeight = height;
        byte[] correctData = data;
        //if (correctRotation == 90) {
        //  correctWidth = height;
        //  correctHeight = width;
        //  correctData = rotateImage(data, correctHeight, correctWidth);
        //}
        if (mShouldScanBarCodes && !barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate) {
        //...
      }
    

    我想知道旋转是否仅适用于某些设备型号。

    【讨论】:

    • 嗯,也许旋转是对其他 react-native-camera 功能的修复,例如面部检测..
    • 我遇到了类似的问题,当图像旋转时,相机无法识别 android 和 ios 中的文本。我检查了 org.reactnative.camera.RNCameraView 但没有您在 onFramePreview 中提到的代码行。我该如何存档?
    • react-native-camera 从那时起发生了很大变化。我鼓励你发布一个新问题,并在 react-native-camera 的 GitHub 问题页面中分享它。
    猜你喜欢
    • 1970-01-01
    • 2020-05-15
    • 2013-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-11-28
    相关资源
    最近更新 更多