ImageSequenceProvider.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package VisionX::Component
19  * @author Jan Issac (jan dot issac at gmx dot net)
20  * @date 2011
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #pragma once
26 
28 #include <VisionX/interface/components/Calibration.h>
29 
30 
31 // IVT
32 #include <mutex>
33 #include <string>
34 
35 #include <Calibration/StereoCalibration.h>
36 #include <Image/ByteImage.h>
37 #include <VideoCapture/BitmapSequenceCapture.h>
38 
39 namespace visionx
40 {
42  {
43  public:
46  {
47  defineRequiredProperty<std::string>(
48  "PathLeft",
49  "Filename and path of the left camera images. Enter the path of the first image of "
50  "the sequence. Filenames need to follow the format: path/*%d.bmp (e.g. "
51  "path/image_left0000.bmp).");
52  defineOptionalProperty<std::string>(
53  "PathRight",
54  "",
55  "Filename and path of the right camera images. Enter the path of the first image "
56  "of the sequence. Filenames need to follow the format: path/*%d.bmp (e.g. "
57  "path/image_right0000.bmp).");
58  defineOptionalProperty<float>("FrameRate", 30.0f, "Frames per second")
59  .setMatchRegex("\\d+(.\\d*)?")
60  .setMin(0.0f)
61  .setMax(60.0f);
62  defineOptionalProperty<ImageDimension>(
63  "ImageSize",
64  ImageDimension(640, 480),
65  "Target resolution of the images. Loaded images will be converted to this size.")
66  .setCaseInsensitive(true)
67  .map("320x240", ImageDimension(320, 240))
68  .map("640x480", ImageDimension(640, 480))
69  .map("648x482", ImageDimension(648, 482))
70  .map("800x600", ImageDimension(800, 600))
71  .map("768x576", ImageDimension(768, 576))
72  .map("1024x768", ImageDimension(1024, 768))
73  .map("1024x1024", ImageDimension(1024, 1024))
74  .map("1280x960", ImageDimension(1280, 960))
75  .map("1600x1200", ImageDimension(1600, 1200))
76  .map("none", ImageDimension(0, 0));
77 
78  defineOptionalProperty<std::string>(
79  "CalibrationFile",
80  "",
81  "Camera calibration file, will be made available in the SLICE interface");
82  defineOptionalProperty<bool>(
83  "ImagesAreUndistorted", false, "Sets whether images are provided undistorted.");
84  defineOptionalProperty<bool>(
85  "LoadNextImageAutomatically",
86  true,
87  "If true, a new image is loaded everytime the 'capture()' function is executed. If "
88  "false, the same image is provided until 'loadNextImage()' is called from "
89  "somewhere");
90  defineOptionalProperty<int>(
91  "RepeatImageCount", 1, "Repeats the images for the specified amount of time.");
92 
93  defineOptionalProperty<std::string>(
94  "ReferenceFrameName", "EyeLeftCamera", "Optional reference frame name.");
95  }
96  };
97 
98  /**
99  * Image sequence provider loads images from a device and broadcasts
100  * notifications after loading at a specified frame rate.
101  *
102  * It supports the following image transmission formats:
103  *
104  * - RGB
105  * - Gray Scale
106  *
107  * \componentproperties
108  * \prop VisionX.ImageSequenceProvider.PathLeft: Image directory of the left
109  * (base) camera.
110  * \prop VisionX.ImageSequenceProvider.PathRight: Image directory of the
111  * right camera. Leave this empty if stereo is not required.
112  */
114  virtual public CapturingImageProvider,
115  virtual public ImageFileSequenceProviderInterface
116  {
117  public:
118  std::string
119  getDefaultName() const override
120  {
121  return "ImageSequenceProvider";
122  }
123 
124  /**
125  * Returns the StereoCalibration as provided in configuration
126  *
127  * @return visionx::StereoCalibration
128  */
129  visionx::StereoCalibration
130  getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override;
131 
132  /**
133  * Returns whether images are undistorted
134  *
135  * @return bool
136  */
137  bool getImagesAreUndistorted(const Ice::Current& c = Ice::emptyCurrent) override;
138 
139  std::string
140  getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
141  {
142  return getProperty<std::string>("ReferenceFrameName").getValue();
143  }
144 
145  /**
146  * Set the paths for the image files. If there are no stereo images, leave the right path empty
147  *
148  */
149  void setImageFilePath(const std::string& imageFilePathLeft,
150  const std::string& imageFilePathRight = "",
151  const Ice::Current& c = Ice::emptyCurrent) override;
152 
153  void loadNextImage(const Ice::Current& c = Ice::emptyCurrent) override;
154 
155 
156  protected:
157  /**
158  * @see visionx::CapturingImageProvider::onInitCapturingImageProvider()
159  */
160  void onInitCapturingImageProvider() override;
161 
162  /**
163  * @see visionx::CapturingImageProvider::onExitCapturingImageProvider()
164  */
165  void onExitCapturingImageProvider() override;
166 
167  /**
168  * @see visionx::CapturingImageProvider::onStartCapture(float frameRate)
169  */
170  void onStartCapture(float frameRate) override;
171 
172  /**
173  * @see visionx::CapturingImageProvider::onStopCapture()
174  */
175  void onStopCapture() override;
176 
177  bool capture(void** ppImageBuffers) override;
178 
179 
180  void OpenImageFiles();
181 
182  /**
183  * @see PropertyUser::createPropertyDefinitions()
184  */
187  {
190  }
191 
192  CByteImage** images;
193  CByteImage** resizedImages;
194  CBitmapSequenceCapture* bitmapSequenceCapture;
195  std::string filePathLeft;
196  std::string filePathRight;
197  std::mutex captureMutex;
199 
200  private:
201  /**
202  * IVT Stereo Calibration object
203  */
204  CStereoCalibration ivtStereoCalibration;
205 
206  /**
207  * VisionX StereoCalibration object
208  */
209  StereoCalibration stereoCalibration;
210 
211  int currentRepeatCount = 0;
212  int repeatImageCount;
213  };
214 
215 } // namespace visionx
visionx::ImageSequenceProvider::onExitCapturingImageProvider
void onExitCapturingImageProvider() override
Definition: ImageSequenceProvider.cpp:94
visionx::ImageSequenceProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSequenceProvider.h:140
visionx::ImageSequenceProvider::onStartCapture
void onStartCapture(float frameRate) override
Definition: ImageSequenceProvider.cpp:112
visionx::ImageSequenceProvider::captureMutex
std::mutex captureMutex
Definition: ImageSequenceProvider.h:197
visionx::ImageSequenceProvider::filePathRight
std::string filePathRight
Definition: ImageSequenceProvider.h:196
visionx::ImageSequenceProvider::loadNewImageAtNextCapture
bool loadNewImageAtNextCapture
Definition: ImageSequenceProvider.h:198
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CapturingImageProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingImageProvider.h:201
visionx::ImageSequenceProvider::images
CByteImage ** images
Definition: ImageSequenceProvider.h:192
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:345
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:46
visionx::ImageSequenceProvider::OpenImageFiles
void OpenImageFiles()
Definition: ImageSequenceProvider.cpp:203
visionx::ImageSequenceProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ImageSequenceProvider.h:186
visionx::ImageSequenceProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
Returns whether images are undistorted.
Definition: ImageSequenceProvider.cpp:186
visionx::ImageSequenceProvider::bitmapSequenceCapture
CBitmapSequenceCapture * bitmapSequenceCapture
Definition: ImageSequenceProvider.h:194
visionx::ImageSequenceProviderPropertyDefinitions::ImageSequenceProviderPropertyDefinitions
ImageSequenceProviderPropertyDefinitions(std::string prefix)
Definition: ImageSequenceProvider.h:44
visionx::CapturingImageProvider::capture
virtual void capture()
Definition: CapturingImageProvider.cpp:109
visionx::CapturingImageProvider
The CapturingImageProvider provides a callback function to trigger the capturing of images with diffe...
Definition: CapturingImageProvider.h:52
visionx::ImageSequenceProvider::onInitCapturingImageProvider
void onInitCapturingImageProvider() override
Definition: ImageSequenceProvider.cpp:49
visionx::ImageSequenceProvider::setImageFilePath
void setImageFilePath(const std::string &imageFilePathLeft, const std::string &imageFilePathRight="", const Ice::Current &c=Ice::emptyCurrent) override
Set the paths for the image files.
Definition: ImageSequenceProvider.cpp:192
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:79
CapturingImageProvider.h
visionx::ImageSequenceProvider
Image sequence provider loads images from a device and broadcasts notifications after loading at a sp...
Definition: ImageSequenceProvider.h:113
visionx::ImageSequenceProvider::onStopCapture
void onStopCapture() override
Definition: ImageSequenceProvider.cpp:127
visionx::ImageSequenceProvider::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Returns the StereoCalibration as provided in configuration.
Definition: ImageSequenceProvider.cpp:180
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:69
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:35
visionx::ImageSequenceProvider::resizedImages
CByteImage ** resizedImages
Definition: ImageSequenceProvider.h:193
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:35
visionx::ImageSequenceProvider::filePathLeft
std::string filePathLeft
Definition: ImageSequenceProvider.h:195
visionx::ImageSequenceProviderPropertyDefinitions
Definition: ImageSequenceProvider.h:41
visionx::ImageSequenceProvider::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ImageSequenceProvider.h:119
visionx::ImageSequenceProvider::loadNextImage
void loadNextImage(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSequenceProvider.cpp:281