I have a trained face recognizer.
After doing face_recognizer.getHistograms() I want to show them.
How can I do this?
Thanks ahead!
2 Answers
To plot histogram of an image, use you use pyplot.hist:
If you're image is in grayscale where gray scale intensities vary from 0 to 255, use:
from matplotlib import pyplot as plt
plt.hist(img.ravel(), 256, [0,256])
If it's a color image, you can also use opencv's calcHist function:
color = ('b', 'g', 'r')
for i,col in enumerate(color):
    histr = cv2.calcHist([img],[i],None,[256],[0,256])
    plt.plot(histr,color = col)
    plt.xlim([0,256])
The image intensity of each channel should be between [0, 255]
8 Comments
Yotam Hammer
 I saw that function but I dont want to use it on an image. I want to show the histogram directly. Given a histogram as a numpy array - how can I show it?
  Mohit Motwani
 Which function do you not want to use?
  Yotam Hammer
 I have an pre-made histogram and I just want to show it. The pyplot.hist function shows a histogram of a given image. What I want is just to show an histogram without gibing the function the image itself.
  Mohit Motwani
 Use plt.plot then
  Yotam Hammer
 plt.plot(histogram), plt.show() does not work. It just creates an empty window with x and y axis
   | 
 It's possible to simulate histogram collection via opencv using the OpenCV-Flow online tool.
See results here:
1 Comment
Christoph Rackwitz
 interesting web app!
  