Inspiration

Automated visual inspection often gives one confident answer even when it should not. Missing a defect is costly, and false alarms waste people's time. We wanted an inspector that knows when it is unsure, tries to settle that itself, hands the rest to a person with the evidence, and leaves a record nobody can quietly change.

What it does

OptiInspect ("Inspection that takes a second look") finds defects in product photos with OpenCV 5 and scores how sure it is.

If the first look is unsure, the agent looks again: it compares afresh, boosts contrast, and zooms in, then shows every step it took. Safety rule: an extra check can confirm a defect but can never clear one. If the checks only make it look less likely, a person decides, seeing the exact region zoomed. Every step is written to a hash-linked audit log with the name of the person who acted. One click verifies that nothing was edited, reordered or removed. Wrong inputs (an answer mask, a blank image, another product) are refused instead of getting a confident guess. A full React app with accounts and roles, batch and camera inspection, a review queue, insights, and a heat map of where defects happen. Three labs to test the agent yourself: a Stress test (paint a defect and watch the real agent react, plus a sweep showing how faint a mark can be before it is missed), a Challenge (you and the agent judge the same real photos), and a Tolerance lab (drag the agent's decision lines over all 83 real photos and see the misses, false alarms and workload).

How we built it

Python, Flask and OpenCV 5.0.0.93 (phase correlation and ECC alignment, lighting match, an edge-tolerant difference, CLAHE contrast, zoom) with NumPy. "Normal" is learned from good photos of each product instead of guessing thresholds. The interface is React 19 with Vite, React Router and Framer Motion, with hand-written SVG charts. Accounts are local files with scrypt hashes, signed sessions, CSRF protection and roles. The agent's next check is chosen by simple rules, not an AI model. Everything runs on one computer with no cloud service. Code: https://github.com/akritiib30/OptInspect

Challenges we ran into

Our first scoring divided by each photo's own noise, which made clean real photos look "certain": all 20 good bottles were flagged. Calibrating "normal" on separate good photos fixed it. Real edges never line up perfectly. Forgiving mismatches near strong edges was the biggest single improvement (AUROC 0.82 to 0.98). With extra checks allowed to clear defects, three real small defects were wrongly dismissed. That led to the safety rule. An answer-mask image was once accepted as "defect confirmed, 1.00", so we added the wrong-photo check. Our test checked the server directly and missed that file uploads from the real page were broken. Testing in a real browser caught it. Accomplishments that we're proud of On 83 real MVTec AD bottle photos the agent confirmed 57 of 63 defects, sent 3 to a person, missed 3 faint ones, and wrongly confirmed none of the 20 good bottles. 136 automated checks pass, including one proving the Tolerance lab's replay matches the real agent photo by photo. The audit log detects edits, deletions and reordering.

What we learned

Calibration beats hand-picked thresholds. A system that admits it is unsure is more useful than one that always answers. Testing the real interface finds bugs that server tests miss. And our own stress test showed a limit: on these dark photos, bright marks are caught from about 13% strength, while dark marks need roughly 70% or more.

Honest limits

The edge setting was chosen while looking at the same test photos, so the results are somewhat optimistic. Only the bottle product was tested, at 256 px. Three faint contamination defects are missed. Accounts are local files (no email or two-step sign-in). The log is tamper-evident, not tamper-proof. The demo video uses a synthetic voice. Test photos are from MVTec AD (CC BY-NC-SA 4.0), used for non-commercial research and not redistributed.

What's next for OptiInspect

Testing more products and a held-out tuning split, higher-resolution inspection of suspicious regions, trying an AI model to choose the next check and measuring whether it beats the simple rules, two-step sign-in, anchoring the log in an external store, and optional cloud hosting.

Built With

Share this project:

Updates