Socket
Socket
Sign inDemoInstall

nativescript-ocr

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    nativescript-ocr

Optical Character Recognition - powered by Tesseract


Version published
Weekly downloads
18
decreased by-30.77%
Maintainers
1
Install size
42.9 kB
Created
Weekly downloads
 

Readme

Source

NativeScript OCR

Build Status NPM version Downloads Twitter Follow

Optical Character Recognition - powered by Tesseract

Installation

tns plugin add nativescript-ocr

Setup

You'll need to add language files to help Tesseract recognizing text in the images you feed it.

Download version 3.04.00 of the tessdata files here and add your required language to the app/tesseract/tessdata/ folder of your app.

Note that if your language(s) has multiple files (like English: there's 9 files matching eng.*), copy all those files to the folder.

iOS

iOS searches for the tessdata folder in app/App_Resources/iOS, but instead of dulicating the folder you can create a symbolic link:

cd app/App_Resources/iOS
ln -s ../../tesseract/tessdata

API

retrieveText

JavaScript

This is just a basic example using the default settings, look at the TypeScript code below for a more elaborate example.

var OCRPlugin = require("nativescript-ocr");
var ocr = new OCRPlugin.OCR();

ocr.retrieveText({
  image: myImage
}).then(
    function (result) {
      console.log("Result: " + result.text);
    },
    function (error) {
      console.log("Error: " + error);
    }
);
TypeScript

This example shows how to use all possible (but optional) options you can pass into retrieveText:

import { OCR, RetrieveTextResult } from "nativescript-ocr";
import { ImageSource } from "image-source";

export Class MyOCRClass {
  private ocr: OCR;
  
  constructor() {
    this.ocr = new OCR();
  }

  doRecognize(): void {
    let img: ImageSource = new ImageSource();

    img.fromFile("~/samples/scanned.png").then((success: boolean) => {
      if (success) {
        this.ocr.retrieveText({
          image: img,
          whitelist: "ABCDEF",     // you can include only certain characters in the result
          blacklist: "0123456789", // .. or you can exclude certain characters from the result
          onProgress: (percentage: number ) => {
            console.log(`Decoding progress: ${percentage}%`);
          }
        }).then(
            (result: RetrieveTextResult) => {
              this.set(HelloWorldModel.BUSY_KEY, false);
              console.log(`Result: ${result.text}`);
            }, (error: string) => {
              console.log(`Error: ${err}`);
            })
      }
    });
  }
}

Keywords

FAQs

Last updated on 27 Apr 2017

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