face_video_segment  0.8
Adaptation of The Video Segmentation Project for face segmentation.
keyframe_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 FVS_KEYFRAME_UNIT_H__
30 #define FVS_KEYFRAME_UNIT_H__
31 
32 #include "base/base.h"
33 #include "video_framework/video_unit.h"
34 #include "keyframer.h"
35 
36 #include <opencv2/core.hpp>
37 
38 namespace fvs {
39 
41  {
42  std::string video_stream_name = "VideoStream";
43  std::string segment_stream_name = "SegmentationStream";
44  std::string landmarks_stream_name = "LandmarksStream";
45  std::string face_regions_stream_name = "FaceRegionsStream";
46  int start_frame = 10;
47  int stability_range = 5;
48  bool debug = false;
49  };
50 
53  class KeyframeDetectionUnit : public video_framework::VideoUnit
54  {
55  public:
58 
60  KeyframeDetectionUnit& operator=(const KeyframeDetectionUnit&) = delete;
61 
62  virtual bool OpenStreams(video_framework::StreamSet* set);
63  virtual void ProcessFrame(video_framework::FrameSetPtr input, std::list<video_framework::FrameSetPtr>* output);
64  virtual bool PostProcess(std::list<video_framework::FrameSetPtr>* append);
65 
66  private:
67  KeyframeDetectionOptions options_;
68  std::string output_dir_;
69  std::string src_name_;
70 
71  int video_stream_idx_;
72  int landmarks_stream_idx_;
73  int face_regions_stream_idx_;
74 
75  int frame_number_ = 0;
76  std::unique_ptr<Keyframer> keyframer_;
77  };
78 
80  {
81  std::string video_stream_name = "VideoStream";
82  std::string segment_stream_name = "SegmentationStream";
83  std::string landmarks_stream_name = "LandmarksStream";
84  std::string face_regions_stream_name = "FaceRegionsStream";
85  unsigned int max_scale = 500;
86  bool upscale = false;
87  bool debug = false;
88  };
89 
92  class KeyframeWriterUnit : public video_framework::VideoUnit
93  {
94  public:
96  const std::string& output_dir, const std::string& src_name);
98 
99  KeyframeWriterUnit(const KeyframeWriterUnit&) = delete;
100  KeyframeWriterUnit& operator=(const KeyframeWriterUnit&) = delete;
101 
102  virtual bool OpenStreams(video_framework::StreamSet* set);
103  virtual void ProcessFrame(video_framework::FrameSetPtr input, std::list<video_framework::FrameSetPtr>* output);
104  virtual bool PostProcess(std::list<video_framework::FrameSetPtr>* append);
105 
106  private:
107  KeyframeWriterOptions options_;
108  std::string output_dir_;
109  std::string src_name_;
110 
111  int video_stream_idx_;
112  int seg_stream_idx_;
113  int landmarks_stream_idx_;
114  int face_regions_stream_idx_;
115  int frame_number_ = 0;
116  };
117 
118 } // namespace fvs
119 
120 #endif // FACE_VIDEO_SEGMENT_KEYFRAME_WRITER_UNIT_H__
Writes keyframe from stream to file.
Definition: keyframe_unit.h:92
Definition: keyframe_unit.h:40
Definition: keyframe_unit.h:79
Detects key frames from stream.
Definition: keyframe_unit.h:53
Definition: face_regions.cpp:43