Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
nativescript-ocr
Advanced tools
Readme
Optical Character Recognition - powered by Tesseract
tns plugin add nativescript-ocr
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 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
retrieveText
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);
}
);
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}`);
})
}
});
}
}
FAQs
Optical Character Recognition - powered by Tesseract
The npm package nativescript-ocr receives a total of 18 weekly downloads. As such, nativescript-ocr popularity was classified as not popular.
We found that nativescript-ocr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.