Jack Gold
Jack Gold

Reputation: 201

I would like to detect a custom shape using OpenCV

I would like to detect the shape below, I have tried the following methods:

1) Training a cascade using opencv_traincascade and creating the positive images using opencv_createsamples - no success, lot's of false positives, the object does not have many features.

2) Tried doing ellipse detection, again lots of false positives as there's many ellipses in the scene. Also, it didn't give a solid detection as it's not a perfect ellipse.

3) Tried colour detection, gave good results but the object has multiple colours, ranging from green, red, blue and yellow, hence colour cannot be used for detection. Also, it varies due to illumination.

I was wondering whether I could train a classifier using the edges or some other way of customly defining a shape and detecting that in the scene.

Results using canny edge detection

Any help will be greatly appreciated.

Upvotes: 0

Views: 2421

Answers (1)

Leo91
Leo91

Reputation: 1741

Maybe you can try something like this. After that you have the edge image:

  1. Use findContours() to obtain the separated contours.
  2. Plot every contours on black image and use convexHull in order to have a shape with that contour.
  3. Build an edge template of your shape and apply convexHull on it: this will be your template to find in every new image.
  4. For every new image, compute Normalized Cross Correlation and find the coordinates with max Correlation.

This method has a strong assumption: the shape you're looking for is not varying its rotation or its scale. If you want to be invariant to rotation and scale you should apply another method to compare Template and the Imgae (for example a template matching that is rotation and scaling invariant, such as this: http://www.cv-foundation.org/openaccess/content_cvpr_2013/papers/Korman_FasT-Match_Fast_Affine_2013_CVPR_paper.pdf )

Upvotes: 0

Related Questions