Nirkin Face Segmentation  0.9.0
Deep face segmentation based on fully connected convolutional neural network.
face_seg.h
1 #ifndef FACE_SEG_FACE_SEG_H
2 #define FACE_SEG_FACE_SEG_H
3 
4 // std
5 #include <string>
6 
7 // OpenCV
8 #include <opencv2/core.hpp>
9 
10 // Caffe
11 #include <caffe/caffe.hpp>
12 
13 namespace face_seg
14 {
18  class FaceSeg
19  {
20  public:
27  FaceSeg(const std::string& deploy_file, const std::string& model_file,
28  bool with_gpu = true, int gpu_device_id = 0);
29 
30  ~FaceSeg();
31 
37  cv::Mat process(const cv::Mat& img);
38 
39  private:
40 
47  void wrapInputLayer(std::vector<cv::Mat>& input_channels);
48 
53  void preprocess(const cv::Mat& img, std::vector<cv::Mat>& input_channels);
54 
58  void subtractMean_c3(cv::Mat& img);
59 
60  protected:
61  std::shared_ptr<caffe::Net<float>> m_net;
62  int m_num_channels;
63  cv::Size m_input_size;
64  bool m_with_gpu;
65 
66  // Mean pixel color
67  const float MB = 104.00699f, MG = 116.66877f, MR = 122.67892f;
68  };
69 
70 } // namespace face_seg
71 
72 #endif // FACE_SEG_FACE_SEG_H
Definition: face_seg.h:13
This class provided deep face segmentation using Caffe with a fully connected convolutional neural ne...
Definition: face_seg.h:18
cv::Mat process(const cv::Mat &img)
Do face segmentation.
FaceSeg(const std::string &deploy_file, const std::string &model_file, bool with_gpu=true, int gpu_device_id=0)
Construct FaceSeg instance.