A comprehensive real-time computer vision system for manufacturing environments, combining bottle cap quality inspection with advanced object detection, tracking, and segmentation. The system identifies bottle caps on a conveyor belt, analyzes them for defects in shape, color, and position, and provides detailed object analytics using YOLOv8 and SAM 2.
- Bottle Cap Inspection:
- Automated Inspection: Detects and tracks bottle caps moving in a straight line on a conveyor belt
- Real-time Analysis: Performs shape, color, and position analysis in real-time
- User Interface: Displays inspection results in a clean side panel showing:
- Cap ID (identification number)
- Shape status (OK/DAMAGED)
- Color status (OK/DAMAGED)
- Position status (OK/DAMAGED)
- Test Video Generation: Includes a script to generate test videos with bottle caps and various defects
- Manufacturing Vision System:
- Object Detection & Tracking: Identifies and tracks objects using YOLOv8
- Precise Segmentation: Generates detailed object outlines using SAM 2
- Real-time Analytics: Monitors FPS, processing time, and object statistics
- Interactive UI: Modern web-based dashboard with customizable display options
- Screenshot & Fullscreen: Captures and views important moments
- Multi-source Input: Supports sample videos, webcam, and custom video uploads
- Detailed Object Information: Tracks IDs, positions, sizes, and confidence scores
- Python 3.8+
- CUDA-compatible GPU (recommended for real-time performance)
- OpenCV
- NumPy
- Pandas
- Torch
- Ultralytics
- Flask
- Segment-anything
-
Clone this repository:git clone https://github.com/SiddhantSwan12/manufacturing-vision-system.git cd manufacturing-vision-system
-
Install dependencies:pip install -r requirements.txt
-
Verify models and sample videos: Ensure
yolov8n.ptandsam2_checkpoint.pthare in themodels/directory. Download a sample video if needed: python download_sample_video.py
Run the complete system (generate test video + run inspection UI + manufacturing vision dashboard):
The system can be run with various options: Options:
--no-cap-inspection: Run only the manufacturing vision dashboard, skipping bottle cap inspection--skip-video-gen: Skip test video generation (use existing video)--video-duration: Set test video duration in seconds (default: 30)--video-output: Specify output path for test video (default: input.mp4)--output-dir: Specify output directory for inspection results (default: output)
To generate a test video without running the inspection UI: python scripts/generate_test_video.py --output input.mp4 --duration 30
To run the bottle cap inspection UI on an existing video file: python scripts/cap_inspection_ui.py --video input.mp4 --output output
To run the web-based dashboard for object detection, tracking, and segmentation: python run.py --no-cap-inspection
-
Bottle Cap Inspection:
- Test Video Generation: Creates a video with bottle caps moving on a conveyor belt
- Caps move in a straight line
- Some caps have defects: color variations, scratches, or misalignment
- Object Detection: Uses background subtraction and contour analysis to detect caps
- Object Tracking: Tracks caps across frames to maintain consistent Cap IDs
- Defect Analysis:
- Shape Analysis: Checks for circularity
- Color Analysis: Checks for proper gold/yellow outer ring and white inner
- Position Analysis: Checks if cap is properly centered
- UI Display: Shows a real-time display with:
- Left panel: Video feed with tracked objects
- Right panel: Detailed inspection results for the cap in the central ROI
- Test Video Generation: Creates a video with bottle caps moving on a conveyor belt
-
Manufacturing Vision System:
- Object Detection and Tracking: Uses YOLOv8 to identify and track objects, assigning unique track IDs
- Segmentation: SAM 2 generates precise segmentation masks for detected objects
- Real-time Processing: Processes video frames, applying detection, segmentation, contour extraction, and visualization
- Web Interface: Streams video and displays:
- Interactive controls
- Real-time statistics (FPS, objects detected, processing time)
- Detailed object information (IDs, positions, sizes, confidence scores)
- Bottle Cap Inspection:
- Press 'q' to quit the application
- Press 's' to save a screenshot of the current inspection view
- Web Interface:
- Take screenshots of the current frame
- Toggle fullscreen mode
- Toggle bounding boxes, contours, and track IDs
- Monitor object details in the sidebar
backend/: Core logic for detection, segmentation, and video processingdetection.py: YOLOv8 detection and tracking logicsegmentation.py: SAM 2 segmentation and contour extractionutils.py: Helper functions for visualization and data processingvideo_processor.py: Integrates detection, segmentation, and output
frontend/: Web interface componentsstatic/css/style.css: Styles for the web interfacestatic/js/app.js: Client-side JavaScript for interactive featurestemplates/index.html: HTML template for the dashboardapp.py: Flask app for serving the frontend and streaming video
models/: Pre-trained modelsyolov8n.pt: YOLOv8 model (downloaded automatically)sam2_checkpoint.pth: SAM 2 checkpoint
data/: Sample and uploaded videostest_video.mp4: Sample manufacturing videouploads/: Directory for user-uploaded videos
scripts/: Bottle cap inspection scriptsgenerate_test_video.py: Generates test videos with bottle capscap_inspection_ui.py: Main inspection UI for bottle cap analysisrun_cap_inspection.py: Runs both video generation and inspection
output/: Default output directory for results and screenshotsrun.py: Main entry point for the applicationdownload_sample_video.py: Downloads a sample videorequirements.txt: List of Python dependenciesREADME.md: Project documentation
- Bottle Cap Inspection:
- Adjust detection parameters in
scripts/cap_inspection_ui.py(e.g., circularity thresholds, color ranges) - Modify test video generation settings in
scripts/generate_test_video.py(e.g., cap size, defect frequency)
- Adjust detection parameters in
- Manufacturing Vision System:
- Change model paths in
backend/detection.py(YOLOv8) orbackend/segmentation.py(SAM 2) - Adjust detection confidence threshold in
backend/detection.py - Modify visualization settings (colors, line thickness) in
backend/utils.py - Change resize width in
frontend/app.pyfor performance vs. quality
- Change model paths in
-
CUDA Out of Memory: Reduce input frame size or use a smaller model
-
Slow Performance: Use a GPU or reduce frame size for CPU processing
-
Model Loading Errors: Verify model paths and ensure models are downloaded
-
Browser Compatibility: Use Chrome or Firefox for best results
-
Bottle Cap Detection Issues: Adjust detection thresholds in
scripts/cap_inspection_ui.py -
Missing Dependencies: Install manually if needed:pip install opencv-python numpy pandas torch ultralytics flask segment-anything
-
Bottle Cap Quality Control: Detect and flag defective caps based on shape, color, and position
-
Part Tracking: Monitor components through assembly lines
-
Quality Control: Identify defective parts based on visual characteristics
-
Object Counting: Count products on a conveyor
-
Process Monitoring: Analyze material flow through production
-
Safety Monitoring: Detect objects in restricted areas