我使用open cv和dlib c ++库来安装android应用程序。
要对齐检测到的面部,我正在使用代码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;
}
此代码成功切出了脸但未对齐。我知道我可以像这样旋转位图:
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.如何使用此库对齐检测到的面部?