Defect Inspector is an industrial-grade dual-screen visual inspection application developed with Python and Tkinter, specially designed to be paired with Transcend ECM series lenses/cameras. It integrates Ultralytics YOLO for object/defect detection and PaddleOCR for real-time text recognition.
The system utilizes a multiprocessing architecture to ensure smooth rendering of high-resolution camera feeds (30 FPS) while running heavy deep learning models in the background. Features include real-time Region of Interest (ROI) selection, automatic image deskewing (alignment), and one-click training data collection.
- Real-time Video Streaming: Automatically scans and connects to high-resolution video feeds, optimized for Transcend ECM series hardware.
- Dual-Panel UI Design:
- Left Panel (40%): Live video preview, mode configuration, and ROI selection.
- Right Panel (60%): High-resolution Gallery view, dynamic glow for defect alerts, and OCR readouts.
- Multi-Model Support: Dynamically switch between different detection modes (e.g., Sticker) without restarting the application.
- Smart Image Processing: Supports multi-target tracking, automated angle calculation, and physical deskewing of cropped images.
- Data Collection Mode: Save the current detection results with a single keystroke (Shortcut
S). The system automatically generates YOLO-format annotation files (.txt) for future model training.
- OS: Jetson Linux (Download from https://developer.nvidia.com/embedded/learn/get-started-jetson-nano-devkit#intro).
- GPU: NVIDIA GPU with CUDA installed is highly recommended to significantly improve YOLO and OCR inference speeds.
- Camera: Transcend ECM series lenses/cameras are required to capture high-resolution video via the UVC protocol, ensuring optimal image clarity, precise field of view, and full hardware compatibility.
Please ensure Python 3.8 or higher is installed.
# 1. Clone the repository
git clone https://github.com/transcend-information/Jetson_Print-Defect-Detection_Demo.git
cd defect-inspector
# 2. Create a virtual environment (Highly Recommended)
python -m venv venv
# Activate on Linux:
source venv/bin/activate
# 3. Install required packages
# Note: Adjust the PyTorch installation URL based on your specific CUDA version.
pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118
pip install ultralytics
pip install paddlepaddle-gpu # Use 'paddlepaddle' if you do not have a GPU
pip install paddleocr==2.7.3 numpy==1.26.1 #Version compatibility warnings or errors can be safely ignored
Before running the application, you must manually create a models directory and place your trained YOLO models inside. You also need an application icon image.
defect-inspector/
|
|-- demo_camera.py # Main application script
|
|-- models/ # -> You must create this folder and add models
| |-- stick_best.pt # YOLO model for sticker detection
|
|-- dataset_update/ # Auto-generated when pressing 'S' to save training data
(Note: If you only use one mode, simply place the corresponding .pt file in the folder.)
Once your environment is set up and models are in place, start the system with:
python demo_camera.pyNote: The application starts in full-screen mode by default. It will load the YOLO and OCR models in the background. Please wait 10-30 seconds until the status bar at the bottom left displays "Detection model ready".
Look at the CONFIG & PREVIEW panel on the left. Click the radio buttons at the top to switch between detection modes (e.g., Sticker). The system will automatically swap the YOLO model in the background.
- Ensure the Transcend ECM camera feed is displaying correctly on the left panel.
- Click and drag your mouse over the left video feed to draw a red bounding box (ROI).
- Release the mouse button. The system will lock onto this area and begin continuous automatic detection.
As shown in the image below, once the target enters the user-defined red bounding box (ROI), the system automatically isolates the object, physically deskews (straightens) it, and begins defect detection.
The right panel provides a detailed Gallery Inspection view. The system provides clear visual feedback based on the detection results.
PASS State: If no defects are detected, the zoomed inspection gallery will display a green glowing border along with a clear PASS indicator.
FAIL State: If defects are found, the inspection gallery will switch to a red glowing border. The exact locations of the defects will be highlighted with red bounding boxes directly on the deskewed image.
- Mouse Wheel Zoom: Hover over the right panel and use your mouse wheel to zoom in and out for closer manual inspection.
- OCR Readout: The bottom right section automatically formats and displays the text recognized by PaddleOCR.
If you encounter a false positive or a missed detection and want to add it to your dataset for future training:
- Ensure the target object is currently displayed in the right Gallery panel.
- Press the
Skey on your keyboard. - The status bar will display "Saved X sticker sample(s)...".
- The cropped images and corresponding YOLO
.txtlabel files will be automatically saved in thedataset_update/directory.
- Press the
ESCkey to toggle between full-screen and windowed modes. - Click the
Xbutton on the window (in windowed mode) to close the application. The system will safely terminate background workers and release camera/GPU resources.
-
Q: The bottom status bar is stuck at "Detection model not found: stick".
- A: Make sure you have created the
modelsfolder and placed thestick_best.ptfile inside it.
- A: Make sure you have created the
-
Q: The screen is black, and the terminal shows a critical error about not finding a camera device.
- A:
- Check your Transcend ECM camera's connection.
- The program scans
/dev/v4l/by-path/and/dev/video*(Linux). If your camera is being used by another application (like OBS or a web browser), close that application and restart this script.
- A:
-
Q: PaddleOCR throws an error on Linux (missing libgomp or similar libraries).
- A: Install the required system dependencies by running:
sudo apt-get install libgomp1 libglib2.0-0 libsm6 libxext6 libxrender-dev
- A: Install the required system dependencies by running:


