Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the best Region of Interest after edge detection in OpenCV

I would like to apply OCR to some pictures of 7 segment displays on a wall. My strategy is the following:

  1. Covert Img to Grayscale
  2. Blur img to reduce false edges
  3. Threshold the img to a binary img
  4. Apply Canny Edge detection
  5. Set Region of Interest (ROI) base on a pattern given by the silhouette of the number
  6. Scale ROI and Template match the region

How to set a ROI so that my program doesn't have to look for the template through the whole image? I would like to set my ROI base on the number of edges found or something more useful if someone can help me.

I was looking into Cascade Classification and Haar but I don't know how to apply it to my problem.

Here is an image after being pre-processed and edge detected: an image after being pre-processed and edge detected

original Image

enter image description here

like image 350
locorecto Avatar asked Feb 21 '12 04:02

locorecto


People also ask

How do I choose a region of interest in OpenCV?

Python OpenCV – selectroi() Function With this method, we can select a range of interest in an image manually by selecting the area on the image. Parameter: window_name: name of the window where selection process will be shown. source image: image to select a ROI.

Which is the best edge detection operator?

Canny's edge detection algorithm is computationally more expensive compared to Sobel, Prewitt and Robert's operator. However, the Canny's edge detection algorithm performs better than all these operators under almost all scenarios.


1 Answers

If this is representative of the number of edges you'll have to deal with you could try a nice naive strategy like sliding a ROI-finder window across the binary image which just sums the pixel values, and doesn't fire unless that value is above a threshold. That should optimise out all the blank surfaces.

Edit: Ok some less naive approaches. If you have some a-priori knowledge, like you know the photo is well aligned (and not badly rotated or skewed), you could do some passes with a low-high-low-high grate tuned to capture the edges either side of a segment, using different scales in both x and y dimensions. A good hit in both directions will give clues not only about ROI but what scale of template to begin with (too large and too small grates won't hit both edges at once).

You could do blob detection, and then apply your templates to blobs in turn (falling back on merging blobs if the template matching score is below a threshold, in case your number segment is accidentally partitioned). The size of the blob might again give you some hint as to the scale of template to apply.

like image 148
dabhaid Avatar answered Oct 02 '22 17:10

dabhaid