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 <VideoCapture/BitmapSequenceCapture.h>
33 #include <Image/ByteImage.h>
34 #include <Calibration/StereoCalibration.h>
35 
36 #include <string>
37 #include <mutex>
38 
39 namespace visionx
40 {
43  {
44  public:
47  {
48  defineRequiredProperty<std::string>("PathLeft", "Filename and path of the left camera images. Enter the path of the first image of the sequence. Filenames need to follow the format: path/*%d.bmp (e.g. path/image_left0000.bmp).");
49  defineOptionalProperty<std::string>("PathRight", "", "Filename and path of the right camera images. Enter the path of the first image of the sequence. Filenames need to follow the format: path/*%d.bmp (e.g. path/image_right0000.bmp).");
50  defineOptionalProperty<float>("FrameRate", 30.0f, "Frames per second")
51  .setMatchRegex("\\d+(.\\d*)?")
52  .setMin(0.0f)
53  .setMax(60.0f);
54  defineOptionalProperty<ImageDimension>("ImageSize", ImageDimension(640, 480), "Target resolution of the images. Loaded images will be converted to this size.")
55  .setCaseInsensitive(true)
56  .map("320x240", ImageDimension(320, 240))
57  .map("640x480", ImageDimension(640, 480))
58  .map("648x482", ImageDimension(648, 482))
59  .map("800x600", ImageDimension(800, 600))
60  .map("768x576", ImageDimension(768, 576))
61  .map("1024x768", ImageDimension(1024, 768))
62  .map("1024x1024", ImageDimension(1024, 1024))
63  .map("1280x960", ImageDimension(1280, 960))
64  .map("1600x1200", ImageDimension(1600, 1200))
65  .map("none", ImageDimension(0, 0));
66 
67  defineOptionalProperty<std::string>("CalibrationFile", "", "Camera calibration file, will be made available in the SLICE interface");
68  defineOptionalProperty<bool>("ImagesAreUndistorted", false, "Sets whether images are provided undistorted.");
69  defineOptionalProperty<bool>("LoadNextImageAutomatically", true, "If true, a new image is loaded everytime the 'capture()' function is executed. If false, the same image is provided until 'loadNextImage()' is called from somewhere");
70  defineOptionalProperty<int>("RepeatImageCount", 1, "Repeats the images for the specified amount of time.");
71 
72  defineOptionalProperty<std::string>("ReferenceFrameName", "EyeLeftCamera", "Optional reference frame name.");
73  }
74  };
75 
76  /**
77  * Image sequence provider loads images from a device and broadcasts
78  * notifications after loading at a specified frame rate.
79  *
80  * It supports the following image transmission formats:
81  *
82  * - RGB
83  * - Gray Scale
84  *
85  * \componentproperties
86  * \prop VisionX.ImageSequenceProvider.PathLeft: Image directory of the left
87  * (base) camera.
88  * \prop VisionX.ImageSequenceProvider.PathRight: Image directory of the
89  * right camera. Leave this empty if stereo is not required.
90  */
92  virtual public CapturingImageProvider,
93  virtual public ImageFileSequenceProviderInterface
94  {
95  public:
96  std::string getDefaultName() const override
97  {
98  return "ImageSequenceProvider";
99  }
100 
101 
102  /**
103  * Returns the StereoCalibration as provided in configuration
104  *
105  * @return visionx::StereoCalibration
106  */
107  visionx::StereoCalibration getStereoCalibration(const Ice::Current& c = Ice::emptyCurrent) override;
108 
109  /**
110  * Returns whether images are undistorted
111  *
112  * @return bool
113  */
114  bool getImagesAreUndistorted(const Ice::Current& c = Ice::emptyCurrent) override;
115 
116 
117  std::string getReferenceFrame(const Ice::Current& c = Ice::emptyCurrent) override
118  {
119  return getProperty<std::string>("ReferenceFrameName").getValue();
120  }
121 
122  /**
123  * Set the paths for the image files. If there are no stereo images, leave the right path empty
124  *
125  */
126  void setImageFilePath(const std::string& imageFilePathLeft, const std::string& imageFilePathRight = "", const Ice::Current& c = Ice::emptyCurrent) override;
127 
128  void loadNextImage(const Ice::Current& c = Ice::emptyCurrent) override;
129 
130 
131 
132  protected:
133  /**
134  * @see visionx::CapturingImageProvider::onInitCapturingImageProvider()
135  */
136  void onInitCapturingImageProvider() override;
137 
138  /**
139  * @see visionx::CapturingImageProvider::onExitCapturingImageProvider()
140  */
141  void onExitCapturingImageProvider() override;
142 
143  /**
144  * @see visionx::CapturingImageProvider::onStartCapture(float frameRate)
145  */
146  void onStartCapture(float frameRate) override;
147 
148  /**
149  * @see visionx::CapturingImageProvider::onStopCapture()
150  */
151  void onStopCapture() override;
152 
153  bool capture(void** ppImageBuffers) override;
154 
155 
156  void OpenImageFiles();
157 
158 
159  /**
160  * @see PropertyUser::createPropertyDefinitions()
161  */
163  {
165  }
166 
167  CByteImage** images;
168  CByteImage** resizedImages;
169  CBitmapSequenceCapture* bitmapSequenceCapture;
170  std::string filePathLeft;
171  std::string filePathRight;
172  std::mutex captureMutex;
174 
175  private:
176  /**
177  * IVT Stereo Calibration object
178  */
179  CStereoCalibration ivtStereoCalibration;
180 
181  /**
182  * VisionX StereoCalibration object
183  */
184  StereoCalibration stereoCalibration;
185 
186  int currentRepeatCount = 0;
187  int repeatImageCount;
188  };
189 
190 }
191 
visionx::ImageSequenceProvider::onExitCapturingImageProvider
void onExitCapturingImageProvider() override
Definition: ImageSequenceProvider.cpp:92
visionx::ImageSequenceProvider::getReferenceFrame
std::string getReferenceFrame(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSequenceProvider.h:117
visionx::ImageSequenceProvider::onStartCapture
void onStartCapture(float frameRate) override
Definition: ImageSequenceProvider.cpp:110
visionx::ImageSequenceProvider::captureMutex
std::mutex captureMutex
Definition: ImageSequenceProvider.h:172
visionx::ImageSequenceProvider::filePathRight
std::string filePathRight
Definition: ImageSequenceProvider.h:171
visionx::ImageSequenceProvider::loadNewImageAtNextCapture
bool loadNewImageAtNextCapture
Definition: ImageSequenceProvider.h:173
visionx
ArmarX headers.
Definition: OpenPoseStressTest.h:38
visionx::CapturingImageProvider::frameRate
float frameRate
Required frame rate.
Definition: CapturingImageProvider.h:198
visionx::ImageSequenceProvider::images
CByteImage ** images
Definition: ImageSequenceProvider.h:167
armarx::PropertyDefinitionContainer::prefix
std::string prefix
Prefix of the properties such as namespace, domain, component name, etc.
Definition: PropertyDefinitionContainer.h:333
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
visionx::ImageSequenceProvider::OpenImageFiles
void OpenImageFiles()
Definition: ImageSequenceProvider.cpp:197
visionx::ImageSequenceProvider::createPropertyDefinitions
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: ImageSequenceProvider.h:162
visionx::ImageSequenceProvider::getImagesAreUndistorted
bool getImagesAreUndistorted(const Ice::Current &c=Ice::emptyCurrent) override
Returns whether images are undistorted.
Definition: ImageSequenceProvider.cpp:182
visionx::ImageSequenceProvider::bitmapSequenceCapture
CBitmapSequenceCapture * bitmapSequenceCapture
Definition: ImageSequenceProvider.h:169
visionx::ImageSequenceProviderPropertyDefinitions::ImageSequenceProviderPropertyDefinitions
ImageSequenceProviderPropertyDefinitions(std::string prefix)
Definition: ImageSequenceProvider.h:45
visionx::CapturingImageProvider::capture
virtual void capture()
Definition: CapturingImageProvider.cpp:106
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:188
armarx::Component::getConfigIdentifier
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition: Component.cpp:74
CapturingImageProvider.h
visionx::ImageSequenceProvider
Image sequence provider loads images from a device and broadcasts notifications after loading at a sp...
Definition: ImageSequenceProvider.h:91
visionx::ImageSequenceProvider::onStopCapture
void onStopCapture() override
Definition: ImageSequenceProvider.cpp:125
visionx::ImageSequenceProvider::getStereoCalibration
visionx::StereoCalibration getStereoCalibration(const Ice::Current &c=Ice::emptyCurrent) override
Returns the StereoCalibration as provided in configuration.
Definition: ImageSequenceProvider.cpp:176
armarx::ComponentPropertyDefinitions
Default component property definition container.
Definition: Component.h:70
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::ComponentPropertyDefinitions::ComponentPropertyDefinitions
ComponentPropertyDefinitions(std::string prefix, bool hasObjectNameParameter=true)
Definition: Component.cpp:37
visionx::ImageSequenceProvider::resizedImages
CByteImage ** resizedImages
Definition: ImageSequenceProvider.h:168
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
visionx::ImageSequenceProvider::filePathLeft
std::string filePathLeft
Definition: ImageSequenceProvider.h:170
visionx::ImageSequenceProviderPropertyDefinitions
Definition: ImageSequenceProvider.h:41
visionx::ImageSequenceProvider::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: ImageSequenceProvider.h:96
visionx::ImageSequenceProvider::loadNextImage
void loadNextImage(const Ice::Current &c=Ice::emptyCurrent) override
Definition: ImageSequenceProvider.cpp:271