Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 406
Mike Norgate Avatar asked Feb 19 '12 17:02

Mike Norgate


1 Answers

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

like image 131
fraxel Avatar answered Oct 17 '22 20:10

fraxel