How to cut out color image of contoured human body?


I want to make a color image of the background transparent by extracting the outline to the human body using the web camera or kinect.

Then, copy the masked color image and make A and B. When A moves in front of the camera, B wants to express like an afterimage that follows A with a little delay.

With reference to below topic, we tried to extract contours from the background difference by the web camera, but there was a limit to the adjustment of the threshold if it was a color image of the web camera, and the outline could not be extracted cleanly.

By using the infrared image of the kinectv2 as a source, contour extraction could be made clean, but when applying masks made from infrared images to color images, the resolution and field of view of the source and the like are different, so that the coordinates are mapped I do not know how.

I saw the source of registration but it was difficult to understand, I want a sample code.

Thanks in advance.

reference topic

development environment
Mac OSX El Capitan
oF 0.9.3 Xcode 7.2.1

Hi, wow that is an old post! Like I mention in that thread, I ended up solving my problem by resampling the contour, as per Zachs suggestion. The addon that I wrote at the time and used for this is here
but since then, most of that functionality has been included in ofPolyline.

I’m afraid I don’t fully understand what it is you’re trying to do. Do you want just the person without a background, so that you can put them in a different background? Kind of like a photo-booth effect? If so, a background subtraction should be quite good (note that the background subtraction will modify the pixels of the person too, so you’ll need to use it as a mask on the original color image. Also you will probably get holes where the person has pixels which are similar to the background, so you will need to fill in the contour holes.

Using a kinect is a much simpler solution. with a threshold on the depth. however, the edges will be very noisey and jaggeddy, but you can smooth that using ofPolyline’s smoothing functions. Like you said you will need to align the depth image with the color image, and as far as I remember ofxKinect may have that functionality built in.

hope that helps!

Hi, @memo Thank you for explaining it.
Yes, I just want to do king of like a photo-booth chroma key effect.
About filling in the contour holes, Can it be solved by dilate()?

grayDiff.absDiff(grayBg, grayImage);
contour.findContours(grayDiff, 100, 9999999, 40, false, false);

But, this did not work.