Occlusion handling with Camshift algorithm [closed]

asked 2014-07-30 13:08:11 -0600

user6789 gravatar image

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.!!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-04 09:28:14.245569

Comments

Use a Kalman filter and his predict function. That is exactly what you need!

StevenPuttemans gravatar imageStevenPuttemans ( 2014-07-31 03:05:13 -0600 )edit

oh thank you..!!! i just stumbled upon it too.. any references for implementing it..??? cause i found it pretty confusing..!! thanks!

user6789 gravatar imageuser6789 ( 2014-07-31 09:10:28 -0600 )edit