0

I need to detect shapes and their colours on a taken image. These shapes are: a heart, a rectangle, a star and a circle. Each shape has one of 5 predefined colours. Colour recognition works fine, but shape recognition is a real problem.

After hours and hours of googling, trying and tweaking code, the best I have come up with is the following procedure:

  • First, read the image and convert it to grayscale.

  • Then, apply blur to reduce the noise from the background. Medianblur seems to work best here. Normal blur has little effect, and Gaussian blur rounds the edges of the shapes which gives trouble.

  • Next, apply threshhold. AdaptiveThreshold doesn't give the results I expected; the result vary widely with each image. I now apply two thresholds: One uses Otsu's algorithm to filter the light shapes, and the other uses the Binary Inverted value for the darker shapes.

  • Finally, find contours on the two threshholds and merge them in one list. By the amount of points found in each contour, I decide which shape is found.

I have tried adding Canny, sharpening the image, different threshholds, Convex Hull, Houghes, etc. I probably tried every possible value for each method as well. For now, I can get things working with the above procedure on a few images, but then it fails again on a new image. Either it detects too much points in a contour, or it doesn't detect the shape at all.

I am really stuck and dont know what else to try. One thing I still have to work out is using masks, but I can't find much information on that and don't know if it would make any difference at all.

Any advice is more than welcome. If you would like to see my code, please ask. You can find sample images here: http://tinypic.com/a/34tbr/1

Ad Fundum
  • 665
  • 6
  • 22
  • See similar question [here](http://stackoverflow.com/questions/22023923/shape-detection-in-python-using-opencv/22042006#22042006) might be helpful. – Haris Mar 12 '14 at 04:51
  • I have analysed that question many times. As above, I can get the code working for that image by adjusting a few parameters, but then it doesn't work any more for some of the sample images in my question, or for any new image at all. How do I make my program more robust, so it can detect new images (which might be less sharp or have a different lightning) as well? – Ad Fundum Mar 12 '14 at 09:52
  • As your image is of pre-defined colour, convert to hsv then perform thresholding which will resolve the lightning variation. – Haris Mar 12 '14 at 11:22
  • Is the background static? have you tried background subtraction? – medloh Nov 04 '15 at 00:49

0 Answers0