Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencv: How to Fit an Image into Non-Rectangular Contour?

Tags:

opencv

contour

I want to fit an image of a clown like face into a contour of another face (a person). I am detecting the persons face and getting a elliptical-like contour. I can figure out the center, radius, highest, lowest, left-most and right-most points.

How do I fit the clown face (a square image which I can make elliptical by cutting the face out of the empty background of a png and then detecting the contour) into the persons face?

Or at the least, how do I fit a polygon into another polygon.

I can fit a rectangular image into a rectangular contour with ease, but faces aren't that shape.

Python preferable, but C++ is also manageable, thank you.

Edit: Visual representation as requested:

I have

and I want to make it like this:

but I want the clown face to stretch over the guys face and fit within the blue contour.

like image 276
azazelspeaks Avatar asked Nov 09 '22 05:11

azazelspeaks


1 Answers

I think the keyword you are looking for is Active Appearance Models. First, you need to fit a model to first face (such as this one), which lays inside the contour. Then, you should fit the same model to the clown face. After that, since you have fitted same model to both faces, you can stretch it as you need.

I haven't use AAM myself and I'm not an expert about it, so my explanation might not be enough or might not be exactly correct, but I'm sure it will give you some insight.

like image 82
guneykayim Avatar answered Nov 15 '22 13:11

guneykayim