🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

node-native-ocr

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-native-ocr

Native Node.js bindings for the Tesseract OCR project.

0.1.3
Source
npm
Version published
Weekly downloads
54
-63.01%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status Coverage

node-native-ocr

The native Node.js bindings to the Tesseract OCR project using N-API and node-addon-api.

Benefits:

  • Avoid spawning tesseract command line.
  • Asynchronous I/O: Image reading and processing in insulated event loop backed by libuv.
  • Support to read image data from JavaScript buffers.

Contributions are welcome.

Install

Via npm:

$ npm install node-native-ocr

Usage

Recognize an Image Buffer

import {
  recognize
} from 'node-native-ocr'

import fs from 'fs-extra'

const filepath = path.join(__dirname, 'test', 'fixtures', 'node-native-ocr.jpg')

fs.readFile(filepath).then(recognize).then(console.log) // 'node-native-ocr'

recognize(image [, options])

  • image Buffer the content buffer of the image file.
  • options node-native-ocrOptions= optional

Returns Promise.<String> the recognized text if succeeded.

node-native-ocrOptions Object

{
  // @type `(String|Array.<String>)=eng`,
  //
  // Specifies language(s) used for OCR.
  //   Run `tesseract --list-langs` in command line for all supported languages.
  //   Defaults to `'eng'`.
  //
  // To specify multiple languages, use an array.
  //   English and Simplified Chinese, for example:
  // ```
  // lang: ['eng', 'chi_sim']
  // ```
  lang: 'eng'
}

Promise.reject(error)

  • error Error The JavaScript Error instance
    • code String Error code.
    • message String Error message.
    • other properties of Error.

code: ERR_READ_IMAGE

Rejects if it fails to read image data from file or buffer.

code: ERR_INIT_TESSER

Rejects if tesseract fails to initialize

Example of Using with Electron

// For details of `mainWindow: BrowserWindow`, see
// https://github.com/electron/electron/blob/master/docs/api/browser-window.md
mainWindow.capturePage({
  x: 10,
  y: 10,
  width: 100,
  height: 10

}, (data) => {
  recognize(data.toPNG()).then(console.log)
})

Compiling Troubles

For Mac OS users, if you are experiencing trouble when compiling, run the following command:

$ xcode-select --install

will resolve most problems.

Warnings:

xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance

resolver:

$ sudo xcode-select -s /Applications/Xcode.app/Contents/Developer

Why another node OCR package?

After doing a lot of research and trying to compile other node OCR packages for electron without success, I decided to create my own. Based on N-API, which would save me from a lot of trouble. Now it is used in Repeato, a low-code mobile app testing tool which works based on Computer Visions. Node-native-ocr enables Repeato to do text recognition and text assertions on Android and iOS and acrross all platforms such as React Native, Flutter or Unity.

Let me know about your projects too, and I can add them here to the list!

License

MIT

Keywords

tesseract

FAQs

Package last updated on 21 Jul 2021

Did you know?

Socket

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