Opencv: How to fit an image into a non-rectangular outline?

I want to fit the image of a clown as a face into the contour of another person (person). I detect the face of the face and get an elliptical outline. I can determine the center, radius, highest, lowest, left and right.

How do I match a clown’s face (a square image that I can make elliptical by cutting out a face from an empty png background and then detecting an outline) on the face of the face?

Or at least how can I put a polygon in another polygon.

I easily place a rectangular image in a rectangular outline, but faces do not have this shape.

Python is preferable, but C ++ is manageable too, thanks.

Edit: visual representation on request:

I have

and I want to do it like this:

, .

+4
2

, , , Active Appearance Models. -, (, ), . . , , .

AAM, , , , .

+1

, , (), 4 .

, fitEllipse(), 4 . , , , - , , .

:

vector<Point> contour;
// Do whatever you are doing to populate this vector

RotatedRect ellipse = fitEllipse(Mat(contour));

, RotatedRect.

// Resize your mask with these sizes for optimum fit
ellipse.size.width
ellipse.size.height

.

UPDATE:

, , , , , .

0

Source: https://habr.com/ru/post/1607852/


All Articles