Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to find pdf from color histogram and how to play the next frame?

I want to apply the particle filter for tracking.. My friend said that I need to find the pdf of color histogram of the video first as a model state.. I already try with these code to show the plot

import cv2
import matplotlib.pyplot as plt
bgsMOG = cv2.BackgroundSubtractorMOG2()
cap    = cv2.VideoCapture("d:\MOV_5702.avi")    
color=('b','g','r')

if cap:
    while True:
        ret, frame = cap.read()
        for i,col in enumerate(color):
          hist       = cv2.calcHist([frame],[i],None,[256],[0,256])
          plt.plot(hist,color=col)
          plt.xlim([0,256])              

        if ret:
            gfmask1=cv2.medianBlur(frame,3)
            fgmask = bgsMOG.apply(gfmask1, None, 0.01)
            cv2.imshow('Output', frame)
            plt.show()
            key = cv2.waitKey(400)
            if key == ord('q'):
                break
cap.release()
cv2.destroyAllWindows()

My question is:

  1. In the paper I read there's only 1 pdf plot, is bgr histogram produce 1 pdf? If yes, how I can do that? If no, am I just used one channel from bgr?
  2. The code won't play the next frame, how I can fix it?

How to find pdf from color histogram and how to play the next frame?

I want to apply the particle filter for tracking.. My friend said that I need to find the pdf of color histogram of the video first as a model state.. I already try with these code to show the plot

import cv2
import matplotlib.pyplot as plt
from matplotlib.pylab import subplots
bgsMOG = cv2.BackgroundSubtractorMOG2()
cap    = cv2.VideoCapture("d:\MOV_5702.avi")    cv2.VideoCapture("d:\MOV_5702.avi")

color=('b','g','r')
 if cap:
    while True:
        ret, frame = cap.read()
        for i,col in enumerate(color):
          hist       = cv2.calcHist([frame],[i],None,[256],[0,256])
          plt.plot(hist,color=col)
          plt.xlim([0,256])              plt.xlim([0,256])
          plt.ion()
          plt.draw()


        if ret:
            gfmask1=cv2.medianBlur(frame,3)
            fgmask = bgsMOG.apply(gfmask1, None, 0.01)
            cv2.imshow('Output', frame)
            plt.show()
            key = cv2.waitKey(400)
cv2.waitKey(1)
            if key == ord('q'):
                break
cap.release()
cv2.destroyAllWindows()

My question is:

  1. In the paper I read there's only 1 pdf plot, is bgr histogram produce 1 pdf? If yes, how I can do that? If no, am I just used one channel from bgr?
  2. The code won't play the next frame, how I can fix it?