Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
node-native-ocr
Advanced tools
The native Node.js bindings to the Tesseract OCR project using N-API and node-addon-api.
Benefits:
tesseract
command line.buffer
s.Contributions are welcome.
Via npm:
$ npm install node-native-ocr
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'
Buffer
the content buffer of the image file.node-native-ocrOptions=
optionalReturns 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
The JavaScript Error
instance
String
Error code.String
Error message.Error
.ERR_READ_IMAGE
Rejects if it fails to read image data from file or buffer.
ERR_INIT_TESSER
Rejects if tesseract fails to initialize
// 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) => {
const appPath = (electron.app || electron.remote.app).getAppPath();
const tessdataPath = path.resolve(appPath, ocrPackagePath, "tessdata");
recognize(data.toPNG(), {
lang: ["eng", "ita"],
// output can be 'tsv' or 'txt'
output: "txt",
tessdataPath,
}).then(console.log);
}
);
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
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!
If you set the output option to 'tsv', you will get a table of data, cells separated by tabs. Since I had a hard time finding the format for it, I will paste it here: This is the original reference: https://www.tomrochette.com/tesseract-tsv-format
To build the node-native-ocr project for testing, navigate into the node-native-ocr directory and exec
npm run install
I had problems with some node versions. A version which definitelly worked for me was v16.13.0.
After changing the code, and rebuilding the project, just run npm run test
To test changes, compilation is needed before. prebuild will only recompile if there is no precompiled version for your platform in the "prebuilds" dir. That's we have to delete it before starting the compilation. You can use npm run rebuild-and-test
for that
MIT
FAQs
Native Node.js bindings for the Tesseract OCR project.
The npm package node-native-ocr receives a total of 106 weekly downloads. As such, node-native-ocr popularity was classified as not popular.
We found that node-native-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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.