Skip to content

shreeyas99/Fake-Drug-Detection

 
 

Repository files navigation

Drug Classification System

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.

Features

  • 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

Requirements

System Dependencies

  • Tesseract OCR: Required for text extraction
    • macOS: brew install tesseract
    • Ubuntu/Debian: sudo apt-get install tesseract-ocr
    • Windows: Download from Tesseract GitHub

Python Dependencies

  • opencv-python
  • pyzbar
  • pytesseract
  • Pillow
  • numpy

Quick Start

Option 1: Automated Setup

python setup_and_run.py

Option 2: Manual Setup

# Install Python dependencies
pip install -r requirements.txt

# Run the scanner
python barcode_scanner.py

Usage

Process All Images

python barcode_scanner.py

Process Single Image

python barcode_scanner.py --single path/to/image.jpg

Custom Options

python barcode_scanner.py --images custom_folder --output results.json

Output Format

The 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
  }
]

Features Explained

Barcode Detection

  • Supports multiple barcode formats (QR, UPC, EAN, Code128, etc.)
  • Provides barcode position information
  • Handles multiple barcodes per image

Text Extraction

  • Uses Tesseract OCR for high accuracy
  • Extracts both full text and individual words with positions
  • Includes confidence scores for each detected word

Association

  • 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

Troubleshooting

Common Issues

  1. Tesseract not found

    • Install Tesseract OCR on your system
    • Make sure it's in your system PATH
  2. Poor text recognition

    • Ensure images are clear and well-lit
    • Try preprocessing images for better contrast
  3. No barcodes detected

    • Check if barcodes are clear and not damaged
    • Ensure barcodes are not too small or too large

Performance Tips

  • Use high-resolution images for better OCR accuracy
  • Ensure good lighting and contrast in images
  • For batch processing, consider processing in smaller batches

Example Use Cases

  • 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

QR Code + Medicine ID Lookup

Setting Up Medicine Database

  1. 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)
  2. Load Medicine Data:

    python load_medicine_data.py your_medicine_file.xlsx

    This will create a medicine_database.json file with unique IDs for each medicine.

  3. QR Codes: Each medicine should have its own unique QR code that corresponds to its Medicine ID.

Using QR Code Lookup

  1. Start the Web Application:

    python app.py

    Or use:

    python start_web_app.py
  2. Access the Web Interface:

    • Open your browser and go to http://localhost:5000
    • Click on the "QR Code + Medicine ID Lookup" tab
  3. 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

Important Notes

  • 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

File Structure

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!

About

A machine learning–based system that detects counterfeit medicines using product data, QR‑code information, and labeled datasets. The model analyzes drug details, packaging features, and encoded metadata to classify medicines as genuine or fake, helping improve safety and prevent counterfeit drug circulation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 100.0%