OCR-Based Product Information Scanner by karthikeya YelamanchiliOCR-Based Product Information Scanner by karthikeya Yelamanchili

OCR-Based Product Information Scanner

karthikeya Yelamanchili

karthikeya Yelamanchili

OCR-Based Product Information Scanner

A comprehensive solution that uses Optical Character Recognition (OCR) to scan product labels from images and retrieve detailed product information from a MongoDB database. This system combines multiple OCR technologies with intelligent database querying to provide accurate product identification and information retrieval.

Overview

This project implements a complete product information scanning system that addresses the challenge of automatically extracting and matching product data from label images. The system leverages both Tesseract OCR and EasyOCR technologies to maximize text extraction accuracy, then performs intelligent database searches to retrieve comprehensive product details including ingredients, nutrition facts, brand information, and product categories.

Features

Core Functionality

Dual OCR Engine Support: Utilizes both Tesseract OCR and EasyOCR for maximum text extraction accuracy
Intelligent Text Processing: Advanced text extraction algorithms that identify product names and barcodes from OCR results
MongoDB Integration: Robust database connectivity with case-insensitive search capabilities
Web Interface: User-friendly Flask-based web application for easy image upload and result visualization
Error Handling: Comprehensive error handling for OCR failures, database connectivity issues, and invalid inputs

Technical Capabilities

Multiple Image Format Support: Accepts PNG, JPG, JPEG, GIF, and BMP image formats
Case-Insensitive Search: Database queries that handle variations in text case and formatting
Fallback Search Strategy: Multiple search attempts using different OCR results and search methods
Real-time Processing: Immediate OCR processing and database lookup upon image upload
Responsive Design: Mobile-friendly web interface that works across different screen sizes

Architecture

The system follows a modular architecture with clear separation of concerns:

Technology Stack

Backend Technologies

Python 3.11: Core programming language
Flask 3.0.3: Web framework for the user interface
PyMongo 4.8.0: MongoDB driver for database operations
Tesseract OCR: Traditional OCR engine with high accuracy for printed text
EasyOCR 1.7.2: Deep learning-based OCR with support for multiple languages
Pillow 10.4.0: Image processing library for handling various image formats

Database

MongoDB: NoSQL database for storing product information with flexible schema support
MongoDB Atlas: Cloud-hosted database service for reliable data storage and access

Frontend Technologies

HTML5: Modern markup for the web interface
CSS3: Responsive styling with grid layouts and modern design principles
JavaScript (ES6+): Client-side functionality for form handling and dynamic content updates

Installation and Setup

Prerequisites

Python 3.11 or higher
Tesseract OCR system package
Internet connection for MongoDB Atlas access
Modern web browser for the interface

System Dependencies


Python Environment Setup


Database Configuration

The system is pre-configured to connect to the provided MongoDB Atlas instance. No additional database setup is required as the connection string is embedded in the application.

Usage

Starting the Application


The application will start on http://localhost:5000 and display startup information including the local IP addresses where the service is accessible.

Using the Web Interface

Access the Application: Open your web browser and navigate to http://localhost:5000
Upload an Image: Click the "Choose File" button and select a product label image
Process the Image: Click "Scan Product" to initiate OCR processing and database lookup
View Results: The system will display:
OCR text extraction results from both engines
Extracted product information (name, barcode)
Complete product details if found in the database
Error messages if processing fails

Command Line Testing

For development and testing purposes, you can also run the OCR modules directly:

API Endpoints

POST /upload

Processes an uploaded image file and returns OCR results and product information.
Request Format:
Method: POST
Content-Type: multipart/form-data
Body: Image file with key "file"
Response Format:

Database Schema

The MongoDB database uses the following document structure for product information:

Testing

Sample Data

The system includes sample data for testing purposes. A dark chocolate product is pre-loaded in the database with complete nutrition information and ingredient details.

Test Images

Sample images are provided in the sample_images/ directory for testing the OCR functionality and end-to-end system operation.

Verification Steps

OCR Accuracy: Test with various image qualities and lighting conditions
Database Connectivity: Verify successful connection to MongoDB Atlas
Search Functionality: Test both exact and case-insensitive product name searches
Error Handling: Test with invalid images and network connectivity issues
Web Interface: Verify responsive design and proper error message display

Performance Considerations

OCR Processing

Tesseract OCR: Optimized for printed text with high accuracy on clear images
EasyOCR: Better performance on handwritten text and complex backgrounds but requires more computational resources
Processing Time: Typical processing time ranges from 2-10 seconds depending on image complexity and system resources

Database Operations

Connection Pooling: MongoDB driver automatically manages connection pooling for optimal performance
Query Optimization: Case-insensitive searches use MongoDB regex with appropriate indexing
Timeout Handling: 4-second timeout for database operations to prevent hanging requests

Scalability

Concurrent Requests: Flask development server handles multiple concurrent requests
Image Storage: Temporary image storage with automatic cleanup
Memory Management: Efficient image processing with proper resource cleanup

Error Handling

The system implements comprehensive error handling at multiple levels:

OCR Errors

Invalid image formats
Corrupted image files
OCR processing failures
Empty or unreadable text extraction

Database Errors

MongoDB connection failures
Network connectivity issues
Query timeout errors
Invalid search parameters

Web Interface Errors

File upload size limits (16MB maximum)
Unsupported file types
Network request failures
Client-side JavaScript errors

Security Considerations

File Upload Security

File Type Validation: Only allows specific image file extensions
File Size Limits: Maximum 16MB upload size to prevent abuse
Secure Filename Handling: Uses werkzeug secure_filename for safe file processing
Temporary Storage: Uploaded files are stored temporarily and can be cleaned up regularly

Database Security

Connection String: Uses MongoDB Atlas with built-in security features
Input Validation: All database queries use parameterized inputs to prevent injection attacks
Error Message Sanitization: Database errors are logged but not exposed to end users

Future Enhancements

Planned Features

Batch Processing: Support for processing multiple images simultaneously
Advanced OCR: Integration with cloud-based OCR services for improved accuracy
Product Database Expansion: Integration with larger product databases and APIs
Mobile Application: Native mobile app for on-the-go product scanning
Barcode Recognition: Enhanced barcode detection and processing capabilities

Technical Improvements

Caching: Redis-based caching for frequently accessed product information
API Rate Limiting: Request throttling to prevent abuse
Logging: Comprehensive logging system for monitoring and debugging
Testing: Automated test suite with unit and integration tests
Deployment: Docker containerization for easy deployment and scaling

Troubleshooting

Common Issues

OCR Not Working
Verify Tesseract is properly installed: tesseract --version
Check image quality and resolution
Ensure image contains clear, readable text
Database Connection Errors
Verify internet connectivity
Check MongoDB Atlas service status
Confirm connection string is correct
Web Interface Issues
Clear browser cache and cookies
Check browser console for JavaScript errors
Verify Flask server is running on correct port
Performance Issues
Monitor system resources during OCR processing
Consider image preprocessing for better OCR results
Check network latency to MongoDB Atlas

Debug Mode

Enable Flask debug mode for detailed error information:

Contributing

This project welcomes contributions in the following areas:
OCR accuracy improvements
Database schema enhancements
Web interface usability improvements
Performance optimizations
Additional test cases and documentation

License

This project is developed for educational and demonstration purposes. Please ensure compliance with all relevant licenses for the included OCR libraries and database services.

Support

For technical support or questions about this implementation, please refer to the documentation or create an issue in the project repository.
Like this project

Posted Aug 13, 2026

Created an OCR-based solution for scanning product labels with integrated database search.