12

I would like to extract the silhouette of a human in a photo and remove the background. The photo could be taken of the full body, only the upper body or only the lower body.

What I have done so far is track the face using Haar Cascades, but the algorithm I use does a rectangle over the face and I would need the shape of all the body. I have tried HOG as well, but as well it gives me a rectangle and it doesn't work with all photos.

It would be great if somebody could help me. I'm using OpenCV and C++.

Ilmari Karonen
  • 44,762
  • 9
  • 83
  • 142
mapetilan
  • 151
  • 1
  • 5

1 Answers1

7

You can try the GrabCut or GraphCut algorithms (At least grabcut is present in OpenCV).

You tell them the rectangle (where the body is), and they do the best to cut the object inside. It's not fast, nor perfect, but you'll have a hard time trying to find something better.

This is an open research field, so if your images do not get cut as you want, prepare yourself for some years of post-PhD research to find better algorithms :)

Sam
  • 18,653
  • 4
  • 53
  • 78
  • 3
    Just for completeness, GraphCut isn't a silhouete detection, but a background segmentation alghorithm. Instead of training the computer to find a person, what would be extremely difficult, it uses the background information to extract the foreground. It's not designed to classify the foreground as a person or any other object, but if you garantee that the foreground IS a person in your input data, you have detected it's silhouete. – Ian Medeiros Dec 13 '11 at 13:28
  • Hi Ian, thanks for your help. I have already tried this algorithm. But the problem is when I use it, it does strange things. For example, if I select the person it does a segmentation tacking some parts of the body and some parts of the environment. Anyway I will try to change some of the parameters and see if I can get a better result.Thanks again. Miguel – mapetilan Dec 13 '11 at 19:04
  • 1
    If you are going for the background segmentation aproach, I think that GraphCut is an overkill, it's not designed to be used on real time applications (maybe with a GPU implementation). I've never used this alghorithm, but saw a friend of mine performing a performance analysis on it and concluded that a simple background substraction plus some erode/dilation alghorithm suffices in most cases. – Ian Medeiros Dec 14 '11 at 15:32