No description
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-09-08 15:52:59 +05:30
docs Show OCR timing and persist inspection settings and ROI 2026-09-07 17:03:52 +05:30
src/industrial_ocr_app Add triggered inspections, daily scan logs and full-screen preview 2026-09-08 15:52:59 +05:30
.gitignore Initial industrial OCR app scaffold 2026-09-06 00:57:15 +05:30
.python-version Support HTTP camera streams 2026-09-06 01:31:24 +05:30
pyproject.toml Load main window from Qt UI file 2026-09-06 02:27:41 +05:30
README.md Add triggered inspections, daily scan logs and full-screen preview 2026-09-08 15:52:59 +05:30

Industrial OCR Desktop

Industrial OCR desktop application for Windows and Linux using Python and PySide6. The app connects to an HTTP IP camera stream, previews live video, runs OCR on sampled frames, and flags configured keywords in the detected text.

Detailed internal documentation is available in docs/CODEBASE_DOCUMENTATION.md. The main desktop layout is defined in src/industrial_ocr_app/ui/main_window.ui and loaded at runtime. If you pull UI-related changes, reinstall with pip install -e . so packaged .ui files stay in sync.

Features

  • PySide6 desktop UI for operators
  • Borderless full-screen video via Full Screen Video; press Escape to return to the controls
  • Latest recognized text in red at the bottom-right of the video, with a transparent background in both preview modes
  • IP camera HTTP video stream input through OpenCV
  • Background video capture and OCR workers so the UI stays responsive
  • Pluggable OCR engine abstraction
  • Keyword-based content detection for industrial workflows
  • ROI-based OCR to focus on the exact inspection area
  • Regex-based validation rules for industrial code formats
  • Cross-platform project structure for Windows and Linux

Typical Industrial Use Cases

  • Reading labels, batch codes, and printed serial numbers
  • Detecting missing or incorrect text on packaging
  • Verifying machine panel text or HMI messages from network cameras
  • Monitoring conveyor-mounted products with fixed IP cameras
  • Validating printed batch, lot, and part-number formats

Requirements

  • Python 3.10+
  • Tesseract OCR installed on the machine
  • A reachable IP video source such as:
    • http://192.168.1.3:8080/video
    • http://camera-ip/mjpeg
    • http://user:password@camera-ip:8080/video
    • local test source if supported by OpenCV

Install

Linux

Install Tesseract first using your package manager. Example on Ubuntu/Debian:

sudo apt-get update
sudo apt-get install -y tesseract-ocr

Then create a virtual environment and install the app:

python3 -m venv .venv
source .venv/bin/activate
pip install -e .

Windows

  1. Install Tesseract OCR and note the install path.
  2. Create a virtual environment and install dependencies:
py -m venv .venv
.venv\Scripts\activate
pip install -e .
  1. If Tesseract is not in PATH, set TESSERACT_CMD before starting the app:
$env:TESSERACT_CMD="C:\Program Files\Tesseract-OCR\tesseract.exe"
industrial-ocr

Run

industrial-ocr

In the app, enter an HTTP camera endpoint such as 192.168.1.3:8080/video. The UI will automatically convert it to http://192.168.1.3:8080/video.

Scan Logs

Every completed OCR pass appends scanned text and OCR reading time in milliseconds to ocr_YYYY-MM-DD.log. Files use the local completion date and switch automatically at midnight; a day's file is created on its first scan. Restarting appends to the existing file. Empty OCR results are also recorded. Logging runs in the OCR worker and is excluded from the measured OCR time.

On Linux, logs normally live in ~/.local/share/IndustrialOCR/logs (or under XDG_DATA_HOME when configured). On Windows, they live in %LOCALAPPDATA%/IndustrialOCR/logs. Records use UTF-8 JSON, one record per line, preserving punctuation and multiline text. Log write failures are shown in the status bar; the OCR result still appears. Logs are retained until manually removed.

{"timestamp": "2026-09-07T17:10:55.000+05:30", "frame_timestamp": 1788772255.0, "scanned_text": "Batch : 12345", "ocr_reading_time_ms": 125.3}

ROI And Validation

Inspection defaults to Manual trigger. Connect the camera, then click Inspect Product (or press Space outside text inputs). After the trigger delay, OCR retries fresh frames for up to 1.5 seconds, stopping when the Validation Required percentage is reached. This saved setting ranges from 1 to 100%, defaulting to 100%. The score is passing rules divided by total rules in a single OCR result; 3 of 4 rules is 75%. Invalid regex rules count as failures, and no configured rules or empty text cannot succeed. The status shows the score and threshold. Only one OCR request runs at a time; manual retries do not wait for the continuous OCR interval. No more frames are submitted after the window ends, but an already-running OCR pass finishes and its result is displayed and logged, so total completion time can exceed the window. The preview stays live and the button is disabled throughout inspection. Continuous (setup) repeats OCR at the configured interval. trigger_inspection() is the entry point for a future sensor adapter; hardware integration is not yet implemented.

The preview draws one thin red rectangle per recognized text line. Hover over a rectangle to see its recognized text in red with a transparent background. Confidence percentages are omitted from the preview to avoid clutter; the full recognized text remains in OCR Output. The ROI outline has no tinted fill.

The selected ROI is also saved automatically and restored for preview and OCR on startup. Clear ROI saves full-frame mode. Coordinates are stored as fractions of the frame size; this is one saved ROI for the current configuration, not separate presets per camera.

The camera URL, keywords, and validation rules are saved automatically after edits and when the window closes, then restored on startup. Settings are per OS user, using Qt QSettings (IndustrialOCR/IndustrialOCRDesktop): normally ~/.config/IndustrialOCR/IndustrialOCRDesktop.conf on Linux and HKEY_CURRENT_USER\Software\IndustrialOCR\IndustrialOCRDesktop on Windows. Empty fields are preserved. Camera credentials included in the URL are stored with it, without encryption.

OCR Reading Time shows the latest completed OCR pass in milliseconds, including image preprocessing, text recognition, and validation. It updates even when no text is found and excludes camera/network delays, queue waiting, and the configured OCR interval.

  • Click Select ROI, then drag on the video preview to limit OCR to the inspection zone.
  • Use Clear ROI to return to full-frame OCR.
  • Enter one validation rule per line.
  • Use Name=regex for named rules, for example:
Batch Code=BATCH\s*-\s*[0-9]{5}
Lot Number=LOT[0-9]{6}
Part ID=PN-[A-Z]{3}-[0-9]{5}

The app reports whether each rule passes or fails on the recognized text.

Architecture

  • src/industrial_ocr_app/ui
    • runtime-loaded Qt Designer window plus custom preview widget
  • src/industrial_ocr_app/services
    • Video capture worker and OCR engine
  • src/industrial_ocr_app/models
    • Shared dataclasses
  • src/industrial_ocr_app/main.py
    • Application entrypoint

Industrial Notes

This starter project is meant to be extended for production. For industrial deployment you will likely want to add:

  • Multiple saved ROI presets per camera or product type
  • Per-line, per-product, or per-station validation rule sets
  • Camera reconnection strategy and watchdog monitoring
  • Result history, audit logs, and export
  • Image preprocessing for low-light, motion blur, or skew
  • Optional GPU inference or a custom OCR model for difficult fonts
  1. Add persistent camera profiles and saved ROI presets.
  2. Save evidence images when a validation rule fails.
  3. Add an OCR confidence threshold and reject handling workflow.
  4. Add a PLC/MQTT/REST integration layer for factory signals.