r/computervision • u/Grouchy_Signal139 • Oct 13 '26
Help: Project OpenCV pixel-difference detection gives inconsistent results for some IC tray pockets. Should I try another method?
Hi everyone,
I’m developing a vision-based counter for ICs in JEDEC trays using a Raspberry Pi camera and OpenCV. Currently, I’m using an empty-tray reference image and pixel-difference detection to determine whether each pocket contains an IC.
Most pockets work well, but I’m having trouble with certain pockets that don’t have a visible hole in the center.
My observations:
-I’ve locked the camera settings and adjusted the lighting angle, which has improved detection.
In the problematic pockets, the IC is visibly present, and its engraving is distinguishable from the surrounding area.
-However, the pixel-difference count is only around 300–600 out of 1,400 pixels, compared with approximately 900 in other pockets.
The count also varies slightly between captures of the same IC, possibly due to differences in the contrast and colour of its engraving.
-I’m currently using a 0.4 threshold for the changed-pixel ratio to avoid false positives.
I’m considering using a different detection method specifically for these pockets.
My questions:
-Is it reasonable to use different detection methods for different pocket types?
-What would you recommend trying first to improve reliability?
-Could small variations in lighting or pixel intensity explain the inconsistent pixel counts, even with locked camera settings?
I’d appreciate any suggestions or experiences with similar industrial vision applications. Thanks!
Sorry i forgot to save the screenshot for failed detection. And this is the only image i have in my gallery.

