Please see the following blog post for more details about this code
Warp one triangle to another using OpenCV ( C++ / Python )