Search code examples
androidopencvtextures

How to fill a polygon with image OpenCV


My polygon has 4 angles, but it is not a rectangle. It is some convex polygon which shape is constantly changing. With Core.fillConvexPoly you can fill it with color. I would like to place there some image. So that it will be textured.

I am using OpenVC for Android. Does anyone have any insight?

Thank you!

-epsilon


Solution

  • you first need to find transformation matrix that projects your texture corners

    {(0,0), (w,0), (w,h), (0,h)}

    to corresponding polygon corners by using getPerspectiveTransform;

    and then use warpPerspective to fit the texture into your polygon.