Question

OpenCV beginner here. I'm struggling to detect a specific shape in openCV using C++. The specific shape is the letter "E".

I have considered multiple methods of doing this. Template matching and OCR will not work at any angle so I'm thinking of using canny edge detection. After researching this it would appear that Hough's line transform or canny edge detection could be used.

I am able to implement both of those, but it's the next step that I am having trouble with. Could any of you please provide some guidance on how to move forward from here. After applying the Canny filter, how do I check that the letter "E" is present?

The input and output images are below, however they could be at any angle.

Input:

input

Output:

output

Was it helpful?

Solution

Depending on how robust this "detection" needs to be, the complexity of possible solutions to your problem may differ quite extensively. As you didn't mention robustness in your question, this is probably not an issue. Therefore, a rather simple solution could be:

  1. Extract the contours from the binary image (Canny) using cv::findContours().
  2. For each contour found, compare the number of contour points to the number of contour points you expect for the letter "E".
  3. If it matches, you've detected an "E".

If you need more robustness, you could:

  • Add subsequent checks on the basis of the contour, e.g., moments, Hu moments.
  • Further preprocessing steps, e.g., rotate the bounding box of candidate objects to some normalized orientation.
  • Something completely different, e.g., Generalized Hough Transform (as in here: Image Processing: Algorithm Improvement for 'Coca-Cola Can' Recognition).
  • I don't think SIFT or SURF would do here, because the object lacks an interesting texture pattern.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top