15

How can I detect a quadrilateral signboard from an image captured using a mobile phone? How can i detect shapes like rectangle? rounded rectangle (rounded corners instead of shape corners)?

I am using opencv.wrapper but i am new to it.

Thanks.

Here is the sample: alt text http://www.freeimagehosting.net/uploads/b03442fd36.png

alt text http://www.freeimagehosting.net/uploads/e6b36040e8.png

Due to the noise and many lines there, i am not able to determine which is the boundary line of the signboard. Sometimes I can find the boundary of the lines after hough transform. I am trapped....in this kind of scenario...

This is the 2 raw pictures taken from mobile phone camera

alt text http://www.freeimagehosting.net/uploads/6dbd613edf.jpg alt text http://www.freeimagehosting.net/uploads/720da20080.jpg

I need ya advice to see how i can process the image to get the signboard out?

Thank you very much

  • 2
    Keywords: opencv, hough transform Duplicates: http://stackoverflow.com/questions/1817442/ http://stackoverflow.com/questions/2068013/ –  Jun 11 '10 at 07:43
  • Yeah, hough transform FTW! –  Jun 11 '10 at 13:43
  • but there are noise in the image how can i find out which is boundary of the signboard –  Jun 12 '10 at 06:46
  • @xabi123: hough transform, threshold, read out boundary –  Jun 12 '10 at 15:32
  • I used hough transform threshold...but there are still many lines...noises ard.. how to select which line is boundary... –  Jun 13 '10 at 17:33
  • 1
    Could you share a sample image? –  Jun 13 '10 at 19:00
  • I have uploaded 2 samples. Some of the boundary is not shown...and noises interferences make me veyr hard to identify the boundary lines... –  Jun 14 '10 at 15:06
  • Well your sample results are enough to find boundary. Now you have to calculate horizontal and vertical histograms. Peak values will give the coordinates of edges of your rectangle. –  Jun 14 '10 at 18:39
  • how to calculate horizontal and vertical histograms? –  Jun 15 '10 at 05:06
  • Here is another project uses histogram to detect boundaries. http://www.aforgenet.com/articles/hands_gesture_recognition/ –  Jun 15 '10 at 05:29
  • are u refering the sample after edge detection or after hough transform? –  Jun 15 '10 at 07:57
  • Image at the right : http://www.freeimagehosting.net/uploads/e6b36040e8.png –  Jun 15 '10 at 10:34
  • Oic...this is one of the simple sample which has the least noise.... –  Jun 15 '10 at 15:55
  • I upload another 2 raw image taken from mobile phone camera.. How shd I actually process the image to take the signboard out. Thanks..I need ya advice on this. –  Jun 15 '10 at 16:20
  • I have face some issuess.. I always have some part of boundary being cut off due to the noise near the bonudary lines. How can I resolve this issues?

    Thanks.

    –  Jun 17 '10 at 17:09
  • Since the distance between peaks in Hough domain refer to angle between lines, you can constraint searching for pairs of peaks, instead of single peaks (the distance can be 90° + some tolerance due to perspective distortion). I did this for similar problem (rectangle detection using Hough). Perspectively distorted rectangles (special case of quadrilaterals) can be more tricky. You can also detect color/texture on both sides of lines - the detected quadrilateral should be similar color/texture inside, i.e. on the corresponding half-plane created by a line. – Libor Jul 30 '12 at 10:33
  • can you re-upload the images? use the upload button – endolith Aug 30 '15 at 13:32

3 Answers3

7

Both your images contain many lines that have nothing to do with the sign you're looking for. And some of those lines are longer/have higher contrast than the lines you actually want, so I think detecting the edge lines (e.g. using a hough transform or by summing up contrasts horizontally/vertically) will not work.

But: The sign you're looking for has other characteristics that should be easier to detect:

  • There sign background has (almost) constant brightness
  • It takes up a relatively large area of the image
  • It's near the center of the image

So you're looking for a large connected area with low contrast. I've hacked a proof-of-concept algorithm in Mathematica. (I'm not an OpenCV expert, but I'll mention the respective OpenCV function when I know them.)

First, I use gaussian derivative filters to detect the gradient magnitude at each pixel. The gaussian derivative filter has a wide aperture (11x11 pixels in this case), so it is very noise-insensitive. I then normalize the gradient image to mean=1, so I can use the same thresholds for both samples.

src = Import["http://www.freeimagehosting.net/uploads/720da20080.jpg"];
pixels = ImageData[ColorConvert[src, "Grayscale"]];
gradient = Sqrt[GaussianFilter[pixels, 5, {1, 0}]^2 + GaussianFilter[pixels, 5, {0, 1}]^2];
gradient = gradient/Mean[Flatten[gradient]];

OpenCV implementation: You can use sepFilter2D for the actual filtering, but apparently, you'll have to calculate the filter kernel values yourself.

The result looks like this:

gradient magnitude

In this image, the sign background is dark and the sign borders are bright. So I can binarize this image and look for dark connected components.

binaryBorders = Binarize[Image[gradient], 0.2];
sign = DeleteBorderComponents@ColorNegate[binaryBorders];
largestComponent = SortBy[ComponentMeasurements[sign, {"Area", "ConvexVertices"}][[All, 2]], First][[-1, 2]];

OpenCV implementation: Thresholding should be straightforward, but I think OpenCV doesn't contain connected component analysis - you can either use flood fill or cvBlobsLib for that.

Now, just find the largest blob near the center of the image and find the convex hull (I've simply used the largest blob that's not connected to the background, but that might not be enough for every image).

Results: enter image description here enter image description here

Niki Estner
  • 6,181
  • 1
  • 30
  • 30
0

Another approach that you can take that is more robust to noises in this situation is to generate a curve of the mean gray-level of the image along the x-axis and along the y-axis. That is, compute the mean gray level for each line/column in the image.

If, for example, the signboard (or its borders) is lighter than its surroundings (which is the case for all the examples shown in the question) you will have two peaks in your x-axis curve (for the left and right and borders) and two peaks in you y-axis curve (for the top and bottom borders). Using a border detection technique for a 1-dimension signal (maybe a high-pass filter) you can deduce the corners coordinates of the signboard.

I have seen this approach being used to to detect license plates and also for face recognition (the nose tends to be the brighter part of the face, so it generates a peak in the x-axis and y-axis curves).

Alceu Costa
  • 206
  • 1
  • 4
0

This might be a little upside-down idea, but might be worth trying out. Instead of trying to detect the rectange and thinking of the text like noise, maybe you can treat the text like information and use it to detect the rectange easier.

Here's the outline of the idea:

  • detect the text in the image. It does not need to be a robust implementation (you should be able to google some small library that does that, or maybe OpenCV has it), just a rough estimate of the text in the image
  • find the cener of all the text detections. Even with noisy images it should be around the real place
  • do Hough rectangle decetion on the area around the text detections. Maybe use the median distance from the center of the text detections, or something similar. Do different diameters and take the strongest recall.

The explanations and advantages:

  • the area around the text is homogenous usually -- the real rectangle should be the first strong recall
  • this way you do not have to do hough transform on the whole image, so you can do it more thurally (maybe multiple times on the same area but with different bucket sizes...)
penelope
  • 3,676
  • 1
  • 26
  • 63