Ask Your Question

Revision history [back]

how to save histogram in python?

Hello , I get my hist by the following code ,and I want to save the result to file or database so next time I can load it without re-computing.I have tried python's pickle dumps and josn but they will not work. Is anyone knows how to do it? thanks a lot!

hsv = cv.CreateImage(cv.GetSize(src), 8, 3)
hplane = cv.CreateImage(cv.GetSize(src), 8, 1)
splane = cv.CreateImage(cv.GetSize(src), 8, 1)
vplane = cv.CreateImage(cv.GetSize(src), 8, 1)
planes = [hplane, splane]
cv.CvtColor(src, hsv, cv.CV_BGR2HSV)
cv.Split(hsv, hplane, splane, vplane, None)
hist = cv.CreateHist((h_bins, s_bins), cv.CV_HIST_ARRAY,
        ranges=((0, 180), (0, 255)), uniform=True)
cv.CalcHist(planes, hist)  # compute histogram
cv.NormalizeHist(hist, 1.0)  #  how can i save it ?
click to hide/show revision 2
retagged

updated 2015-09-10 04:49:13 -0500

berak gravatar image

how to save histogram in python?

Hello , I get my hist by the following code ,and I want to save the result to file or database so next time I can load it without re-computing.I have tried python's pickle dumps and josn but they will not work. Is anyone knows how to do it? thanks a lot!

hsv = cv.CreateImage(cv.GetSize(src), 8, 3)
hplane = cv.CreateImage(cv.GetSize(src), 8, 1)
splane = cv.CreateImage(cv.GetSize(src), 8, 1)
vplane = cv.CreateImage(cv.GetSize(src), 8, 1)
planes = [hplane, splane]
cv.CvtColor(src, hsv, cv.CV_BGR2HSV)
cv.Split(hsv, hplane, splane, vplane, None)
hist = cv.CreateHist((h_bins, s_bins), cv.CV_HIST_ARRAY,
        ranges=((0, 180), (0, 255)), uniform=True)
cv.CalcHist(planes, hist)  # compute histogram
cv.NormalizeHist(hist, 1.0)  #  how can i save it ?