Ask Your Question
0

histogram in database

asked 2013-03-14 05:34:06 -0500

mrgloom gravatar image

I compute histogram for image(code below)

def compute_histogram_rgb(src, r_bins = 32, g_bins = 32, b_bins= 32):
        #create planes
        rplane = cv.CreateImage(cv.GetSize(src), 8, 1)
        gplane = cv.CreateImage(cv.GetSize(src), 8, 1)
        bplane = cv.CreateImage(cv.GetSize(src), 8, 1)

        planes = [rplane, gplane, bplane]
        cv.Split(src, rplane, gplane, bplane, None)

        #compute histogram
        hist = cv.CreateHist((r_bins, g_bins, b_bins), cv.CV_HIST_ARRAY,
                ranges = ((0, 255),(0, 255), (0, 255)), uniform = True)
        cv.CalcHist(planes, hist)      #compute histogram
        cv.NormalizeHist(hist, 1.0)    #normalize hist

        return hist

and then I want to store histogram in database (sqllite3 in python) but I don't know what format histogram is, do I need to unwrap it to vector?

edit retag flag offensive close merge delete

Comments

it would get much easier using the cv2 instead of the cv api, since it would be a simple numpy array then, which is easy to serialize as a 'blob' in sqlite3

berak gravatar imageberak ( 2013-03-15 05:51:13 -0500 )edit

cv2 is more complicated, do you have any example with numpy array?

mrgloom gravatar imagemrgloom ( 2013-03-15 06:52:05 -0500 )edit

1 answer

Sort by » oldest newest most voted
0

answered 2013-03-14 06:03:12 -0500

Documentation says the following

Python: cv.CreateHist(dims, type, ranges=None, uniform=1) → hist

So I am guessing that the createHist function actually throws back a python defined hist data type.

This link has some information contained on how histograms are actually created. I guess this can help ya further? http://msenux.redwoods.edu/math/python/hist.php

When storing in a database, I would suggest reading out the data of that object type and putting it in a own selected format.

edit flag offensive delete link more

Comments

it seems when table created I need to specify type of column http://docs.python.org/2/library/sqlite3.html

mrgloom gravatar imagemrgloom ( 2013-03-14 06:40:19 -0500 )edit

That is something you have to do in every database environment. However, I do not think it will support basic storage of a complete hist object. So creating a vector of integers or so, will certainly do the trick.

StevenPuttemans gravatar imageStevenPuttemans ( 2013-03-14 06:49:39 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2013-03-14 05:34:06 -0500

Seen: 930 times

Last updated: Mar 14 '13