1

I am trying to show video and it's your own histogram side by side, but my code is not working fine, at least simultaneously:

import cv2
from skimage.io import imread
import numpy as np
import scipy.misc

import matplotlib.pyplot as plt

cap = cv2.VideoCapture('video.mp4') 
count = 0
while(cap.isOpened()):
    ret, frame = cap.read()
    count +=1  

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) 
    gray =  scipy.misc.imresize(gray, 0.45) 

    hist = cv2.calcHist([gray],[0],None,[256],[0,256])

    cv2.imshow('Gray', gray)
    cv2.waitKey(5)
    plt.title("Histogram")

    plt.plot(hist)
    plt.show()

cap.release()
cv2.destroyAllWindows()

How can I do that? I accept any suggestion... My goal is to show two windows (one playing video and another plotting histogram) or just one window with video and histogram side-by-side, maybe with numpy.hstack.

  • 2
    Display with `matplotlib.pyplot.imshow`, and have two figures side by side (see matplotlib docs on how to do that). | Alternately you could let matplotlib render into an image, and then combine everything into a big canvas image... but that's a bit more complex. – Dan Mašek Aug 31 '17 at 00:02
  • You may look at this question: https://stackoverflow.com/questions/44598124/update-frame-in-matplotlib-with-live-camera-preview Instead of showing two video streams you would show the histogram in one of the subplots. – ImportanceOfBeingErnest Aug 31 '17 at 10:49

0 Answers0