This python script was created to see how I could detect the presence of a particle within clear liquid solution of a clear glass vial and check the height & width of an clear glass ampoule.
We start by capturing an amount of frames from a video source (e.g webcam) i used 4 frames. A standard process for inspection would be somewhere in the region of up to 30 frames for the ability to start detecting trajectory.
The frames are then merged, we can then set a region of interest to reduce the number of false positives / outline of the container or surrounding, crop the image, set to grayscale and thresholded.
Capture frames - i used 1 frame Set image to grayscale, apply threshold get the bounds of the tip show height and width
Create new python env
python -m venv envactivate env
source env/bin/activateinstall requirements
pip install -r requirements.txtYou can use the demo images by renaming the demo_img folder to images.
There is an easy to use GUI to change settings and reprocess images on the fly to test results.
python main.pyMain GUI - Detection settings are loaded from config.ini and are reloaded on save.
Generate ROI Particle - After clicking reset ROI you click to drag the region of interest for particles and then hit enter.
Generate ROI Fill Level - Now you can perform the second ROI for fill level detection, once selected hit enter and then escape to close.
Particle Detection results



