Hi everyone,
Here in above image you can see because of lights even bad image turned to good.
I’m using Raspberry Pi + Picamera2 + OpenCV to detect if anything is stuck on a metal mold plate.
The logic works, but detection becomes **unreliable when lighting changes or reflections appear.
**
Current method
-
Fixed ROI
-
CLAHE for contrast normalization
-
cv2.absdiff()between reference & live frame -
Adaptive threshold using mean/std
-
Morphological cleanup + contour detection
diff = cv2.absdiff(ref_eq, test_eq)
mean_diff = np.mean(diff)
std_diff = np.std(diff)
_, thresh = cv2.threshold(diff, mean_diff + 3.5*std_diff, 255, cv2.THRESH_BINARY)
Issue
Reflections or brightness variation cause false positives/negatives — the system detects “defects” where there are none.
Looking for
Suggestions or algorithms to make detection robust under lighting/reflection changes, e.g.:
-
Illumination normalization
-
SSIM / feature-based / background subtraction
-
Lightweight ML anomaly detection
Any help or code ideas would be greatly appreciated


