I need to develop an algorithm to remove a background from the foreground image. I would like to use chroma keying. This will be done on a live camera stream and I need to do it using OpenCV in C++.
The algorithm I thought would be something like:
- Capture frame from webcam into matrix
- Compute 3d rgb space graph
- The points around a certain value e.g. (10,255,10) for green background.
- Convert all points around green region to 0.
- And the rest to 1.
- Multiply that with the original image (convolution)
- Should get rid of background.
I would like some help on a method to remove a plain color background from foreground image without the color from the foreground image being removed.
Is there like a special type of crop function to remove background?