An object counter for a factory camera
The problem
Build a plain-Python pipeline that takes small greyscale images of parts on a conveyor belt, with uneven lighting and noise, and reports how many parts there are, where they are and whether any are too small.
Requirements
- Generate test images as grids: bright parts of several sizes on a darker background with a lighting gradient, plus salt-and-pepper noise
- Remove the noise with a median filter and correct the lighting with a top-hat or adaptive threshold
- Choose a threshold automatically with Otsu's method and clean the mask with opening and closing
- Label 8-connected components and report each part's area, bounding box and centroid
- Flag parts whose area is below a given limit and print an annotated text picture of the result
Technologies
- Python
- Median filtering
- Otsu thresholding
- Morphology
- Connected components
Step by step
- Write a generator for test images, with known part positions saved as ground truth.
- Build and test each stage on one image, printing the image after every stage as text shading.
- Add Otsu's threshold and compare it with a fixed threshold on images with different lighting.
- Label the parts and compute their measurements.
- Compare the found parts with the ground truth using bounding-box IoU and count misses and false alarms.
- Tune the filter sizes and element sizes and record which settings work best.
Expected result
A counter that finds every part in noisy, unevenly lit images, with a report of its measurements and an accuracy check against ground truth.
How it is evaluated
- Every stage is a separate, tested function
- The pipeline finds all parts on at least nine of ten generated images
- Detected boxes match the ground truth with IoU of at least 0.5
- The report explains which settings were chosen and why
Ways to improve it
- Split touching parts with erosion before labelling
- Estimate each part's orientation from its pixel positions
- Rewrite the pipeline with OpenCV on your own computer and compare the results