如何裁剪三角形

问题描述 投票:0回答:1

我工作的一些“面子归化”项目。我所做的到现在是:

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

现在我现在需要做的:我知道所有的地标坐标和所有的三维坐标,所以我要裁剪的2D每个三角形,把它放在了正确的位置上3D通用模型来生成检测到的面部的三维模型。

问题:1。)有没有人知道的方式来裁剪通过了解这三个COORDS一个三角形? 2)什么样的转变我一定要对通用的3D模型使用“复制”裁剪三角其正确的地方?

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

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

enter image description here

现在我只想单独裁剪所有这些三角形。那么,如何可以裁剪三角形(当我知道所有的3 coords)使用从画面和安全它在另一个窗口?

c++ opencv opengl 3d normalization
1个回答
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;
  }
© www.soinside.com 2019 - 2024. All rights reserved.