face_video_segment  0.8
Adaptation of The Video Segmentation Project for face segmentation.
face_segmentation_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_FACE_SEGMENTATION_UNIT_H__
30 #define FACE_VIDEO_SEGMENT_FACE_SEGMENTATION_UNIT_H__
31 
32 #include "base/base.h"
33 #include "video_framework/video_unit.h"
34 #include "segment_util/segmentation_util.h"
35 #include "face_regions.h"
36 
37 namespace fvs
38 {
39  using namespace segmentation;
40 
42  std::string stream_name = "FaceRegionsStream";
43  };
44 
47  class FaceRegionsReaderUnit : public video_framework::VideoUnit
48  {
49  public:
51  const std::string& fvs_path);
53 
55  FaceRegionsReaderUnit& operator=(const FaceRegionsReaderUnit&) = delete;
56 
57  virtual bool OpenStreams(video_framework::StreamSet* set);
58  virtual void ProcessFrame(video_framework::FrameSetPtr input, std::list<video_framework::FrameSetPtr>* output);
59  virtual bool PostProcess(std::list<video_framework::FrameSetPtr>* append);
60 
61  private:
62  FaceRegionsReaderOptions options_;
63  std::unique_ptr<Sequence> fvs_sequence_;
64  int frame_number_ = 0;
65  };
66 
68  std::string stream_name = "FaceRegionsStream";
69  std::string video_stream_name = "VideoStream";
70  std::string segment_stream_name = "SegmentationStream";
71  std::string landmarks_stream_name = "LandmarksStream";
72  std::string video_path = "";
73  std::string seg_path = "";
74  std::string landmarks_path = "";
75  };
76 
79  class FaceRegionsUnit : public video_framework::VideoUnit
80  {
81  public:
82  FaceRegionsUnit(const FaceRegionsOptions& options);
83  ~FaceRegionsUnit();
84 
85  FaceRegionsUnit(const FaceRegionsUnit&) = delete;
86  FaceRegionsUnit& operator=(const FaceRegionsUnit&) = delete;
87 
88  virtual bool OpenStreams(video_framework::StreamSet* set);
89  virtual void ProcessFrame(video_framework::FrameSetPtr input, std::list<video_framework::FrameSetPtr>* output);
90  virtual bool PostProcess(std::list<video_framework::FrameSetPtr>* append);
91 
94  virtual void save(const std::string& filePath) const;
95 
96  private:
97  FaceRegionsOptions options_;
98  int video_stream_idx_;
99  int landmarks_stream_idx_;
100  int seg_stream_idx_;
101 
102  int frame_width_;
103  int frame_height_;
104  int frame_number_ = 0;
105 
106  std::unique_ptr<FaceRegions> face_regions_;
107  std::unique_ptr<Sequence> m_fvs_sequence;
108  };
109 
110 } // namespace fvs
111 
112 #endif // FACE_VIDEO_SEGMENT_FACE_SEGMENTATION_UNIT_H__
Reads face regions from file into stream.
Definition: face_segmentation_unit.h:47
Definition: landmarks_unit.cpp:49
Definition: face_segmentation_unit.h:67
Definition: face_segmentation_unit.h:41
Definition: face_regions.cpp:43
Classifies face regions from stream.
Definition: face_segmentation_unit.h:79