使用dlib在图像上应用仿射变换



我希望使用dlib检测器学习的68个界标来对齐两张人脸图像。我知道我可以将图像转换为OpenCV Mat,然后使用warpAffine方法。我有一些内存泄漏,决定看看是否可以只使用dlib。我注意到dlib库在geometry.h中有一些用于此目的的方法。

为此,我使用find_affine_transform方法来获得point_transform_affine对象,其中我找到使用形状和模板获得的3个点之间的仿射变换。在文档中,我们可以使用这个对象对点的向量应用变换。然而,我一直找不到一些例子

  1. 你能告诉我如何应用所学的转换吗
  2. 其次,我在array2d对象中加载了一个图像。有没有一种方法可以从数组2d到点的向量

下面列出了find_affine_transform的一些初始代码。

std::vector<dlib::vector<double,2>> TemplateLandmarks;
std::vector<dlib::vector<double,2>> ObtainedLandmarks;
// push_back the specific coordinates in the above vectors
array2d<bgr_pixel> img; 
// read the image from a file path using load_image
//  learning the best transformation map
point_transform_affine H = find_affine_transform ( ObtainedLandmarks , TemplateLandmarks );

这可以使用dlib中的extract_image_chips函数来完成。在面平面标记示例程序中甚至有一个使用它来对齐面的示例。

最新更新