Mike Norgate
Mike Norgate

Reputation: 2431

OpenCV Color Concentration Histogram

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.

Upvotes: 9

Views: 4651

Answers (2)

Derrick Johnson
Derrick Johnson

Reputation: 385

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.

Upvotes: -2

fraxel
fraxel

Reputation: 35289

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

Upvotes: 7

Related Questions