Hi,
I don’t have much experience in OpenCV and I would like a bit of help in the program I work on.
I’m working with an image like this one below :
The idea would be to detect those shapes and get their dimensions.
For know I’m using a gaussian blur to get rid of the noise and a SimpleBlobDetector to find the shapes on the image.
What can I do now to get theses shapes dimensions knowing that I will only have to process ellipses ?
SimpleBlobDetector
should be able to filter for circularity.
if you need more control over what’s going on, I’d recommend connectedComponentsWithStats or findContours, and then go from there
there’s fitEllipse, which you’d apply to a contour. this example shows minAreaRect and fitEllipse, which are independent of each other OpenCV: Creating Bounding rotated boxes and ellipses for contours
Seems to work,
Here is my code :
Mat imgCanny = new Mat();
Mat imgContours = new Mat();
Mat<OpenCvSharp.Point>[] points;
List<RotatedRect> rectangles = new List<RotatedRect>();
RotatedRect rect = new RotatedRect();
OpenCvSharp.Size imgSize = new OpenCvSharp.Size(9, 9);
HierarchyIndex[] index;
//Filtrage (inversion → flou gaussien → Canny)
img = Cv2.ImRead(imagePath, ImreadModes.Grayscale);
Cv2.BitwiseNot(img, img);
Cv2.GaussianBlur(img, img, imgSize, 4);
Cv2.Canny(img, imgCanny, _MinThreshold, _MaxThreshold);
//Recherche des contours
points = Cv2.FindContoursAsMat(imgCanny, RetrievalModes.External,ContourApproximationModes.ApproxSimple);
//Pour chaque forme trouvée, on détermine l'ellipse correspondante
for(int i = 0; i<points.Length; i++)
rectangles.Add(Cv2.FitEllipse(points[i]));
Cv2.CvtColor(img, img, ColorConversionCodes.GRAY2BGR);
//On affiche toute les éllipses trouvées
foreach(RotatedRect rectangle in rectangles)
Cv2.Ellipse(img, rectangle, Scalar.Red);
var w3 = new Window("Ellipses", img);
Thank you very much !