This project processes images to extract barcodes and text, then associates them together. Perfect for drug classification and inventory management. It also includes a QR code + Medicine ID lookup system for retrieving medicine details.
- Barcode Detection: Automatically detects and reads various barcode formats (QR codes, UPC, EAN, etc.)
- OCR Text Extraction: Extracts text from images using Tesseract OCR
- Association: Links barcode data with extracted text from the same image
- Batch Processing: Processes all images in a folder automatically
- JSON Output: Saves results in structured JSON format
- QR Code + Medicine ID Lookup: Upload QR code and enter Medicine ID to retrieve detailed medicine information
- Web Interface: User-friendly Flask web application for barcode and QR code lookups
- Tesseract OCR: Required for text extraction
- macOS:
brew install tesseract - Ubuntu/Debian:
sudo apt-get install tesseract-ocr - Windows: Download from Tesseract GitHub
- macOS:
- opencv-python
- pyzbar
- pytesseract
- Pillow
- numpy
python setup_and_run.py# Install Python dependencies
pip install -r requirements.txt
# Run the scanner
python barcode_scanner.pypython barcode_scanner.pypython barcode_scanner.py --single path/to/image.jpgpython barcode_scanner.py --images custom_folder --output results.jsonThe script generates a JSON file with the following structure:
[
{
"image_path": "images/sample.jpg",
"image_name": "sample.jpg",
"timestamp": "2024-01-01T12:00:00",
"barcodes": [
{
"data": "1234567890123",
"type": "EAN13",
"position": {
"x": 100,
"y": 50,
"width": 200,
"height": 50
}
}
],
"text": {
"full_text": "Drug Name: Aspirin\nDosage: 500mg\nExpiry: 2025-12-31",
"words": [
{
"text": "Aspirin",
"confidence": 95,
"position": {"x": 10, "y": 20, "width": 60, "height": 15}
}
]
},
"barcode_count": 1,
"has_text": true
}
]- Supports multiple barcode formats (QR, UPC, EAN, Code128, etc.)
- Provides barcode position information
- Handles multiple barcodes per image
- Uses Tesseract OCR for high accuracy
- Extracts both full text and individual words with positions
- Includes confidence scores for each detected word
- Automatically links barcodes with text from the same image
- Provides detailed position information for both barcodes and text
- Enables easy correlation between barcode data and product information
-
Tesseract not found
- Install Tesseract OCR on your system
- Make sure it's in your system PATH
-
Poor text recognition
- Ensure images are clear and well-lit
- Try preprocessing images for better contrast
-
No barcodes detected
- Check if barcodes are clear and not damaged
- Ensure barcodes are not too small or too large
- Use high-resolution images for better OCR accuracy
- Ensure good lighting and contrast in images
- For batch processing, consider processing in smaller batches
- Drug Inventory: Scan medication barcodes and extract drug names, dosages, expiry dates
- Product Catalog: Process product images with barcodes and descriptions
- Document Processing: Extract both barcode and text information from documents
-
Prepare Your Excel File:
- Create an Excel file (
.xlsx) with medicine details - Each row should represent one medicine
- Columns can include: Medicine Name, Manufacturer, Expiry Date, Batch Number, MRP, etc.
- Place the Excel file in the project root directory (same folder as
app.py)
- Create an Excel file (
-
Load Medicine Data:
python load_medicine_data.py your_medicine_file.xlsx
This will create a
medicine_database.jsonfile with unique IDs for each medicine. -
QR Codes: Each medicine should have its own unique QR code that corresponds to its Medicine ID.
-
Start the Web Application:
python app.py
Or use:
python start_web_app.py
-
Access the Web Interface:
- Open your browser and go to
http://localhost:5000 - Click on the "QR Code + Medicine ID Lookup" tab
- Open your browser and go to
-
Lookup Medicine:
- Upload the QR code image for the medicine
- Enter the corresponding Medicine ID (e.g., HM002, ABC123, etc.)
- Click "Lookup Medicine Details"
- The system will validate the QR code and display medicine details if both QR and ID match
- QR Code Validation: Each medicine has a unique QR code that must be uploaded
- Medicine ID: Each medicine has a unique ID from your Excel file (e.g., HM002, ABC123)
- Security: The system requires both the correct QR code AND the correct Medicine ID to work
- Matching Required: The QR code and Medicine ID must match each other for successful lookup
project/
├── images/ # Input images folder
├── uploads/ # Temporary upload folder (auto-created)
├── templates/ # HTML templates for web app
│ ├── base.html
│ ├── index.html
│ ├── results.html
│ ├── medicine_result.html
│ └── database.html
├── barcode_scanner.py # Main scanner script
├── app.py # Flask web application
├── load_medicine_data.py # Load medicine data from Excel
├── setup_and_run.py # Automated setup script
├── requirements.txt # Python dependencies
├── README.md # This file
├── barcode_text_results.json # Output results (generated)
├── medicine_database.json # Medicine database (generated from Excel)
└── your_medicine_file.xlsx # YOUR EXCEL FILE - Place it here!