A NestJS application that uses EasyOCR to extract text from images. Currently supports BCA Form OCR processing.
Before you begin, ensure you have installed:
- Node.js (v16 or higher)
- Python (v3.8 or higher)
- pip (Python package manager)
git clone <repository-url>
cd ocrnpm install# Install EasyOCR and its dependencies
pip install easyocr pillow numpy
# If you're using Windows and encounter issues, you might need:
pip install torch torchvision torchaudiomkdir uploadsocr/
├── src/
│ ├── controllers/
│ │ └── ocr.controller.ts
│ ├── services/
│ │ ├── ocr-base.service.ts
│ │ └── bca-form.service.ts
│ ├── types/
│ │ └── bca-form.type.ts
│ ├── app.module.ts
│ └── main.ts
├── python/
│ └── bca_form_ocr.py
├── uploads/ # Temporary storage for uploaded files
└── README.md
# Development mode
npm run start:dev
# Production mode
npm run build
npm run start:prodPOST /ocr/bca-form
Content-Type: multipart/form-data
body:
- image: <file>Example using cURL:
curl -X POST -F "image=@/path/to/your/image.jpg" http://localhost:3000/ocr/bca-formResponse:
{
"form_type": "DPBCA",
"form_title": "Formulir Pengunduran Diri Sebagai Peserta Dana Pensiun BCA",
"peserta": {
"nama": "Example Name",
"nip": "12345678",
"alamat": "Example Address",
"email": "example@email.com",
"hp": "081234567890",
"tanggal_dokumen": "01 Jan 2024"
},
"pengunduran_diri": {
"tanggal": "15 Jan 2024",
"alasan": ""
},
"rekening": {
"bank": "BCA",
"nomor": "1234567890",
"pemilik": "Example Name"
},
"kontak_darurat": {
"nama": "Emergency Contact",
"telepon": "081234567890"
}
}- Image text extraction using EasyOCR
- Support for BCA Form processing
- Automatic file cleanup after processing
- File type validation (jpg, jpeg, png, pdf)
- File size limit (5MB)
- Error handling
- Type-safe responses
- Create new type definition in
src/types/ - Create new service extending
OcrBaseService - Add new Python script in
python/ - Add new endpoint in
OcrController
# unit tests
npm run test
# e2e tests
npm run test:e2e
# test coverage
npm run test:covThe API returns error responses in the following format:
{
"error": "Error message description"
}Common errors:
- File type not supported
- File size exceeds limit
- OCR processing failed
- Invalid or corrupted image
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This README provides:
1. Clear installation instructions
2. Project structure overview
3. Usage examples with API documentation
4. Development guidelines
5. Testing information
6. Error handling details
7. License and contribution guidelines
You can customize it further based on your specific needs or add more sections as the project grows.