I'm still a beginner in OpenCV.
Currently, I'm trying to detect a specific shape as in the image in the link below using OpenCV.
I've read many blogs and articles about detecting shapes using OpenCV but I've not found anything related to what I'm working on.
Also, I can't use methods like cvHistogram, because I don't want to find matches in two almost identical pictures, but instead, I want to detect a specific shape, and not some geometric shapes like rectangles, circles, etc.
Do you know a way to do it?
Thank you in advance.
When working with OpenCV Python, images are stored in numpy ndarray. To get the image shape or size, use ndarray. shape to get the dimensions of the image. Then, you can use index on the dimensions variable to get width, height and number of channels for each pixel.
Python - OpenCV & PyQT5 together To detect a triangle in an image, we first detect all the contours in the image. Then we loop over all the contours. Find the approximate contour for each of the contours. If the number of vertex points in the approximate contour is 3, then draw the contour and set it as a triangle.
Compute the aspect ratio of the contour cnt. Set a range of aspect ratios to detect the square. We set it [0.9, 1.1]. If the ratio is between 0.9 and 1.1, the detected contour is a square else it is a rectangle.
It's hard to say how to detect this shape. You should specify some criterions about shape that you want to detect. For example in your case:
And so on.
And after this it will be easier to find good detection algorithm.
By the way reading these docs will be useful:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With