Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Occlusion handling with Camshift algorithm

I am working on object tracking by camshift algorithm. For the time being i am using the inbuilt opencv code wherein i have trouble dealing with occlusion.

 hsv = cv2.cvtColor(self.frame, cv2.COLOR_BGR2HSV)
 mask = cv2.inRange(hsv, np.array((0., 60., 32.)), np.array((180., 255., 255.)))
 prob = cv2.calcBackProject([hsv], [0], self.hist, [0, 180], 1)
 cv2.imshow('prob_0',prob)
 prob &= mask
 cv2.imshow('prob',prob)
 term_crit = ( cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 1 )
 track_box, self.track_window = cv2.CamShift(prob, self.track_window, term_crit)

My problem is that in this code when my object which is a red ball goes out of the field of vision of the camera or if i cover some portion of the ball with my hand , then it crashes and give the error that:

track_box, self.track_window = cv2.CamShift(prob, self.track_window, term_crit)
error: ..\..\..\..\opencv\modules\video\src\camshift.cpp:80: error: (-5) Input           
window has non-positive sizes in function cvMeanShift

This is because my parameter to cv2.Camshift -> which is "prob" is not having any values corresponding to my ball.(prob is the binary image obtained which consists of the thresholded ball)

I have one idea for dealing with occlusion in this scenario.It's that i'll store the ball matrix in a global variable and if my camera's current frame cannot obtain the ball matrix then it should use the global variable instead of it till it doesn't find and track the ball. So how to apply this logic in the given code..?

So can anyone help me how to deal with the occlusion in this ball situation. Please...Urgent...thanks.!!