Socket
Socket
Sign inDemoInstall

rn-ocr-lib

Package Overview
Dependencies
0
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    rn-ocr-lib

React native library to perform OCR on images


Version published
Weekly downloads
17
increased by13.33%
Maintainers
1
Install size
90.8 kB
Created
Weekly downloads
 

Readme

Source

rn-ocr-lib

React native library to perform OCR on images. This library uses Tesseract library for image processing in android and vision library for iOS.

Npm package version Npm package monthly downloads License: MIT

React Native Android iOS

Showcase

Demo

Installation

npm install rn-ocr-lib
# or
yarn add rn-ocr-lib

Setup

Android

Create folder app/src/main/assets/tessdata. Inside tessdata place ${lang}.traineddata. You can get the train data files from here.

iOS

Vision library is present in iOS from version 13 or above. So update ios/Podfile.

platform :ios, '13.0'

Usage

Kindly refer the example project for usage for Android and iOS.

API Reference

Methods

import { getText, useOCREventListener } from 'rn-ocr-lib';

getText

Call this method to initiate image processing

getText(data: string, dataInputType: DataInputType, options?: Partial<OCROptions>): void;

useOCREventListener

Call this hook to setup listener to listen to progress, result and error.

useOCREventListener(
  (event: OCREventType, ocrEventResponse: OCREventResponse) => {
    switch (event) {
      case OCREvent.FINISHED:
        return;
      case OCREvent.PROGRESS:
        return;
      case OCREvent.ERROR:
        return;
      default:
        return;
    }
  }
);

Parameters

dataInputType

Input typeValueDescription
fileFILEPath to image file
base64BASE64Base64 string


options

OptionTypeiOSAndroidDefaultDescription
ocrEngineModeOCREngineModeYesYesFASTType of mode between fast or accurate recognization
pageSegModePageSegModeNoYesPSM_OSD_ONLYPage seg mode of tesseract
langstring[]YesYes["eng"]Languages for which recognization is needed


ocrEngineMode

Engine ModeValueDescription
FAST0Fast mode where recognization will be faster but mismatch of words is possible
ACCURATE1Accurate mode where time to process is more but more accurate text will be obtained
FAST_ACCURATE2Relavant for android tesseract where train data is provided for accurate and fast results but traindata file may be bigger compared to previous modes


pageSegMode (Android)

By default Tesseract expects a page of text when it segments an image. If you’re just seeking to OCR a small region, try a different segmentation mode.

Segmentation ModeValueDescription
PSM_OSD_ONLY0Orientation and script detection (OSD) only.
PSM_AUTO_OSD1Automatic page segmentation with OSD.
PSM_AUTO_ONLY2Automatic page segmentation, but no OSD, or OCR.
PSM_AUTO3Fully automatic page segmentation, but no OSD. (Default)
PSM_SINGLE_COLUMN4Assume a single column of text of variable sizes.
PSM_SINGLE_BLOCK_VERT_TEXT5Assume a single uniform block of vertically aligned text.
PSM_SINGLE_BLOCK6Assume a single uniform block of text.
PSM_SINGLE_LINE7Treat the image as a single text line.
PSM_SINGLE_WORD8Treat the image as a single word.
PSM_CIRCLE_WORD9Treat the image as a single word in a circle.
PSM_SINGLE_CHAR10Treat the image as a single character.
PSM_SPARSE_TEXT11Sparse text. Find as much text as possible in no particular order.
PSM_SPARSE_TEXT_OSD12Sparse text with OSD.
PSM_RAW_LINE13Raw line. Treat the image as a single text line, bypassing hacks that are Tesseract-specific.


event

Event typeValueDescription
FINISHEDfinishedEvent when OCR completes
PROGRESSprogressProgress event when OCR is processing
ERRORerrorError event OCR fails and some error is being thrown


ocrEventResponse

KeyTypeDescription
textstringResult text
progressnumberProgress percent
errorstringError message

Language Support

Android

Here is the list of supported languages for android.

iOS

Vision library currently has limited language support. It supports the following languages.

LanguageCode
Englisheng
Francefra
Italianita
Germandeu
Spanishspa
Portuguesepor
Chinese Simplifiedchi_sim
Chinese Traditionalchi_tra

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT


Made with create-react-native-library

Keywords

FAQs

Last updated on 24 May 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc