
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
ddddocr-node
Advanced tools
This project is a port of the Python project DdddOcr.
The goal is to make it easy to use this trained model for text detection in JavaScript.
npm install ddddocr-node
Primarily used for recognizing single-line text, where the text occupies the main portion of the image, such as common alphanumeric captchas. This project can recognize Chinese characters, English (with random case sensitivity or case constrained by specified ranges), numbers, and certain special characters.
const { DdddOcr } = require('ddddocr-node');
const ddddOcr = new DdddOcr();
const result = await ddddOcr.classification('example.jpg');
console.log(result);
This library includes two built-in OCR models, which do not switch automatically by default. You need to use setOcrMode() with parameters to switch between them.
const { DdddOcr, MODEL_TYPE } = require('ddddocr-node');
// Method 1: Enable Beta OCR mode after creating an instance
const ddddOcr = new DdddOcr();
ddddOcr.setOcrMode(MODEL_TYPE.OCR_BETA);
// Method 2: Directly enable Beta OCR mode during instance creation
const ddddOcr = new DdddOcr().setOcrMode(MODEL_TYPE.OCR_BETA);
const result = await ddddOcr.classification('example.jpg');
console.log(result);
To provide more flexible control and range restriction for OCR results, the project supports setting range limitations on OCR results.
The setRanges() method restricts the returned characters.
This method accepts one parameter. If the input is of type int, it refers to a predefined character set restriction. If the input is of type string, it represents a custom character set.
For int input, please refer to the table below.
| Parameter Value | Meaning |
|---|---|
| 0 | Pure integers 0-9 |
| 1 | Pure lowercase letters a-z |
| 2 | Pure uppercase letters A-Z |
| 3 | Lowercase letters a-z + uppercase letters A-Z |
| 4 | Lowercase letters a-z + integers 0-9 |
| 5 | Uppercase letters A-Z + integers 0-9 |
| 6 | Lowercase letters a-z + uppercase letters A-Z + integers 0-9 |
| 7 | Default character set - lowercase a-z, uppercase A-Z, and integers 0-9 |
For string input, provide a string where each character is treated as a candidate character, e.g., "0123456789+-x/=".
const { DdddOcr, CHARSET_RANGE } = require('ddddocr-node');
const ddddOcr = new DdddOcr();
ddddOcr.setRanges(CHARSET_RANGE.NUM_CASE);
const result = await ddddOcr.classification('example.jpg');
console.log(result);
The main purpose is to quickly detect the possible location of the target object in the image. Since the detected target may not necessarily be text, this function only provides the bounding box (bbox) location of the target. In object detection, we typically use a bbox (bounding box) to describe the target location. A bbox is a rectangular frame, which can be determined by the x and y coordinates of the top-left corner and the x and y coordinates of the bottom-right corner.
const { DdddOcr } = require('ddddocr-node');
const ddddOcr = new DdddOcr();
const result = await ddddOcr.detection('example.jpg');
console.log(result);
If you want to add the detected bounding box to the original image, here is an example.
const { Jimp, cssColorToHex } = require('jimp');
const { DdddOcr } = require('ddddocr-node');
const { drawRectangle } = require('ddddocr-core');
const ddddOcr = new DdddOcr();
const result = await ddddOcr.detection('example.jpg');
const image = await Jimp.read('example.jpg');
const color = cssColorToHex('#ff0000');
for (let i = 0; i < result.length; i++) {
const [x1, y1, x2, y2] = result[i];
const points = [
{ x: x1, y: y1 },
{ x: x2, y: y1 },
{ x: x2, y: y2 },
{ x: x1, y: y2 }
];
drawRectangle(image, points, color);
}
image.write('output.jpg');
FAQs
The JS version of DdddOcr
The npm package ddddocr-node receives a total of 158 weekly downloads. As such, ddddocr-node popularity was classified as not popular.
We found that ddddocr-node demonstrated a healthy version release cadence and project activity because the last version was released less than 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.