How to save/load histogram data (bins)

464 views
Skip to first unread message

David Titarenco

unread,
Mar 29, 2011, 2:52:55 PM3/29/11
to javacv
I will deal with a large amount of histogram data that I would like to
store in a database (as opposed to memory or an xml file). How can I
extract the bin data from a histogram, given:

CvHistogram hist;

int h_bins = 30;
int s_bins = 32;

int hist_size[] = { h_bins, s_bins };
float h_ranges[] = { 0, 180 };
float s_ranges[] = { 0, 255 };

float[][] ranges = { h_ranges, s_ranges };

hist = cvCreateHist(hist_size.length, hist_size, CV_HIST_ARRAY,
ranges, 1);

IplImage planes[] = { h_plane, v_plane };
cvCalcHist(planes, hist, 0, null);

cvNormalizeHist(hist, 1);

It feels that dumping something like:

hist.bins().asByteBuffer(1024);

Just yields garbage..

Also, how would I go _back_ from something like a ByteBuffer to a
CvArr (or rather, CvMat)?

Samuel Audet

unread,
Mar 29, 2011, 5:51:34 PM3/29/11
to jav...@googlegroups.com
On 2011-03-30 03:52, David Titarenco wrote:
> I will deal with a large amount of histogram data that I would like to
> store in a database (as opposed to memory or an xml file). How can I
> extract the bin data from a histogram, given:

I think it would be easier to use the OpenCV file storage facilities for
that. Here's a sample that should help you:
http://tech.groups.yahoo.com/group/OpenCV/message/23544
And then you can copy the content of that XML file in your database, and
reload it with OpenCV again from a temporary file created from data in
your database..

> hist.bins().asByteBuffer(1024);
>
> Just yields garbage..

What you are looking for is probably getByteBuffer(), not asByteBuffer()..

> Also, how would I go _back_ from something like a ByteBuffer to a
> CvArr (or rather, CvMat)?

There's a factory method for that:
CvMat cvMat(int rows, int cols, int type, Pointer data)

Samuel

Reply all
Reply to author
Forward
0 new messages