Indonesia ID Card (KTP) Extractor
1.2K
This Flask application performs Optical Character Recognition (OCR) on Indonesian KTP (Identity Card) images. The app uses EasyOCR and Tesseract to extract and process text from uploaded KTP images.
Create a virtual environment (recommended) and activate it.
Install the required dependencies:
pip install --no-cache-dir -r requirements.txt
Create a file named .env in your project directory and add the following environment variables, replacing the placeholders with your actual values:
API_KEY=your-api-key # (Optional, for API access control)
.env API_KEY=your-api-key for static API Key authentication.Start the application:
python app.py
The application runs on http://0.0.0.0:5000 (localhost) by default in debug mode.
Make a POST request to the / endpoint with an image file in the image field of your multipart form data and ocr_choice easyocr or pytesseract ocr engine switch. The API key needs to be included in the request header (if configured).
curl -X POST http://localhost:5000/ \
-H "X-API-KEY: your_api_key" \
-F "[email protected]" -F 'ocr_choice="easyocr"'
{
"error": false,
"message": "OCR Success!",
"data": {
"nik": "3026061812510006",
"nama": "WIDIARSO",
"tempat_lahir": "PEMALANG,",
"tgl_lahir": "18-12-1959",
"jenis_kelamin": "LAKI-LAKI",
"agama": "ISLAM",
"status_perkawinan": "KAWIN",
"pekerjaan": "KARYAWAN SWASTA",
"alamat": {
"name": "SKU JLSUMATRA BLOK B78/15",
"rt_rw": "0037004",
"kel_desa": "MEKARSARI",
"kecamatan": "TAMBUN SELATAN",
"kabupaten": "KABUPATEN BEKASI",
"provinsi": "PROVINSI JAWA BARAT\n-"
},
"time_elapsed": 2.512
}
}
Implement unit tests for your functions using a framework like pytest. Manually test the API endpoint using tools like Postman or cURL as demonstrated in the “Usage” section.
run docker-compose up
version: "3"
services:
ocr:
build:
context: .
dockerfile: Dockerfile
image: ocr
container_name: ocr
environment:
API_KEY: "your_value"
restart: unless-stopped
ports:
- "8000:8000"
networks:
- ocr-network
command: gunicorn app:app -w 4 -t 90 --log-level=debug -b 0.0.0.0:8000 --reload --threads 2 --worker-class gevent --keep-alive 5 --timeout 60 --worker-connections 1000
networks:
ocr-network:
driver: bridge
Content type
Image
Digest
sha256:f6c7dda30…
Size
3 GB
Last updated
about 2 years ago
docker pull arakattack/ocr-ktp