2015-11-06 130 views
0

我正在做一些“Face Normalization”项目。 我所做的到现在是:如何裁剪一个三角形

  1. 人脸检测
  2. 面部标志检测(68)
  3. 斯普利特面对的是通过连接多个标记(德劳内三角化 - > AAM)的几个三角形
  4. 创建一个通用的脸的一些3D模型(包括68(同地标)点),3D和也做了一些Delaunay三角

现在我现在需要做的: 我知道所有Landmark坐标和所有3D坐标,因此我想在2D中裁剪每个三角形,并将其放在3D通用模型的正确位置上以生成检测到的面部的3D模型。

问题: 1.)有没有人知道一种方法通过了解所有三个coords来裁剪单个三角形? 2.)我有什么样的转换来将复制的三角形“复制”在通用3D模型的正确位置上?

我编程在C++中,把DLIB和OpenCV的面部标志检测,并在3D方面,我用OpenGL

工作

编辑: 也许是更好地“看”的问题。这就是我已经

enter image description here

,现在我只想seperatly裁剪所有这些三角形。那么,我怎样才能从一张图片中裁剪出一个三角形(当我知道所有3个坐标的时候)并在另一个窗口中安全呢?

回答

0

为了裁剪一个三角形,我们需要使用warpaffine方法。

http://docs.opencv.org/2.4/doc/tutorials/imgproc/imgtrans/warp_affine/warp_affine.html

#include "opencv2/highgui/highgui.hpp" 
#include "opencv2/imgproc/imgproc.hpp" 
#include <iostream> 
#include <stdio.h> 

using namespace cv; 
using namespace std; 

/// Global variables 
char* source_window = "Source image"; 
char* warp_window = "Warp"; 
char* warp_rotate_window = "Warp + Rotate"; 

/** @function main */ 
int main(int argc, char** argv) 
{ 
    Point2f srcTri[3]; 
    Point2f dstTri[3]; 

    Mat rot_mat(2, 3, CV_32FC1); 
    Mat warp_mat(2, 3, CV_32FC1); 
    Mat src, warp_dst, warp_rotate_dst; 

    /// Load the image 
    src = imread(argv[1], 1); 

    /// Set the dst image the same type and size as src 
    warp_dst = Mat::zeros(src.rows, src.cols, src.type()); 

    /// Set your 3 points to calculate the Affine Transform 
    srcTri[0] = Point2f(0,0); 
    srcTri[1] = Point2f(src.cols - 1, 0); 
    srcTri[2] = Point2f(0, src.rows - 1); 

    dstTri[0] = Point2f(src.cols*0.0, src.rows*0.33); 
    dstTri[1] = Point2f(src.cols*0.85, src.rows*0.25); 
    dstTri[2] = Point2f(src.cols*0.15, src.rows*0.7); 

    /// Get the Affine Transform 
    warp_mat = getAffineTransform(srcTri, dstTri); 

    /// Apply the Affine Transform just found to the src image 
    warpAffine(src, warp_dst, warp_mat, warp_dst.size()); 

    /** Rotating the image after Warp */ 

    /// Compute a rotation matrix with respect to the center of the image 
    Point center = Point(warp_dst.cols/2, warp_dst.rows/2); 
    double angle = -50.0; 
    double scale = 0.6; 

    /// Get the rotation matrix with the specifications above 
    rot_mat = getRotationMatrix2D(center, angle, scale); 

    /// Rotate the warped image 
    warpAffine(warp_dst, warp_rotate_dst, rot_mat, warp_dst.size()); 

    /// Show what you got 
    namedWindow(source_window, CV_WINDOW_AUTOSIZE); 
    imshow(source_window, src); 

    namedWindow(warp_window, CV_WINDOW_AUTOSIZE); 
    imshow(warp_window, warp_dst); 

    namedWindow(warp_rotate_window, CV_WINDOW_AUTOSIZE); 
    imshow(warp_rotate_window, warp_rotate_dst); 

    /// Wait until user exits the program 
    waitKey(0); 

    return 0; 
    } 
+0

感谢您的帮助,现在,但它是我这个梅索德不理解,还是你明白我的问题错了吗? –

+1

请编辑您的问题以添加更多详情。 –