Algorithm
- Save the reference frame(in gray scale and saturation scale) at the beginning of the video
- Convert other coming frames to gray scale and also hsv channels
- Compare each new frame with the reference frame in saturation and gray scale
- If absolute value differences bigger than 25 than mark the pixel and save in a new Mat
- Then erode + dilate to this frame (2 times)
- Check non-zero pixels in gray channel domain and mark them for result image
- Remained zero pixels in Step-6 check in saturation domain and mark them in result image
- If still remained zero pixels which means they belong to background, you can make replace them with the desired background
Requirements:
- At the beginning camera should take a reference frame so you shouldnt be in front of camera
- Camera should be constant