Skip to content

About

Crack and stress detection for transparent components using polarized optical imaging

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

PolarVision

Crack and stress detection for transparent components using polarized optical imaging

Python OpenCV PyQt5 License Platform

Splash screen

Overview

Micro-cracks and residual stress in transparent components — architectural glazing, windshields, optical elements — are nearly invisible under ordinary lighting, yet they routinely precede failure.

PolarVision exploits stress birefringence. Placed between crossed polarizers, unstressed glass extinguishes the light and appears black, while stress concentrations rotate the polarization state and produce bright or colored interference fringes. The system captures these frames live from a USB camera, extracts crack geometry and stress distribution, and reports a four-level risk assessment with an interpretable score.

Main window
Live four-panel view with adjustable detection parameters and risk assessment

Features

Polarization-enhanced imaging Brightness-weighted chroma response that isolates birefringence signal from sensor noise
12-dimensional feature extraction Crack length, width, area, orientation, curvature, branch and endpoint counts, tip gradient, texture entropy
Four-level risk grading Intact / minor / medium / high, backed by an interpretable risk score R
Plug-and-play USB cameras Automatic device enumeration, external-camera preference, hot-plug detection
Real-time processing 15 fps capture with a frame-skipping pipeline; runs smoothly on low-spec laptops
Demo fallback Cycles sample imagery when no camera is present, so the UI is never blank
One-click reporting Composite PNG report plus a full JSON feature dump
Standalone executable PyInstaller build requires no Python on the target machine

How It Works

Optical setup

[LED backlight] → [polarizer] → [specimen] → [analyzer ⊥] → [USB camera]
                                     ↓
              unstressed → extinguished, appears black
              stressed   → birefringent, colored fringes appear

Processing pipeline

frame → polarization response S → CLAHE → validity mask → Canny edges
                                                             ↓
risk grade ← risk score R ← 12-D features ← crack/stress masks ← morphology

Polarization response:

S = √( (V/255)² + Chroma² ) / √2 ,  Chroma = (Sat × V) / 255²

Saturation must be weighted by value. HSV saturation is unreliable at low brightness — a near-black pixel can report very high saturation — so using the raw channel turns sensor noise on a dark background into phantom stress signal.

Risk score:

R = w₁·(L/L_max) + w₂·(A_s/A_max) + w₃·(G_t/G_max) + w₄·(P_max/P_ref)
R Grade Interpretation
< 0.15 🟢 INTACT No significant defects
0.15–0.35 🟡 MINOR Minor cracking, monitor
0.35–0.65 🟠 MEDIUM Moderate risk, re-inspect
> 0.65 🔴 HIGH High risk, replacement advised

Quick Start

Run from source

git clone https://github.com/<your-username>/PolarVision.git
cd PolarVision

python -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate

pip install -r requirements.txt
python main.py

Build a Windows executable

:: Keep the project in an ASCII-only path, e.g. C:\Projects\PolarVision\
build.bat

The result lands in dist\PolarVision\PolarVision.exe. Ship the whole dist\PolarVision\ directory — the executable needs the _internal\ folder beside it.

Process a single image offline

python -m polarvision.cli path/to/image.jpg --out reports/
Generated report
Generated report: four-panel view plus the full feature breakdown

Project Structure

PolarVision/
├── main.py                     entry point
├── build.bat / build.ps1       Windows build scripts
├── run_dev.bat                 run from source without packaging
├── build.spec                  PyInstaller configuration
├── polarvision/
│   ├── processing.py           polarization response, enhancement, extraction
│   ├── features.py             12-D features, risk score, grading
│   ├── classifier.py           rule-based grading + optional RandomForest
│   ├── cameras.py              device enumeration and preference scoring
│   ├── welcome.py              animated splash screen
│   ├── gui.py                  PyQt5 main window
│   ├── cli.py                  command-line interface
│   ├── report.py               report generation
│   └── synthetic.py            synthetic test image generator
├── sample_images/              photographed specimens + synthetic samples
└── docs/
    ├── PROJECT_BRIEF.md        full technical documentation
    └── images/

Tuning

Six sliders adjust detection live. Optimal values depend on the optical path, camera, and ambient light.

Slider Controls Raising it
Edge low / high Canny hysteresis thresholds Detects fewer faint edges
Saturation thr Chroma floor for stress regions Only more vivid fringes count as stress
Brightness thr Value floor for stress regions Suppresses false positives in low light
CLAHE clip Contrast enhancement strength Weak fringes stand out, noise amplifies too
Min crack area Minimum connected-component size Filters out more speckle noise

Training a Custom Classifier

Grading is rule-based by default. Once labelled specimens are available, a RandomForest can take over:

from polarvision.classifier import PolarVisionClassifier

# CSV header: L,W,A_c,theta,C,N_b,N_t,P_mean,P_max,A_s,G_t,H,label
PolarVisionClassifier.train_from_csv("samples.csv", out_path="model.joblib")

Place the resulting model.joblib next to main.py (or the executable) and the application switches to ML inference at startup.


Known Limitations

  • The algorithm assumes input from a crossed-polarizer optical path. Frames captured under ordinary illumination have bright backgrounds throughout, which drives heavy false positives. This is an input-domain mismatch rather than an implementation defect.
  • Single-angle capture cannot recover full Stokes parameters, so stress orientation is only coarsely estimated from image moments. A four-angle interface is present in processing.py for a future hardware upgrade.
  • RiskWeights normalization constants are empirical and should be calibrated against known reference specimens.
  • Ambient light contaminates stress detection; a darkroom or a light shield is recommended.

Built With

Python 3.12 · OpenCV · PyQt5 · NumPy · scikit-learn · scikit-image · PyInstaller · pygrabber


Credits

Project conception, system architecture, and hardware testing by Yichen Liang (Henan University of Science and Technology,CHINA).

Algorithm design, implementation, and software validation by Zihan Zhao (Penn State University,United States).

Fell free to ask if you have any questions through GitHub OR email: zihan_z64@outlook.com and yichenliang17@gmail.com.

Generative AI tools were used in parts of this project.


License

MIT

About

Crack and stress detection for transparent components using polarized optical imaging

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages