face_video_segment  0.8
Adaptation of The Video Segmentation Project for face segmentation.
landmarks_unit.h
1 // Copyright (c) 2010-2014, The Video Segmentation Project
2 // All rights reserved.
3 
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of the The Video Segmentation Project nor the
12 // names of its contributors may be used to endorse or promote products
13 // derived from this software without specific prior written permission.
14 
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 //
27 // ---
28 
29 #ifndef FACE_VIDEO_SEGMENT_VIDEO_LANDMARKS_UNIT_H__
30 #define FACE_VIDEO_SEGMENT_VIDEO_LANDMARKS_UNIT_H__
31 
32 #include "base/base.h"
33 #include "video_framework/video_unit.h"
34 #include <sfl/sequence_face_landmarks.h>
35 #include <sfl/utilities.h>
36 #include <opencv2/core.hpp>
37 
38 namespace segmentation {
39 
41  std::string stream_name = "LandmarksStream";
42  std::string video_stream_name = "VideoStream";
43  std::string landmarks_path = "";
44  float frame_scale = 1.0f;
45  sfl::FaceTrackingType tracking = sfl::TRACKING_BRISK;
46  };
47 
50  class LandmarksUnit : public video_framework::VideoUnit {
51  public:
52  LandmarksUnit(const LandmarksOptions& options);
53  ~LandmarksUnit();
54 
55  LandmarksUnit(const LandmarksUnit&) = delete;
56  LandmarksUnit& operator=(const LandmarksUnit&) = delete;
57 
58  virtual bool OpenStreams(video_framework::StreamSet* set);
59  virtual void ProcessFrame(video_framework::FrameSetPtr input, std::list<video_framework::FrameSetPtr>* output);
60  virtual bool PostProcess(std::list<video_framework::FrameSetPtr>* append);
61 
62  private:
63  LandmarksOptions options_;
64  std::shared_ptr<sfl::SequenceFaceLandmarks> sfl_;
65  std::list<std::unique_ptr<sfl::Frame>>::const_iterator sequence_it;
66 
67  int video_stream_idx_;
68  int frame_width_;
69  int frame_height_;
70  int main_face_id_;
71  };
72 
74  //std::string stream_name = "LandmarksRendererStream";
75  std::string video_stream_name = "VideoStream";
76  std::string landmarks_stream_name = "LandmarksStream";
77  };
78 
81  class LandmarksRendererUnit : public video_framework::VideoUnit
82  {
83  public:
86 
88  LandmarksRendererUnit& operator=(const LandmarksRendererUnit&) = delete;
89 
90  virtual bool OpenStreams(video_framework::StreamSet* set);
91  virtual void ProcessFrame(video_framework::FrameSetPtr input, std::list<video_framework::FrameSetPtr>* output);
92  virtual bool PostProcess(std::list<video_framework::FrameSetPtr>* append);
93 
94  private:
95  LandmarksRendererOptions options_;
96  int video_stream_idx_;
97  int landmarks_stream_idx_;
98 
99  int frame_width;
100  int frame_height;
101  int frame_num_ = 0;
102 
103  };
104 
105 } // namespace segmentation
106 
107 #endif // FACE_VIDEO_SEGMENT_VIDEO_LANDMARKS_UNIT_H__
Definition: landmarks_unit.cpp:49
Calculates face landmarks in video frames from stream.
Definition: landmarks_unit.h:50
Renders face landmarks from stream.
Definition: landmarks_unit.h:81
Definition: landmarks_unit.h:40
Definition: landmarks_unit.h:73