Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VideoSource_Disk.hh
1 /*
2 This file is part of the BIAS library (Basic ImageAlgorithmS).
3 
4 Copyright (C) 2003-2009 (see file CONTACT for details)
5  Multimediale Systeme der Informationsverarbeitung
6  Institut fuer Informatik
7  Christian-Albrechts-Universitaet Kiel
8 
9 
10 BIAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU Lesser General Public License as published by
12 the Free Software Foundation; either version 2.1 of the License, or
13 (at your option) any later version.
14 
15 BIAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU Lesser General Public License for more details.
19 
20 You should have received a copy of the GNU Lesser General Public License
21 along with BIAS; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24 
25 
26 #ifndef __BIASVIDEOSOURCE_DISK_HH__
27 #define __BIASVIDEOSOURCE_DISK_HH__
28 
29 
30 
31 #include <VideoSource/VideoSource_Base.hh>
32 #ifdef BIAS_HAVE_FFMPEG
33 # include <VideoSource/VideoSource_FFmpeg.hh>
34 #endif
35 
36 #include "Base/Debug/TimeMeasure.hh"
37 
38 
39 namespace BIAS{
40 /**
41  \class VideoSource_Disk
42  \ingroup g_videosource
43  \author evers
44  \brief This class simulates a video device by loading images from disk.
45 */
46  class BIASVideoSource_EXPORT VideoSource_Disk : public VideoSource{
47 
48  public:
50  virtual ~VideoSource_Disk();
51 
52  /**
53  * @brief this opens all images given by prefix, postfix, Digitcount and PictureCount
54  * e.g. myimages_00001.mip - myimages_00100.mip
55  * prefix = myimages_, postfix = .mip, digitcount = 5, picturecount = 101
56  * @param [in] Prefix, image prefix such as myimages_
57  * @param [in] Postfix, image postfix such as .mip
58  * @param [in] DigitCount, number of digits in number, e.g. 5
59  * @param [in] PictureCount, number of images
60  * @param [in] StartCount, number to start counting
61  */
62  virtual int OpenDevice(std::string Prefix, std::string Postfix, int DigitCount,
63  int PictureCount,int StartCount=0);
64  /**
65  * @brief this opens all images given in the vector of strings
66  */
67  virtual int OpenDevice(const std::vector<std::string> &FileNames);
68 
69  int CloseDevice();
70 
71  int SetColorMode(BIAS::ImageBase::EColorModel mode);
72 
73  void SetLoopMode(bool l=true){Loop_ = l;};
74 
75  void SetReverseMode(bool r=true){bReverse_=r;};
76 
77  void Rewind() {ActiveFrame_ = 0;};
78 
79  virtual int GrabSingle(BIAS::Camera <unsigned char> &image);
80  virtual int GrabSingle(BIAS::Camera <float> &image);
81 #ifdef BUILD_IMAGE_USHORT
82  virtual int GrabSingle(BIAS::Camera <unsigned short int> &image);
83 #endif
84 
85  /** Disk has also a imagebase grabber for e.g.g float images
86  */
87  virtual int GrabSingle(BIAS::ImageBase &image);
88 
89  std::string GetNextFilename() const {
90  if (ActiveFrame_ <FileNames_.size()) return FileNames_[ActiveFrame_];
91  else return "";};
92  std::string GetLastFilename() const {
93  return ActiveFrame_ >0 ? FileNames_[ActiveFrame_-1] : "" ;};
94 
95  std::vector<std::string> &GetFilenamesRef() {return FileNames_;};
96 
97  unsigned int GetNumFramesRemaining() const;
98 
99  /** @brief zero based counting, returns next frame */
100  unsigned int GetActiveFrameNumber() const { return ActiveFrame_;}
101 
102  void SetActiveFrameNumber(unsigned int frame) { ActiveFrame_ = frame; }
103 
104  /** @brief pushback new filenames on internal filename vector
105  @author koeser 12/2005 */
106  inline void AddFilenames(const std::vector<std::string> &FileNames) {
107  FileNames_.reserve(FileNames_.size()+FileNames.size());
108  for (unsigned int i=0; i<FileNames.size(); i++){
109  FileNames_.push_back(FileNames[i]);
110  }
111  }
112 
113  void SetGenerateNewUIDs(bool s) {GenerateNewUIDs_=s;};
114  void SetKeepFPS(bool s) {KeepFPS_ = s;};
115  int PreGrab();
116  int PostGrab() {return true;};
117  void SetFrameCounterAsTimeStamp(const bool b) {FrameCounterAsTimeStamp_=b;}
118 
119  /**
120  If set to 'true' ParseMetaData will be called after load-image.
121  !!!Overrides timestamp from SetFrameCounterAsTimeStamp!!!
122  **/
123  inline void SetUseMetaData(const bool b) {bUseMetaData_=b;}
124 
125  protected:
126 
128 
129  // for doublebuffering this swich is used to select the frame
130  unsigned int ActiveFrame_;
131  bool Loop_;
132  bool bReverse_;
135  std::vector<std::string> FileNames_;
136  bool KeepFPS_;
139  bool bVideo_;
140 
141 #ifdef BIAS_HAVE_FFMPEG
142  VideoSource_FFmpeg Video_;
143 #endif
144  };
145 
146 
147 } // namespace MIP
148 
149 #endif
EColorModel
These are the most often used color models.
Definition: ImageBase.hh:127
BIAS::TimeMeasure timer_
void SetUseMetaData(const bool b)
If set to &#39;true&#39; ParseMetaData will be called after load-image.
void SetLoopMode(bool l=true)
Defines a common interface to different devices.
Simple video decoding of video files using FFmpeg library.
void SetFrameCounterAsTimeStamp(const bool b)
unsigned int GetActiveFrameNumber() const
zero based counting, returns next frame
void SetReverseMode(bool r=true)
void AddFilenames(const std::vector< std::string > &FileNames)
pushback new filenames on internal filename vector
std::string GetNextFilename() const
std::vector< std::string > & GetFilenamesRef()
std::string GetLastFilename() const
std::vector< std::string > FileNames_
void SetActiveFrameNumber(unsigned int frame)
This is the base class for images in BIAS.
Definition: ImageBase.hh:102
class TimeMeasure contains functions for timing real time and cpu time.
Definition: TimeMeasure.hh:111
int PostGrab()
Stop anything started in PreGrab()
This class simulates a video device by loading images from disk.