Face3d
Detection.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <opencv2/opencv.hpp>
4 #include <iostream>
5 #include <vector>
6 #include "FaceGeometry.hpp"
7 
8 /*
9 This class implements the first part of the pileline: detection of the individual face components
10 According to the paper, the following steps have to be executed:
11 1. Preprocessing
12 2. Extract face region
13 3. Extract facial components
14 */
15 
16 namespace Face3D
17 {
18 
19  void onColorThresholdsTrackbar(int, void*);
20  void onTextureAdjustmentTrackbar(int val, void* ptr);
21  bool isConcave(const cv::Point& a, const cv::Point& b, const cv::Point& c);
22 
24  class Detection
25  {
26  public:
27 
32  Detection(const cv::Mat& front, const cv::Mat& side);
33 
36  {
38  cv::Mat textureFront;
39  cv::Mat textureSide;
40  };
41 
46 
47  private:
49  struct ContourInfo
50  {
51  ContourInfo() : areaOfContour(0.0), cogX(0.0), cogY(0.0){}
52  std::vector<cv::Point> contour;
53  double areaOfContour;
54  double cogX, cogY;
55 
56  bool operator<(const ContourInfo& other)
57  {
58  return areaOfContour>other.areaOfContour;
59  }
60  };
61 
62 
64  cv::Mat getCopyOfOriginal(int imgNr)
65  {
66  cv::Mat tmp;
67  m_Originals[imgNr].copyTo(tmp);
68  return tmp;
69  }
70 
72  void doPreprocessing();
73 
75  void doFaceExtraction();
76 
79 
81  void doFacialComponentsExtractionFront(FaceGeometry& faceGeometry, const std::vector<ContourInfo>& componentContourInfo, const std::vector<ContourInfo>& faceContourInfo);
82 
84  void doFacialComponentsExtractionSide(FaceGeometry& faceGeometry, const std::vector<ContourInfo>& componentContourInfo, const std::vector<ContourInfo>& faceContourInfo);
85 
88 
90  std::vector<size_t> findRegions(const std::vector<std::vector<cv::Point> >& contours, const std::vector<cv::Vec4i>& hierarchy, RegionType regionType);
91 
93  std::vector<ContourInfo> extractContourInfo(const std::vector<std::vector<cv::Point> >& contours, const std::vector<size_t> indices);
94 
96  void doMatchCoordinates();
97 
99  void createTextures();
100 
102  cv::Rect getBoundingBox(const cv::Mat& color);
103 
107  double m_AddTextureBottom = 0;
108  double m_AddTextureTop = 0;
109  void doFaceExtractionGUI();
111  cv::Mat combineVertically(const cv::Mat& a, const cv::Mat& b) const;
112 
113 
115  const size_t frontImgNr = 0;
116  const size_t sideImgNr = 1;
117  const size_t imgSize = 320;
118  std::vector<cv::Mat> m_Originals;
119  std::vector<cv::Mat> m_Preprocessed;
120  std::vector<cv::Mat> m_FaceExtracted;
121  std::vector<cv::Mat> m_FaceMask;
123  std::vector<cv::Mat> m_Textures;
124 
127  cv::Mat m_TexturesGUI;
128 
129 
130  friend void onColorThresholdsTrackbar(int, void*);
131  friend void onTextureAdjustmentTrackbarBottom(int, void*);
132  friend void onTextureAdjustmentTrackbarTop(int, void*);
133  };
134 }
int m_ColorThresValue
Definition: Detection.hpp:105
void createTextures()
Definition: Detection.cpp:447
double m_AddTextureBottom
Definition: Detection.hpp:107
const size_t sideImgNr
index of the side image when both images are stored in an array
Definition: Detection.hpp:116
void doFaceExtraction()
Definition: Detection.cpp:60
cv::Mat getCopyOfOriginal(int imgNr)
Definition: Detection.hpp:64
void doPreprocessing()
Definition: Detection.cpp:49
Definition: Detection.hpp:35
Definition: FaceGeometry.hpp:8
FaceGeometry faceGeometry
Definition: Detection.hpp:37
std::vector< cv::Mat > m_Originals
original images (scaled down)
Definition: Detection.hpp:118
friend void onTextureAdjustmentTrackbarBottom(int, void *)
Definition: Detection.cpp:614
void doMatchCoordinates()
Definition: Detection.cpp:440
cv::Rect getBoundingBox(const cv::Mat &color)
Definition: Detection.cpp:558
Definition: Detection.hpp:87
cv::Mat combineVertically(const cv::Mat &a, const cv::Mat &b) const
Definition: Detection.cpp:574
cv::Mat textureFront
Definition: Detection.hpp:38
std::vector< cv::Mat > m_FaceExtracted
binary image with skin as foreground
Definition: Detection.hpp:120
void onTextureAdjustmentTrackbar(int val, void *ptr)
friend void onColorThresholdsTrackbar(int, void *)
Definition: Detection.cpp:587
double cogY
Definition: Detection.hpp:54
FaceGeometry m_FaceGeometry
Definition: Detection.hpp:122
std::vector< ContourInfo > extractContourInfo(const std::vector< std::vector< cv::Point > > &contours, const std::vector< size_t > indices)
Definition: Detection.cpp:415
cv::Mat textureSide
Definition: Detection.hpp:39
cv::Mat m_TexturesGUI
Definition: Detection.hpp:127
Definition: Detection.hpp:87
const size_t imgSize
size of the images we are working with. 320x320 seems good as its fast but has still enough details ...
Definition: Detection.hpp:117
const size_t frontImgNr
index of the front image when both images are stored in an array
Definition: Detection.hpp:115
RegionType
Definition: Detection.hpp:87
cv::Mat m_FacialPointsGUI
Definition: Detection.hpp:126
Definition: Detection.hpp:49
std::vector< cv::Mat > m_FaceMask
mask of the face regions. foreground regions which are not the face are already removed ...
Definition: Detection.hpp:121
int m_OffsetCB
Definition: Detection.hpp:106
void doFaceExtractionGUI()
Definition: Detection.cpp:598
ContourInfo()
Definition: Detection.hpp:51
void createTexturesAndShowResultsGUI()
Definition: Detection.cpp:635
FaceGeometry m_FaceGeometryBackup
the geometry of the face, i.e. the coordinates of the facial components
Definition: Detection.hpp:122
Definition: Detection.hpp:24
std::vector< cv::Mat > m_Preprocessed
preprocessed images (smooth)
Definition: Detection.hpp:119
bool isConcave(const cv::Point &a, const cv::Point &b, const cv::Point &c)
Definition: Detection.cpp:258
void onColorThresholdsTrackbar(int val, void *ptr)
Definition: Detection.cpp:587
std::vector< cv::Point > contour
Definition: Detection.hpp:52
int m_OffsetCR
Definition: Detection.hpp:106
bool operator<(const ContourInfo &other)
Definition: Detection.hpp:56
std::vector< cv::Mat > m_Textures
the textures, already in a format that can be used in OpenGL
Definition: Detection.hpp:123
double m_AddTextureTop
Definition: Detection.hpp:108
void doFacialComponentsExtraction()
Definition: Detection.cpp:105
void doFacialComponentsExtractionFront(FaceGeometry &faceGeometry, const std::vector< ContourInfo > &componentContourInfo, const std::vector< ContourInfo > &faceContourInfo)
Definition: Detection.cpp:171
std::vector< size_t > findRegions(const std::vector< std::vector< cv::Point > > &contours, const std::vector< cv::Vec4i > &hierarchy, RegionType regionType)
Definition: Detection.cpp:387
void doFacialComponentsExtractionSide(FaceGeometry &faceGeometry, const std::vector< ContourInfo > &componentContourInfo, const std::vector< ContourInfo > &faceContourInfo)
Definition: Detection.cpp:274
double areaOfContour
Definition: Detection.hpp:53
Definition: Common.hpp:7
friend void onTextureAdjustmentTrackbarTop(int, void *)
Definition: Detection.cpp:624
DetectFaceResult detectFace()
calculate the face geometry and the textures
Definition: Detection.cpp:30
Detection(const cv::Mat &front, const cv::Mat &side)
create a Detection object
Definition: Detection.cpp:12