face_video_segment  0.8
Adaptation of The Video Segmentation Project for face segmentation.
video_reader_unit2.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 VFS_VIDEO_READER_UNIT2_H__
30 #define VFS_VIDEO_READER_UNIT2_H__
31 
32 #include "base/base.h"
33 #include "video_framework/video_unit.h"
34 
35 #include <opencv2/videoio.hpp>
36 
37 struct AVCodec;
38 struct AVCodecContext;
39 struct AVFormatContext;
40 struct AVFrame;
41 struct AVPacket;
42 struct SwsContext;
43 
44 namespace fvs {
45 
47  int trim_frames = 0;
48  std::string stream_name = "VideoStream";
49  video_framework::VideoPixelFormat pixel_format =
50  video_framework::PIXEL_FORMAT_BGR24;
51 
52  // For settings below only downscale will be performed, ie. never upscaling.
53  enum DOWNSCALE {
54  DOWNSCALE_NONE,
55  DOWNSCALE_BY_FACTOR, // Resizes each dimension by downscale_factor.
56 
57  DOWNSCALE_TO_MIN_SIZE, // Resizes minimum dimension to downscale_size.
58  DOWNSCALE_TO_MAX_SIZE, // Resizes maximum dimension to downscale_size.
59  };
60 
61  DOWNSCALE downscale = DOWNSCALE_NONE;
62 
63  float downscale_factor = 1.0f;
64  int downscale_size = 0;
65 };
66 
69 class VideoReaderUnit2 : public video_framework::VideoUnit {
70  public:
72  const std::string& video_file);
74 
75  virtual bool OpenStreams(video_framework::StreamSet* set);
76  virtual void ProcessFrame(video_framework::FrameSetPtr input,
77  std::list<video_framework::FrameSetPtr>* output);
78  virtual bool PostProcess(std::list<video_framework::FrameSetPtr>* append);
79  /*
80  // Experimental (might not seek to correct locations).
81  virtual bool SeekImpl(int64_t pts);
82  bool PrevFrame();
83 
84  // Can be positive or negative.
85  bool SkipFrames(int frame_offset);
86  */
87 
88  private:
89  // Returns allocated VideoFrame (ownership passed to caller).
90  // Returns NULL if end of file is reached.
91  video_framework::VideoFrame* ReadNextFrame();
92 
93  private:
94  VideoReader2Options options_;
95  std::string video_file_;
96 
97  int video_stream_idx_;
98  int frame_num_ = 0;
99 
100  int frame_width_ = 0;
101  int frame_height_ = 0;
102  int frame_width_step_ = 0;
103  double fps_;
104 
105  bool used_as_root_ = true;
106 
107  std::unique_ptr<cv::VideoCapture> m_cap;
108  cv::Mat m_frame;
109 };
110 
111 } // namespace fvs.
112 
113 #endif // VFS_VIDEO_READER_UNIT2_H__
Reads video frames from file into stream.
Definition: video_reader_unit2.h:69
Definition: video_reader_unit2.h:46
Definition: face_regions.cpp:43