Giter Club home page Giter Club logo

nativescript-ocr's Introduction

NativeScript OCR

Build Status NPM version Downloads Twitter Follow

โš ๏ธ This repo is hardly maintained - if you want an OCR solution in NativeScript, please consider using Firebase MLKit.

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}`);
            })
      }
    });
  }
}

nativescript-ocr's People

Contributors

eddyverbruggen avatar nathanwalker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.