0

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.

nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Sagar Sm
  • 91
  • 1
  • 2
  • 3
  • possible duplicate of [Shape Detection (circle, square, rectangle, triangle, ellipse) for a camera captured image + i OS 5 + Open CV](http://stackoverflow.com/questions/12495200/shape-detection-circle-square-rectangle-triangle-ellipse-for-a-camera-capt) – stijn Aug 19 '13 at 06:36

3 Answers3

1

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.

OpenMinded
  • 1,175
  • 2
  • 9
  • 24
  • Yes , finding contours is what even I was thinking . I have to take a deeper look as to how the angles and corners are detected . Thanks for the info . I will look into it and get back !! – Sagar Sm Aug 21 '13 at 06:30
0

You can also take a look at the Hough transform.

GilLevi
  • 2,117
  • 5
  • 22
  • 38
  • Hough transform is basically to detect circular objects , right ? I doubt if I can use that to detect a plus sign. – Sagar Sm Aug 21 '13 at 06:28
  • You can use it to detect lines. btw, you should take a look at this link which explains how to detect shapes using openCV: http://opencv-code.com/tutorials/detecting-simple-shapes-in-an-image/ – GilLevi Aug 21 '13 at 07:31
0

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.

Odrai
  • 2,163
  • 2
  • 31
  • 62
  • I have previously used cvblobslib for people tracking , but that is basically to detect moving objects . Need to find a way to detect shapes using that . Thank you . – Sagar Sm Aug 21 '13 at 06:32