I working with open cv and dlib c++ library for android application.
To align detected face I am using code from this post:
public static Bitmap warp(Bitmap originPhoto, List<Point> topCorners) {
    int resultWidth = 600;
    int resultHeight = 600;
    Mat inputMat = new Mat(originPhoto.getHeight(), originPhoto.getHeight(), CvType.CV_8UC1);
    Utils.bitmapToMat(originPhoto, inputMat);
    Mat outputMat = new Mat(resultWidth, resultHeight, CvType.CV_8UC1);
    Mat startM = Converters.vector_Point2f_to_Mat(topCorners);
    Point ocvPOut1 = new Point(0, 0);
    Point ocvPOut2 = new Point(resultWidth, 0);
    Point ocvPOut3 = new Point(0, resultHeight);
    Point ocvPOut4 = new Point(resultWidth, resultHeight);
    List<Point> dest = new ArrayList<>();
    dest.add(ocvPOut1);
    dest.add(ocvPOut2);
    dest.add(ocvPOut4);
    dest.add(ocvPOut3);
    Mat endM = Converters.vector_Point2f_to_Mat(dest);
    MatOfPoint2f matOfPoint2fStart = new MatOfPoint2f(startM);
    MatOfPoint2f matOfPoint2fEnd = new MatOfPoint2f(endM);
    Mat perspectiveTransform = Calib3d.findHomography(matOfPoint2fStart, matOfPoint2fEnd);
    Imgproc.warpPerspective(inputMat, outputMat, perspectiveTransform, new Size(resultWidth, resultHeight));
    Bitmap output = Bitmap.createBitmap(resultWidth, resultHeight, Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(outputMat, output);
    return output;
}
This code successfully cuts out the face but not align. I know I can rotate bitmap something like this:
    Matrix matrix = new Matrix();
    matrix.postRotate(angle);
    Bitmap rotatedBitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
But it's not cool. How can I align detected face using this libraries?