How to find pdf from color histogram and how to play the next frame? [closed]
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:
- 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?
- The code won't play the next frame, how I can fix it?
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?
maybe have a look at the camshift demo ?
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...