{"id":31771656,"url":"https://github.com/vrajvyas11/multilingual_purejs_based_ocr","last_synced_at":"2025-10-14T07:02:10.696Z","repository":{"id":318505016,"uuid":"1071571555","full_name":"VrajVyas11/Multilingual_PureJS_Based_OCR","owner":"VrajVyas11","description":"Multilingual PureJS OCR: A zero-dependency JS library for accurate text extraction from images. Supports English, Chinese, Japanese, Korean \u0026 Latin via PaddleOCR ONNX models. Customizable detection, recognition \u0026 grouping. No Python needed—run in Node.js!","archived":false,"fork":false,"pushed_at":"2025-10-07T15:12:18.000Z","size":38130,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-07T16:33:13.420Z","etag":null,"topics":["image-processing","multilingual","no-python","nodejs","ocr","onnxruntime-node","optical-character-recognition","pure-javascript","text-detection-recognition"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/multilingual-purejs-ocr","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VrajVyas11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-07T14:22:39.000Z","updated_at":"2025-10-07T15:17:46.000Z","dependencies_parsed_at":"2025-10-09T06:15:17.370Z","dependency_job_id":null,"html_url":"https://github.com/VrajVyas11/Multilingual_PureJS_Based_OCR","commit_stats":null,"previous_names":["vrajvyas11/multilingual_purejs_based_ocr"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/VrajVyas11/Multilingual_PureJS_Based_OCR","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VrajVyas11%2FMultilingual_PureJS_Based_OCR","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VrajVyas11%2FMultilingual_PureJS_Based_OCR/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VrajVyas11%2FMultilingual_PureJS_Based_OCR/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VrajVyas11%2FMultilingual_PureJS_Based_OCR/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VrajVyas11","download_url":"https://codeload.github.com/VrajVyas11/Multilingual_PureJS_Based_OCR/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VrajVyas11%2FMultilingual_PureJS_Based_OCR/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279018122,"owners_count":26086280,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image-processing","multilingual","no-python","nodejs","ocr","onnxruntime-node","optical-character-recognition","pure-javascript","text-detection-recognition"],"created_at":"2025-10-10T03:45:30.492Z","updated_at":"2025-10-14T07:02:10.686Z","avatar_url":"https://github.com/VrajVyas11.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Multilingual PureJS OCR 🚀\n\n[![npm version](https://badge.fury.io/js/multilingual-purejs-ocr.svg)](https://www.npmjs.com/package/multilingual-purejs-ocr)\n\nA powerful onnxruntime-node based, **pure JavaScript OCR library** that works directly in Node.js - **no Python dependencies required!** Extract text from images with industry-leading accuracy using PaddleOCR models.\n\n## ✨ Features\n\n- 🌍 **Multilingual Support**: English, Chinese, Japanese, Korean, and Latin languages\n- 🎯 **High Accuracy**: Based on PaddleOCR v3/v4 models\n- 📦 **Zero Python Dependencies**: 100% JavaScript/Node.js implementation\n- 🧠 **ONNX Runtime Node**: Efficient, high-performance model inference directly in Node.js\n- 🔧 **Highly Customizable**: Configure detection, recognition, and grouping parameters\n- 🎨 **Smart Text Grouping**: Automatically groups text into paragraphs\n- 🔌 **Bring Your Own Models**: Use custom ONNX models\n- ⚡ **Production Ready**: Built with performance and reliability in mind\n- 🚀 **Plug and Play**: All models and dictionaries included - just install and run!\n\n## 📥 Installation\n\n```bash\nnpm install multilingual-purejs-ocr\n```\n\n## 🚀 Quick Start\n\n```javascript\nimport Ocr from 'multilingual-purejs-ocr';\n\n// Create OCR instance with default settings (English)\nconst ocr = await Ocr.create();\n\n// Detect text in an image\nconst result = await ocr.detect('./image.jpg');\n\nconsole.log('Total elements:', result.totalElements);\nconsole.log('Paragraphs:', result.paragraphs);\nconsole.log('Individual elements:', result.data);\n```\n\n## 📖 Usage Examples\n\n### Basic Usage - Different Languages\n\n```javascript\n// English (default)\nconst ocrEn = await Ocr.create({ language: 'en' });\nconst resultEn = await ocrEn.detect('./english.jpg');\n\n// Chinese\nconst ocrCh = await Ocr.create({ language: 'ch' });\nconst resultCh = await ocrCh.detect('./chinese.jpg');\n\n// Japanese\nconst ocrJa = await Ocr.create({ language: 'ja' });\nconst resultJa = await ocrJa.detect('./japanese.jpg');\n\n// Korean\nconst ocrKo = await Ocr.create({ language: 'ko' });\nconst resultKo = await ocrKo.detect('./korean.jpg');\n\n// Latin languages (Portuguese, Spanish, French, etc.)\nconst ocrLatin = await Ocr.create({ language: 'latin' });\nconst resultLatin = await ocrLatin.detect('./latin.jpg');\n```\n\n### Advanced Configuration\n\n```javascript\nconst ocr = await Ocr.create({\n  // Language selection\n  language: 'en',\n  \n  // Detection parameters\n  detectionThreshold: 0.1,      // Lower = more sensitive (0-1)\n  minBoxSize: 3,                // Minimum text box size in pixels\n  maxBoxSize: 2000,             // Maximum text box size in pixels\n  unclipRatio: 1.5,             // Box expansion ratio\n  \n  // Recognition parameters\n  confidenceThreshold: 0.5,     // Minimum confidence to accept text (0-1)\n  imageHeight: 48,              // Recognition model input height\n  removeDuplicateChars: true,   // Remove duplicate characters\n  \n  // Text grouping configuration\n  grouping: {\n    verticalThresholdRatio: 1.2,\n    horizontalThresholdRatio: 2.5,\n    minOverlapRatio: 0.3,\n    maxVerticalOffsetRatio: 0.5\n  }\n});\n\nconst result = await ocr.detect('./image.jpg');\n```\n\n### Using Custom Models\n\n```javascript\nconst ocr = await Ocr.create({\n  language: 'en',\n  detectionModelPath: './my-models/custom_detection.onnx',\n  recognitionModelPath: './my-models/custom_recognition.onnx',\n  dictionaryPath: './my-models/custom_dict.txt'\n});\n```\n\n### Performance Tuning with ONNX Options\n\n```javascript\nconst ocr = await Ocr.create({\n  language: 'en',\n  \n  // Detection model ONNX options\n  detectionOnnxOptions: {\n    executionProviders: ['cpu'],\n    intraOpNumThreads: 4,          // Use 4 CPU threads\n    graphOptimizationLevel: 'all',\n    enableCpuMemArena: true\n  },\n  \n  // Recognition model ONNX options\n  recognitionOnnxOptions: {\n    executionProviders: ['cpu'],\n    intraOpNumThreads: 2,\n    executionMode: 'sequential'\n  }\n});\n```\n\n### Without Text Grouping\n\n```javascript\nconst ocr = await Ocr.create({ language: 'en' });\n\n// Get only individual text elements (no paragraph grouping)\nconst result = await ocr.detect('./image.jpg', { grouped: false });\n\nconsole.log(result.data); // Array of individual text elements\n// result.paragraphs will not be present\n```\n\n### Dynamic Grouping Configuration\n\n```javascript\nconst ocr = await Ocr.create({ language: 'en' });\n\n// Update grouping configuration at runtime\nocr.setGroupingConfig({\n  verticalThresholdRatio: 1.5,\n  horizontalThresholdRatio: 3.0\n});\n\n// Get current configuration\nconst config = ocr.getGroupingConfig();\nconsole.log(config);\n```\n\n## 📊 Output Format\n\n### Complete Response Structure\n\n```javascript\n{\n  totalElements: 31,           // Total text elements detected\n  totalParagraphs: 9,          // Number of grouped paragraphs\n  \n  // Grouped paragraphs (when grouped: true)\n  paragraphs: [\n    {\n      text: \"BECAUSE OF YOU,\",\n      confidence: 0.923,\n      boundingBox: {\n        left: 485,\n        top: 61,\n        width: 84,\n        height: 43\n      },\n      elements: [              // Individual elements in this paragraph\n        {\n          text: \"BECAUSE\",\n          confidence: 0.96,\n          frame: { left: 485, top: 61, width: 84, height: 20 }\n        },\n        {\n          text: \"OF YOU,\",\n          confidence: 0.86,\n          frame: { left: 489, top: 81, width: 75, height: 23 }\n        }\n      ]\n    }\n  ],\n  \n  // Individual text elements\n  data: [\n    {\n      text: \"BECAUSE\",\n      confidence: 0.9598,\n      frame: {\n        left: 485,\n        top: 61,\n        width: 84,\n        height: 20\n      },\n      box: [[485, 61], [569, 61], [569, 81], [485, 81]]  // 4-point polygon\n    }\n  ]\n}\n```\n\n## 🎛️ Configuration Options\n\n### Detection Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `detectionThreshold` | number | 0.1 | Text detection sensitivity (0-1, lower = more sensitive) |\n| `minBoxSize` | number | 3 | Minimum text box size in pixels |\n| `maxBoxSize` | number | 2000 | Maximum text box size in pixels |\n| `unclipRatio` | number | 1.5 | Box expansion ratio for better text capture |\n| `baseSize` | number | 32 | Image size base unit (must be multiple of 32) |\n| `maxImageSize` | number | 960 | Maximum image dimension |\n\n### Recognition Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `language` | string | 'en' | Language code: en, ch, ja, ko, latin |\n| `confidenceThreshold` | number | 0.5 | Minimum confidence to accept text (0-1) |\n| `imageHeight` | number | 48 | Recognition model input height |\n| `removeDuplicateChars` | boolean | true | Remove consecutive duplicate characters |\n\n### Grouping Options\n\n| Option | Type | Default | Description |\n|--------|------|---------|-------------|\n| `verticalThresholdRatio` | number | 1.2 | Max vertical gap ratio for grouping |\n| `horizontalThresholdRatio` | number | 2.5 | Max horizontal gap ratio for same line |\n| `minOverlapRatio` | number | 0.3 | Minimum vertical overlap for same line |\n| `maxVerticalOffsetRatio` | number | 0.5 | Max vertical offset ratio for same line |\n\n## 🌍 Supported Languages\n\n```javascript\n// Get list of available languages\nconst languages = Ocr.getAvailableLanguages();\nconsole.log(languages);\n```\n\n| Code | Language | Model |\n|------|----------|-------|\n| `en` | English | PP-OCRv4 |\n| `ch` | Chinese | PP-OCRv4 |\n| `ja` | Japanese | PP-OCRv3 |\n| `ko` | Korean | PP-OCRv4 (Korean dict) |\n| `latin` | Latin (PT, ES, FR, etc.) | PP-OCRv3 |\n\n## 📁 Included Models\n\nThe package ships with all required models and dictionaries for plug-and-play usage:\n\n```\nmodels/\n├── ch_PP-OCRv4_det_infer.onnx         # Detection model (shared)\n├── en_PP-OCRv4_rec_infer.onnx         # English recognition\n├── en_dict.txt                         # English dictionary\n├── ch_PP-OCRv4_rec_infer.onnx         # Chinese recognition\n├── ch_dict.txt                         # Chinese dictionary\n├── japan_PP-OCRv3_rec_infer.onnx      # Japanese recognition\n├── japan_dict.txt                      # Japanese dictionary\n├── korean_dict.txt                     # Korean dictionary\n├── latin_PP-OCRv3_rec_infer.onnx      # Latin recognition\n└── latin_dict.txt                      # Latin dictionary\n```\n\nNo additional setup required - everything is ready to use out of the box!\n\n## 🔧 Custom Models\n\nYou can use your own ONNX models:\n\n```javascript\nconst ocr = await Ocr.create({\n  detectionModelPath: './path/to/detection.onnx',\n  recognitionModelPath: './path/to/recognition.onnx',\n  dictionaryPath: './path/to/dictionary.txt'\n});\n```\n\n### Model Requirements\n\n- **Detection Model**: ONNX format, input shape [1, 3, H, W], output: binary mask\n- **Recognition Model**: ONNX format, input shape [1, 3, 48, W], output: character probabilities\n- **Dictionary**: Text file with one character per line\n\n## 🎯 Use Cases\n\n- 📸 **Document Scanning**: Extract text from scanned documents\n- 🎫 **Receipt Processing**: Parse receipts and invoices\n- 🚗 **License Plate Recognition**: Read vehicle plates\n- 📝 **Form Processing**: Extract data from forms\n- 🌐 **Translation Apps**: Detect and translate text in images\n- 📱 **Screenshot OCR**: Extract text from screenshots\n- 🏷️ **Label Reading**: Read product labels and barcodes\n\n## ⚡ Performance Tips\n\n1. **Adjust Detection Threshold**: Lower for harder-to-read text, higher for cleaner images\n2. **Use Appropriate Language Model**: Select the correct language for better accuracy\n3. **Optimize Image Size**: Resize very large images before processing\n4. **Tune ONNX Threads**: Adjust `intraOpNumThreads` based on your CPU cores\n5. **Disable Grouping**: Use `grouped: false` if you only need individual elements\n\n## 🐛 Troubleshooting\n\n### Low Accuracy\n\n- Adjust `detectionThreshold` (try 0.05 for harder images)\n- Increase `unclipRatio` (try 1.8 or 2.0)\n- Ensure correct language model is selected\n- Preprocess image (increase contrast, remove noise)\n\n### Missing Text\n\n- Lower `detectionThreshold`\n- Reduce `minBoxSize`\n- Increase `unclipRatio`\n\n### Performance Issues\n\n- Reduce `maxImageSize`\n- Adjust ONNX thread settings\n- Process images in batches\n\n### Wrong Grouping\n\n- Adjust grouping ratios in configuration\n- Use `grouped: false` and implement custom grouping\n\n## 📝 API Reference\n\n### `Ocr.create(options)`\n\nCreates a new OCR instance with the specified configuration.\n\n**Parameters:**\n- `options` (Object): Configuration options\n\n**Returns:** `Promise\u003cOcr\u003e` - OCR instance\n\n### `ocr.detect(imagePath, options)`\n\nDetects and recognizes text in an image.\n\n**Parameters:**\n- `imagePath` (string): Path to image file\n- `options` (Object): Detection options\n  - `grouped` (boolean): Return grouped paragraphs (default: true)\n  - `onnxOptions` (Object): Runtime ONNX options\n\n**Returns:** `Promise\u003cObject\u003e` - Detection results\n\n### `ocr.setGroupingConfig(config)`\n\nUpdates the text grouping configuration.\n\n**Parameters:**\n- `config` (Object): New grouping configuration\n\n### `ocr.getGroupingConfig()`\n\nReturns the current grouping configuration.\n\n**Returns:** `Object` - Current grouping configuration\n\n### `Ocr.getAvailableLanguages()`\n\nStatic method that returns available languages.\n\n**Returns:** `Object` - Language configurations\n\n## 🤝 Contributing\n\nContributions are welcome! Please feel free to submit issues or pull requests.\n\n## 📄 License\n\nISC\n\n## 🙏 Acknowledgments\n\n- Built on [PaddleOCR](https://github.com/PaddlePaddle/PaddleOCR) models\n- Uses [ONNX Runtime Node](https://www.npmjs.com/package/onnxruntime-node) for efficient model inference in Node.js\n- Powered by [Sharp](https://sharp.pixelplumbing.com/) for image processing\n\n## 📧 Support\n\nFor issues and questions, please open an issue on [GitHub](https://github.com/VrajVyas11/Multilingual_PureJS_Based_OCR/issues).\n\n---\n\nMade with ❤️ for the JavaScript community","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrajvyas11%2Fmultilingual_purejs_based_ocr","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvrajvyas11%2Fmultilingual_purejs_based_ocr","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvrajvyas11%2Fmultilingual_purejs_based_ocr/lists"}