Hey there, I writing a code for bubble detection, This is the code i'm using as of now.
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/features2d.hpp>
void main()
{
cv::Mat src = cv::imread("e:/template/bubble.jpg");
cv::Mat matX; cv::Mat matY; cv::Mat gray;
cv::blur(src, src, Size(5, 5));
cv::cvtColor(src, gray, COLOR_BGR2GRAY);
cv::Sobel(gray, matX, CV_16SC1, 1, 0);
cv::Sobel(gray, matY, CV_16SC1, 0, 1);
cv::Mat matXY = abs(matX) + abs(matY);
matXY.convertTo(matXY, CV_8UC1);
cv::Mat bin;
cv::threshold(matXY, bin, 100, 255, cv::THRESH_BINARY);
cv::waitKey();
}
source image
The Output of bin is as follows:
By using the sobel method, it can help to find some bubbles, but also lost a lot of especially small bubbles. I have tried contour recognition and other methods, but I can’t get good results from this picture. I hope I can get some pointers from everyone.