jawad zahoor
jawad zahoor

Reputation: 97

I want to read text from Image in React native . (android & ios)

Currently I am using react-native-camera "react-native-camera": "^4.2.1" App Craches when I open camera. But, If I remove this line Camera works fine.

onTextRecognized={(data) =>this.onTextRecognized(data)}

Note: I have used react native ml kit for this purpose. and I want to acheive text reading from image

    <RNCamera
      ref={ref => {
        this.camera = ref;
      }}
      style={styles.camera.preview}
      type={this.state.cameraType}
      flashMode={this.state.flashMode}
      ratio={this.props.ratio}
      captureAudio={false}
      autoFocus={this.props.autoFocus}
      whiteBalance={this.props.whiteBalance}
      androidCameraPermissionOptions={{
        title: 'Permission to use camera',
        message: 'We need your permission to use your camera',
        buttonPositive: 'Ok',
        buttonNegative: 'Cancel'
      }}
      androidRecordAudioPermissionOptions={{
        title: 'Permission to use audio',
        message: 'We need your permission to use your audio',
        buttonPositive: 'Ok',
        buttonNegative: 'Cancel'
      }}
      onTextRecognized={(data) => this.onTextRecognized(data)}
    />

Upvotes: 2

Views: 1735

Answers (1)

Mahammad Momin
Mahammad Momin

Reputation: 493

You can use @react-native-firebase/mlkit. It has a lot more functionality than just performing OCR. It also has both on-device support and cloud based support depending on your need.

Sample Code

import ml from '@react-native-firebase/ml';

const processingResult = await ml().cloudDocumentTextRecognizerProcessImage(media.uri);

method

const onImageSelect = async (media) => {
  if (!media.didCancel) {
    setImage(media.uri);
    const processingResult = await ml().cloudDocumentTextRecognizerProcessImage(media.uri);
    console.log(processingResult);
    setResult(processingResult);
  }
};

for full code read the below doc from below Link https://www.section.io/engineering-education/react-native-firebase-text-recognition/

hope it's working

Upvotes: 0

Related Questions