9

I am working on an ANPR system using OpenCV and have seen in a few articles a way of doing character segmentation. The idea is to make a graph showing the concentration on color across the image.

How do I do this?

enter image description here

This is the image that I have:

enter image description here

I need to detect the locations of the black areas as shown above to identify each of the characters.

I have tried adding the values up pixel by pixel but I am doing this on Android and the time this takes is unacceptable.

Noha Kareem
  • 1,748
  • 1
  • 22
  • 32
Mike Norgate
  • 2,393
  • 3
  • 24
  • 45
  • What is this image? How do you do what? Please try to add more details about what you actually have and what you want to do. – Adi Shavit Feb 19 '12 at 18:39
  • So you currently have the location of the black areas? Can you put a snippet of code for what you mean by "adding values pixel by pixel"? – mathematical.coffee Feb 19 '12 at 23:42
  • If speed is your only issue then I'd suggest you scale your input image to a lower resolution by a factor of 2 or even 4. The input image you show is very high resolution for the task you want to perform. – jilles de wit Feb 20 '12 at 12:49

2 Answers2

7

Ok, its a month later, but I wrote you a little bit of code (in python) for this ;)

(Assuming you are just after the image density histogram)

import cv

im2 = cv.LoadImage('ph05l.jpg')
width, height = cv.GetSize(im2)
hist = []
column_width = 1   # this allows you to speed up the result,
                   # at the expense of horizontal resolution. (higher is faster)
for x in xrange(width / column_width):
    column = cv.GetSubRect(im2, (x * column_width, 0, column_width, height))
    hist.append(sum(cv.Sum(column)) / 3)

To speed things up, you need'nt alter your image files, just alter the bin width of the sampling (column_width in the script), obviously you lose some resolution if you do this (as you can see in the image below).

In the image, I show the results (graphing hist) with your file, using column_width's of 1, 10 and 100. They ran for me at 0.11, 0.02 and 0.01 seconds respectively.

I wrote it in PIL too, but it runs around 5 to 10 times slower.

character density histograms

fraxel
  • 34,470
  • 11
  • 98
  • 102
-2

Check out OpenALPR (http://www.openalpr.com). It does character segmentation the same way (using histograms). It's fairly fast on a desktop, but I'm not sure how fast that would be on Android.

Derrick Johnson
  • 377
  • 5
  • 9