Case study · Computer vision & industrial automation · October 2025
AI-powered garment measurement and quality inspection.
How computer vision can turn a photo of a garment into structured measurements, and how that prototype could grow into an industrial inspection workstation and a measurement platform for apparel brands.
- Computer vision
- Python
- OpenCV
- Apparel technology
- Industrial R&D
- Built by
- Insaf Inhaam & Bavaram Karunaaharan
- Type
- Computer vision R&D
- Stack
- Python · OpenCV · NumPy · SciPy
- Status
- Working software prototype
The challenge: a “medium” isn't one size.
One supplier's medium T-shirt can differ from another's in chest width, shoulder width and length. Stores often publish a generic size chart instead of the real measurements of each garment, because measuring every item by hand is slow and two people rarely measure it the same way.
We set out to test whether a photograph could capture garment dimensions consistently enough to make measurement faster, repeatable and digital from the start.
What we built.

01 · Input 
02 · Edge map 
03 · Measured
01
Capture
A photo of the garment laid flat, with a 5 × 5 cm green square in frame.
02
Calibrate
The square is found by colour and shape, giving a pixels-per-centimetre scale.
03
Detect
Edges are enhanced and the garment outline is isolated from the background.
04
Measure
Width and length are read from the outline, corrected if the garment is rotated.
05
Review
An annotated image and a measurement report are saved for the operator to check.
The engineering behind it. Python and OpenCV, built as separate modules for detection, classification, measurement and drawing.
Finding the reference square reliably
The calibration square is searched in two HSV colour ranges to cope with different lighting, and every green candidate is scored on area, solidity and squareness. The best-scoring shape sets the scale.
Getting a clean garment outline
Fabric texture and soft shadows break simple edge detection. The pipeline combines bilateral filtering, contrast enhancement (CLAHE), two Canny passes at different thresholds and morphological closing to join broken edges.
Garments that aren't laid straight
Both an axis-aligned box and a minimum-area rotated box are computed. If the garment is tilted by more than 5°, measurements follow the rotated box instead of overstating the width.
Classifying without a training set
We tried a YOLOv8 model, but general-purpose models don't recognise garment types. The working version classifies by shape instead, using aspect ratio, solidity and how far the sleeves extend from the body.

Known limits of the prototype
- One global scale assumes the camera is square to a flat garment. Tilt and depth differences add error.
- Shoulder width is estimated from chest width, not measured from landmarks.
- It needs a flat garment on a plain, contrasting background.
- Accuracy has not yet been validated against tape measurements across many garments.
These limits are exactly what a fixed inspection station is designed to remove.
From a phone photo to an inspection station. Same software, controlled conditions.
A fixed camera height, even lighting and calibration targets on the table remove the variables that limit a hand-held photo. Camera, lens and table size would be chosen from the largest garment and the tolerance a manufacturer needs, and validated before any accuracy is promised.
| Edge processor | Raspberry Pi 5 (8 GB) for capture, calibration and the operator interface; heavier models on a Jetson or in the cloud |
|---|---|
| Camera | High-resolution camera at a fixed height; Pi Camera Module 3 for R&D, a machine-vision camera for production |
| Lighting | Diffused LED bars for even, shadow-free light, switched through a driver, never straight from GPIO |
| Inspection surface | Matte or backlit table that separates any garment colour from the background |
| Calibration | ChArUco targets for lens distortion, scale and perspective correction |
| Operator controls | Touchscreen for review and a physical capture button |
A connected measurement platform.
- Garment
- Camera
- Edge device
- Measurement engine
- Cloud platform
- E-commerce / ERP
Inspection · T-shirt, size M
Interface concept| Point of measure | Target | Measured | Tolerance | Result |
|---|---|---|---|---|
| Chest width | 52.0 | 52.3 | ±1.0 | PASS |
| Body length | 70.0 | 71.5 | ±1.0 | FAIL |
| Shoulder width | 44.0 | 44.2 | ±0.5 | PASS |
POST /v1/measurements
{
"measurement_id": "meas_demo_001",
"status": "completed",
"garment_type": "t_shirt",
"unit": "cm",
"measurements": {
"chest_width": 52.3,
"body_length": 70.5
},
"requires_review": false
}- Tolerance checks per point of measure, flagged pass, fail or review
- Inspection history, batch summaries and CSV or PDF export
- Size charts published to Shopify and other stores after human approval
- Organisation accounts, device management, API keys and webhooks
Roadmap.
Phase 1
BuiltSoftware prototype
Photo-based garment detection, calibration and measurement in Python and OpenCV.
Phase 2
ProposedHardware R&D
Fixed camera, controlled lighting, lens calibration and a validation study against manual measurements.
Phase 3
ProposedPlatform
Cloud dashboard, tolerance-based quality inspection, multi-tenant accounts and e-commerce APIs.
Questions, answered.
How can computer vision measure garments?
A photo of a flat garment is segmented to find its outline, and an object of known size in the same photo converts pixels to centimetres. Measurements are then taken from the outline or from detected landmarks such as shoulder and sleeve points.
Why is image calibration important?
Without a known reference, a photo has no physical scale. Lens distortion and camera tilt also stretch parts of the image, so production systems correct for both with camera calibration and perspective correction before measuring.
What are the limits of smartphone garment measurement?
Hand-held photos vary in height, angle and lighting, which changes the scale across the image. A fixed overhead camera with controlled lighting removes most of that variation, which is why we propose a workstation for production use.
Can garment measurements feed an e-commerce store?
Yes, through an API: measurements are returned as structured data that can populate product size charts after a person reviews them. We would never overwrite a store's existing measurements without approval.
Exploring computer vision for your manufacturing workflow?
Throughout builds software, AI and automation for complex operational problems, from a first prototype to a validated system.