Sagar Sm
Sagar Sm

Reputation: 91

Detect shapes using Open CV

I have been trying to detect shapes in an image and also arrive at a count as to how many such shapes are present in an image, for example a plus sign. Are there any built in functions to detect such shapes ? IF any please let me know.

Thank you.

Upvotes: 0

Views: 1054

Answers (3)

Odrai
Odrai

Reputation: 2353

One way to detect shapes is to make use of cvBlobsLib.

A library to perform binary images connected component labelling (similar to regionprops Matlab function). It also provides functions to manipulate, filter and extract results from the extracted blobs, see features section for more information.

For an example, see: https://www.youtube.com/watch?v=Y8Azb_upcIQ

An alternative is to make use of EmguCV

Emgu CV is a cross platform .Net wrapper to the OpenCV image processing library. Allowing OpenCV functions to be called from .NET compatible languages such as C#, VB, VC++, IronPython etc. The wrapper can be compiled in Mono and run on Windows, Linux, Mac OS X, iPhone, iPad and Android devices.

Upvotes: 0

GilLevi
GilLevi

Reputation: 2137

You can also take a look at the Hough transform.

Upvotes: 0

OpenMinded
OpenMinded

Reputation: 1175

You need to find all contours in an image and then filter them.

We know that the plus sign has 12 corners. So you need to filter all contours that have 12 corners. Of course, sometimes this can give you some unwanted objects. So you can filter again those contours that have angles between 2 lines(3 corners) max 0.3 cos for example.

Take a look at squares.cpp in samples directory of OpenCV. It finds all contours with 4 corners and angles max. 0.3 cos. So pretty much all squares.

Upvotes: 1

Related Questions