My current thresholds:
dark_th = [(0, 70)] # catches black filament
white_th = [(170, 255)] # catches white filament
Gray filament (70-170) is not detected! Lighting changes also break it.
Question: How to create ONE dynamic threshold that works for ALL filament colors and lighting conditions?
Problem 2: Diameter Calculation
I calibrate with:
-
1.50mm → 100 pixels
-
1.75mm → 115 pixels
-
3.00mm → 200 pixels
My linear interpolation:
def calc_diameter(px):
if px <= px2: # 115 pixels
ratio = (115-100)/(1.75-1.50)
return ((px-100)/ratio) + 1.50
else:
ratio = (200-115)/(3.00-1.75)
return ((px-115)/ratio) + 1.75
But results are inaccurate, especially for 3.00mm.
Question: What’s the correct mathematical relationship between pixels and actual diameter? Linear? Quadratic? Pixels-per-mm ratio?
Hardware:
-
OpenMV Cam (VGA, Grayscale)
-
Fixed distance, manual exposure
What I need:
-
Code for dynamic threshold that works for any filament color
-
Correct calibration formula for 3-point measurement
-
Simple ROI tracking (filament can move slightly)
Thanks!

