monocr 0.1.3 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +33 -75
  2. package/bin/monocr.js +3 -3
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # monocr (JavaScript/Node.js)
1
+ # monocr
2
2
 
3
- Mon language OCR using ONNX Runtime for Node.js applications.
3
+ Mon language (mnw) OCR for Node.js.
4
4
 
5
5
  ## Installation
6
6
 
@@ -13,107 +13,65 @@ npm install monocr
13
13
  ```javascript
14
14
  const { read_image } = require("monocr");
15
15
 
16
- // Auto-downloads model on first run
17
- const text = await read_image("path/to/image.jpg");
16
+ // Automatically downloads model on first run
17
+ const text = await read_image("image.jpg");
18
18
  console.log(text);
19
19
  ```
20
20
 
21
21
  ## API
22
22
 
23
- ### read_image(imagePath, [modelPath], [charsetPath])
23
+ ### `read_image(imagePath, [modelPath], [charsetPath])`
24
24
 
25
- Recognize text from an image file.
25
+ Recognizes text from an image file.
26
26
 
27
- **Parameters:**
27
+ - `imagePath` (string): Path to image file.
28
+ - `modelPath` (string, optional): Path to ONNX model. Defaults to `~/.monocr/models/monocr.onnx`.
29
+ - `charsetPath` (string, optional): Path to charset file. Defaults to bundled charset.
28
30
 
29
- - `imagePath` - Path to image file (jpg, png)
30
- - `modelPath` - (Optional) Path to ONNX model. Defaults to auto-downloaded model.
31
- - `charsetPath` - (Optional) Path to charset file. Defaults to auto-downloaded file.
31
+ Returns: `Promise<string>`
32
32
 
33
- **Returns:** `Promise<string>` - Recognized text
33
+ ### `read_pdf(pdfPath, [modelPath], [charsetPath])`
34
34
 
35
- ### read_pdf(pdfPath, modelPath, charsetPath)
35
+ Recognizes text from a PDF file.
36
36
 
37
- Recognize text from a PDF file.
37
+ - `pdfPath` (string): Path to PDF file.
38
+ - `modelPath` (string, optional): As above.
39
+ - `charsetPath` (string, optional): As above.
38
40
 
39
- **Parameters:**
41
+ Returns: `Promise<string[]>` (Array of text per page)
40
42
 
41
- - `pdfPath` - Path to PDF file
42
- - `modelPath` - Path to ONNX model (optional)
43
- - `charsetPath` - Path to charset file (optional)
43
+ ### `read_image_with_accuracy(imagePath, groundTruth, [modelPath], [charsetPath])`
44
44
 
45
- **Returns:** `Promise<string[]>` - Array of text per page
45
+ Recognizes text and calculates accuracy against ground truth.
46
46
 
47
- ### read_image_with_accuracy(imagePath, groundTruth, modelPath, charsetPath)
47
+ - `imagePath` (string): Path to image file.
48
+ - `groundTruth` (string): Expected text.
48
49
 
49
- Recognize text with accuracy measurement.
50
+ Returns: `Promise<{text: string, accuracy: number}>`
50
51
 
51
- **Parameters:**
52
+ ## CLI Usage
52
53
 
53
- - `imagePath` - Path to image file
54
- - `groundTruth` - Expected text for accuracy calculation
55
- - `modelPath` - Path to ONNX model (optional)
56
- - `charsetPath` - Path to charset file (optional)
57
-
58
- **Returns:** `Promise<{text: string, accuracy: number}>` - Text and accuracy percentage
59
-
60
- ### MonOCR Class
61
-
62
- For advanced usage, use the `MonOCR` class directly:
63
-
64
- ```javascript
65
- const { MonOCR } = require("monocr");
66
-
67
- const ocr = new MonOCR("model.onnx", "charset.txt");
68
- await ocr.init();
69
-
70
- // Single line
71
- const text = await ocr.predictLine(imageSource);
72
-
73
- // Full page (with line segmentation)
74
- const results = await ocr.predictPage(imagePath);
75
- ```
76
-
77
- ## CLI
78
-
79
- The package includes a command-line tool:
54
+ The package includes a `monocr` command-line tool.
80
55
 
81
56
  ```bash
82
- # Single image
83
- monocr image path/to/image.jpg
84
-
85
- # PDF файл
86
- monocr pdf path/to/document.pdf
87
-
88
- # Batch processing
89
- monocr batch path/to/images/ -o results.json
90
- ```
91
-
92
- ## Examples
93
-
94
- See the `examples/` directory for detailed usage examples:
57
+ # Download model to cache (optional, happens automatically on first use)
58
+ monocr download
95
59
 
96
- - `simple.js` - Basic image OCR
97
- - `with-accuracy.js` - OCR with accuracy measurement
98
- - `batch.js` - Batch processing
60
+ # Recognize single image
61
+ monocr image input.jpg
99
62
 
100
- Run examples:
63
+ # Recognize PDF
64
+ monocr pdf document.pdf
101
65
 
102
- ```bash
103
- node examples/simple.js
66
+ # Batch process directory
67
+ monocr batch ./images -o results.json
104
68
  ```
105
69
 
106
70
  ## Model Files
107
71
 
108
- Models are **automatically downloaded** on first use to `~/.monocr/models/`.
109
-
110
- You can also trigger a manual download:
111
-
112
- ```bash
113
- monocr download
114
- ```
72
+ The ONNX model (`monocr.onnx`) is downloaded automatically to `~/.monocr/models/` on first use. The charset file is bundled with the package.
115
73
 
116
- Can also specify custom model paths if you prefer offline usage without the default cache.
74
+ To use a custom model, provide the `modelPath` argument to the API functions or CLI.
117
75
 
118
76
  ## License
119
77
 
package/bin/monocr.js CHANGED
@@ -14,7 +14,7 @@ program
14
14
  .command('image <path>')
15
15
  .description('Recognize text from an image file')
16
16
  .option('-m, --model <path>', 'Path to ONNX model (optional, auto-downloads)')
17
- .option('-c, --charset <path>', 'Path to charset file (optional, auto-downloads)')
17
+ .option('-c, --charset <path>', 'Path to charset file (optional)')
18
18
  .action(async (imagePath, options) => {
19
19
  try {
20
20
  const text = await read_image(imagePath, options.model, options.charset);
@@ -29,7 +29,7 @@ program
29
29
  .command('pdf <path>')
30
30
  .description('Recognize text from a PDF file')
31
31
  .option('-m, --model <path>', 'Path to ONNX model (optional, auto-downloads)')
32
- .option('-c, --charset <path>', 'Path to charset file (optional, auto-downloads)')
32
+ .option('-c, --charset <path>', 'Path to charset file (optional)')
33
33
  .action(async (pdfPath, options) => {
34
34
  try {
35
35
  const pages = await read_pdf(pdfPath, options.model, options.charset);
@@ -48,7 +48,7 @@ program
48
48
  .command('batch <directory>')
49
49
  .description('Process all images in a directory')
50
50
  .option('-m, --model <path>', 'Path to ONNX model (optional, auto-downloads)')
51
- .option('-c, --charset <path>', 'Path to charset file (optional, auto-downloads)')
51
+ .option('-c, --charset <path>', 'Path to charset file (optional)')
52
52
  .option('-o, --output <path>', 'Output file for results (optional)')
53
53
  .action(async (directory, options) => {
54
54
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "monocr",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "Cross-platform Mon (mnw) language OCR using ONNX Runtime. Supports Node.js.",
5
5
  "main": "src/index.js",
6
6
  "bin": {