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

asked 2014-12-29 02:31:49 -0500

Shiloh gravatar image

updated 2014-12-29 23:29:53 -0500

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")

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.ion()
          plt.draw()


        if ret:
            gfmask1=cv2.medianBlur(frame,3)
            fgmask = bgsMOG.apply(gfmask1, None, 0.01)
            cv2.imshow('Output', frame)
            key = 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?
edit retag flag offensive close merge delete

Comments

I already edit the program so it can play the next frame, but it's play the video slowly and everytime I want to close the plot it's always error.. The error is "Runtime Error Program: C:\Python27\pythonw.exe This application has requested the Runtime to terminate it in an unusual way".. How I can fix these?

Shiloh gravatar imageShiloh ( 2014-12-29 23:33:41 -0500 )edit

maybe have a look at the camshift demo ?

berak gravatar imageberak ( 2014-12-30 01:17:22 -0500 )edit

Isn't convert the histogram (frequency counts) to pdf (probability) is by integrate the histogram? In camshift demo part def show_hist(self) I don't see the command to make the pdf...

Shiloh gravatar imageShiloh ( 2015-01-01 00:19:22 -0500 )edit