- Blob detection is segmentation of an image based on some criterias.
OpenCv and cvBlobLibs
- OpenCv contains many functions that you can use for image processing and then finally detecting blobs.
- cvBlobLibs is used for extracting blobs and filtering them based on area, perimeter etc… It is optional, but the example code uses it.
Pseudo-Steps of a Blob Detection Algorithm
- Image Filtering: Filter your image using cvBlur or cvSmooth. Use Gaussian filter.
- Image Segmentation: Segment your image with the color your want.
- Detect blobs: From the segmented image, connect all 4/8-connected image pixels. For every pixel, check the value of its pixel at its North, East, West and South. If it is also segmented include it in your blob. In this way, all disjointed patches can be detected as blobs.
- Filter blobs: Use some filter like area/roundness/compact or the blob detected to get the blob you are looking for.
- Track blobs: If you are detecting blobs in video, try to track blobs from one frame to the next. This will ensure robustness. A simple approach is to detect mean of the current blob and in the next image search for the mean near the current mean.
- For your robots, you can fix upto 2/3 round colorful circles on your robot and try to track them. Pick colors that you can easily filter. You can also use OpenCv's circle detection algorithm for the Filter blobs stage.
- Library headers for the cvBlobLib in Windows and Linux are different. For example, CBlobResult takes different number of arguments. Below is a Linux implementation. Sample codes has sample code for the Windows version.
Robert's Example Code
(I couldn't get the above example working, so here's an edited version that works for me)
- Convert your RGB image to HSV or YUV. HSV/YUV filter out intensity, color variance unlike RGB making it easy to filter out color pixels.
- Design an interface, a GUI to train your filter. For example, if you want to filter all orange pixels use a range of pixels near orange to compare rather than the exact orange colored pixel. Your GUI can make your task easier to select pixels near orange from an image by using Mouse in cvWindows.
- Use tracking to track your blob and robust detection. Use a filter like Kalman filter.
- Understand Math of filtering to get better results.