how to save histogram in python?

asked 2015-09-09 21:40:49 -0500

kakuka gravatar image

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

berak gravatar image

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 ?
edit retag flag offensive close merge delete

Comments

please do not use the deprecated cv api (already removed in opencv3), but the newer cv2 one.

with cv2, your histogram would be a numpy array, which is quite easy to serialize.

here are some tutorials

berak gravatar imageberak ( 2015-09-10 00:49:45 -0500 )edit