iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ImageSource.H
Go to the documentation of this file.
1 /*! @file
2  @author Randolph Voorhies
3  @copyright GNU Public License (GPL v3)
4  @section License
5  @verbatim
6  // ////////////////////////////////////////////////////////////////////////
7  // The iLab Neuromorphic Robotics Toolkit (NRT) //
8  // Copyright 2010-2012 by the University of Southern California (USC) //
9  // and the iLab at USC. //
10  // //
11  // iLab - University of Southern California //
12  // Hedco Neurociences Building, Room HNB-10 //
13  // Los Angeles, Ca 90089-2520 - USA //
14  // //
15  // See http://ilab.usc.edu for information about this project. //
16  // ////////////////////////////////////////////////////////////////////////
17  // This file is part of The iLab Neuromorphic Robotics Toolkit. //
18  // //
19  // The iLab Neuromorphic Robotics Toolkit is free software: you can //
20  // redistribute it and/or modify it under the terms of the GNU General //
21  // Public License as published by the Free Software Foundation, either //
22  // version 3 of the License, or (at your option) any later version. //
23  // //
24  // The iLab Neuromorphic Robotics Toolkit is distributed in the hope //
25  // that it will be useful, but WITHOUT ANY WARRANTY; without even the //
26  // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
27  // PURPOSE. See the GNU General Public License for more details. //
28  // //
29  // You should have received a copy of the GNU General Public License //
30  // along with The iLab Neuromorphic Robotics Toolkit. If not, see //
31  // <http://www.gnu.org/licenses/>. //
32  // ////////////////////////////////////////////////////////////////////////
33  @endverbatim */
34 
35 
36 #ifndef INCLUDE_NRT_IMAGEPROC_IO_IMAGESOURCE_IMAGESOURCE_H
37 #define INCLUDE_NRT_IMAGEPROC_IO_IMAGESOURCE_IMAGESOURCE_H
38 
41 
42 namespace nrt
43 {
44  class ImageSourceType;
45  namespace imagesource
46  {
47  static ParameterCategory ParamCateg("Image Source Related Options");
48  NRT_DECLARE_PARAMETER_WITH_CALLBACK(intype, std::string,
49  "Input type",
51  }
52 
53 
54  //! A Component that can stream images from a variety of sources
55  /*! The ImageSource framework allows users to easily choose from a variety of
56  Image sources at runtime, such as cameras, @link RandomImageSource random
57  generators @endlink, @link VideoSource video files @endlink, @link
58  ImageFilesSource image sequences @endlink, etc...
59 
60  Example:
61  <code>
62  nrt::Manager mgr(argc, argv);
63 
64  std::shared_ptr<nrt::ImageSource> source(new nrt::ImageSource("mysource"));
65  mgr.addSubComponent(source);
66 
67  mgr.launch();
68 
69  while(source->ok)
70  {
71  nrt::GenericImage img = source->in();
72  }
73  </code>
74 
75  Developers who wish to make their own Image sources compatible with the
76  ImageSource framework should first take a look at the VideoSource and
77  ImageSource classes, as they provide convenient ways to create sources for
78  video files, and image sequences respectively. For non file-based sources
79  (such as cameras, or other devices), developers may inherit directly from
80  the ImageSourceType base class. */
81  class ImageSource : public nrt::Component, public nrt::Parameter<imagesource::intype>
82  {
83  public:
84  ImageSource(std::string instanceID = "in");
85 
86  //! Grab another frame from the underlying source
87  /*! Each call to in() will advance the underyling ImageSourceType to the next frame */
88  virtual GenericImage const in();
89 
90  //! Is this ImageSource ready to grab another frame?
91  /*! If ok() returns true, then a subsequent call to in() should return a valid GenericImage */
92  bool const ok() const;
93 
94  //! Get a reference the the underlying implementation that was created from the --in parameter
95  std::shared_ptr<ImageSourceType> actualSource() const;
96 
97  private:
98  std::shared_ptr<ImageSourceType> itsSource;
99  void onParamChange(nrt::imagesource::intype const & param, std::string const & newtype);
100  };
101 
102 } // namespace nrt
103 
104 #endif // INCLUDE_NRT_IMAGEPROC_IO_IMAGESOURCE_IMAGESOURCE_H
105