title: How can I save a OpenCV histogram to a file in Python?
body: <p>I'd like to save a calculated histogram from a file so that I can reopen it without having to recompute it, but I'm not sure how I would go about saving and then reading it again. </p>
  
  <pre><code>image_path = "/Users/..../test.jpg"
  image = cv2.imread(image_path, 0)
  if image is not None: 
      hist = cv2.calcHist([image], [0], None, [256], [0, 256])
      cv2.imwrite("/Users/.../hist.jpg", hist) # What should this be?
  
  hist = cv2.imread("/Users/.../hist.jpg", 0) # And this?
  </code></pre>
  
  <p>EDIT: 
  So I'd like to do something like this, but I'm not sure what the syntax would be.</p>
  
  <pre><code>with open('hist.txt', 'a') as fp:
      fp.write('%s %s %s', [hist_id, list(hist), color])
  with open('hist.txt', 'r') as fp:
      lines = fp.readlines()
      for line in lines: 
          hist_id = line[0]
          hist = np.array(eval(line[1]))
          color = line[2]
          cv2.compare(hist.....) 
  </code></pre>
  
  <p>EDIT 2:</p>
  
  <pre><code>new_entry = [image, list(hist1), list(hist2)]
  for item in new_entry:
      fd.write("%s\t" % item)
  fd.write("\n")
  
  with open('hist.txt', 'r') as fd:
       lines = fd.readlines()
       for line in lines:
           line = line.split('\t')
           cv2.compareHist(numpy.array(line[1]), numpy.array(line[2]))
  </code></pre>