Image Component Library (ICL)
GenericGrabber.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLIO/src/ICLIO/GenericGrabber.h **
10 ** Module : ICLIO **
11 ** Authors: Christof Elbrechter, Viktor Richter **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 
33 #include <ICLUtils/Macros.h>
34 #include <ICLUtils/Exception.h>
35 #include <ICLUtils/Lockable.h>
36 #include <ICLUtils/ProgArg.h>
38 #include <ICLIO/Grabber.h>
39 #include <string>
40 
41 namespace icl {
42  namespace io{
43 
45  class ConfigurableRemoteServer;
48 
56 
58 
60 
62 
64 
65  public:
67 
69 
71  init(pa);
72  }
73 
75 
76  GenericGrabber(const std::string &devicePriorityList,
77  const std::string &params,
78  bool notifyErrors = true) {
79  init(devicePriorityList,params,notifyErrors);
80  }
81 
82 
84 
85  GenericGrabber():m_poGrabber(0),m_remoteServer(0){}
86 
88 
171  void init(const std::string &devicePriorityList,
172  const std::string &params,
173  bool notifyErrors = true) ;
174 
176  void init(const utils::ProgArg &pa) ;
177 
179  static void resetBus(const std::string &deviceList="dc", bool verbose=false);
180 
182  std::string getType() const {
183  utils::Mutex::Locker __lock(m_mutex);
184  return m_poDesc.type;
185  }
186 
188  Grabber *getGrabber() const {
189  utils::Mutex::Locker __lock(m_mutex);
190  return m_poGrabber;
191  }
192 
194  virtual ~GenericGrabber();
195 
197 
198  const core::ImgBase *grab(core::ImgBase **dst = 0){
199  utils::Mutex::Locker __lock(m_mutex);
200  ICLASSERT_RETURN_VAL(!isNull(), 0);
201 
202  return m_poGrabber->grab(dst);
203  }
204 
206  bool isNull() const { return m_poGrabber == 0; }
207 
209  operator bool() const { return !isNull(); }
210 
211 
214  ICLASSERT_RETURN(!isNull());
215  utils::Mutex::Locker l(m_mutex);
216  m_poGrabber->setDesiredFormatInternal(fmt);
217  }
218 
221  ICLASSERT_RETURN(!isNull());
222  utils::Mutex::Locker l(m_mutex);
223  m_poGrabber->setDesiredSizeInternal(size);
224  }
225 
228  ICLASSERT_RETURN(!isNull());
229  utils::Mutex::Locker l(m_mutex);
230  m_poGrabber->setDesiredDepthInternal(d);
231  }
232 
235  ICLASSERT_RETURN_VAL(!isNull(),(core::format)-1);
236  utils::Mutex::Locker l(m_mutex);
237  return m_poGrabber->getDesiredFormatInternal();
238  }
239 
242  ICLASSERT_RETURN_VAL(!isNull(),(core::depth)-1);
243  utils::Mutex::Locker l(m_mutex);
244  return m_poGrabber->getDesiredDepthInternal();
245  }
246 
250  utils::Mutex::Locker l(m_mutex);
251  return m_poGrabber->getDesiredSizeInternal();
252  }
253 
256  ICLASSERT_RETURN(!isNull());
257  utils::Mutex::Locker l(m_mutex);
258  m_poGrabber->registerCallback(cb);
259  }
260 
263  ICLASSERT_RETURN(!isNull());
264  utils::Mutex::Locker l(m_mutex);
265  m_poGrabber->removeAllCallbacks();
266  }
267 
269 
270  template<class T>
271  bool desiredUsed() const{
272  ICLASSERT_RETURN_VAL(!isNull(),false);
273  utils::Mutex::Locker l(m_mutex);
274  return m_poGrabber->desiredUsed<T>();
275  }
276 
278  template<class T>
279  void useDesired(const T &t){
280  ICLASSERT_RETURN(!isNull());
281  utils::Mutex::Locker l(m_mutex);
282  m_poGrabber->useDesired<T>(t);
283  }
284 
286  void useDesired(core::depth d, const utils::Size &size, core::format fmt){
287  ICLASSERT_RETURN(!isNull());
288  utils::Mutex::Locker l(m_mutex);
289  m_poGrabber->useDesired(d, size, fmt);
290  }
291 
293 
294  template<class T>
295  void ignoreDesired() {
296  ICLASSERT_RETURN(!isNull());
297  utils::Mutex::Locker l(m_mutex);
298  m_poGrabber->ignoreDesired<T>();
299  }
300 
303  ICLASSERT_RETURN(!isNull());
304  utils::Mutex::Locker l(m_mutex);
305  m_poGrabber->ignoreDesired();
306  }
307 
309 
310  template<class T>
311  T getDesired() const {
312  ICLASSERT_RETURN_VAL(!isNull(), T());
313  utils::Mutex::Locker l(m_mutex);
314  return m_poGrabber->getDesired<T>();
315  }
316 
318  void enableUndistortion(const std::string &filename){
319  ICLASSERT_RETURN(!isNull());
320  utils::Mutex::Locker l(m_mutex);
321  m_poGrabber->enableUndistortion(filename);
322  }
323 
326  ICLASSERT_RETURN(!isNull());
327  utils::Mutex::Locker l(m_mutex);
328  m_poGrabber->enableUndistortion(udist);
329  }
330 
332 
334  ICLASSERT_RETURN(!isNull());
335  utils::Mutex::Locker l(m_mutex);
336  m_poGrabber->enableUndistortion(pa);
337  }
338 
340  void enableUndistortion(const core::Img32f &warpMap){
341  ICLASSERT_RETURN(!isNull());
342  utils::Mutex::Locker l(m_mutex);
343  m_poGrabber->enableUndistortion(warpMap);
344  }
345 
347 
351  ICLASSERT_RETURN(!isNull());
352  utils::Mutex::Locker l(m_mutex);
353  m_poGrabber->setUndistortionInterpolationMode(mode);
354  }
355 
358  ICLASSERT_RETURN(!isNull());
359  utils::Mutex::Locker l(m_mutex);
360  m_poGrabber->disableUndistortion();
361  }
362 
364  bool isUndistortionEnabled() const{
365  ICLASSERT_RETURN_VAL(!isNull(),false);
366  utils::Mutex::Locker l(m_mutex);
367  return m_poGrabber->isUndistortionEnabled();
368  }
369 
372  ICLASSERT_RETURN_VAL(!isNull(),0);
373  utils::Mutex::Locker l(m_mutex);
374  return m_poGrabber->getUndistortionWarpMap();
375  }
376 
378 
385  static const std::vector<GrabberDeviceDescription> &getDeviceList(const std::string &filter, bool rescan=true);
386 
388 
389  inline void init(const GrabberDeviceDescription &dev){
390  init(dev.type,dev.type+"="+dev.id,false);
391  }
392  };
393 
394  } // namespace io
395 }
396 
void setDesiredDepthInternal(core::depth d)
internally set a desired format
Definition: GenericGrabber.h:227
void disableUndistortion()
disables distortion
Definition: GenericGrabber.h:357
GrabberDeviceDescription m_poDesc
description of current Grabber
Definition: GenericGrabber.h:59
The General Function Template.
Definition: Function.h:284
void useDesired(const T &t)
sets desired parameters (only available for core::depth,utils::Size and core::format)
Definition: Grabber.h:204
Definition: ConfigurableRemoteServer.h:39
undocument this line if you encounter any issues!
Definition: Any.h:37
Class interface for un-copyable classes.
Definition: Uncopyable.h:64
static const Size null
null is w=0, h=0
Definition: Size.h:64
Grabber * m_poGrabber
internally wrapped grabber instance
Definition: GenericGrabber.h:57
bool isNull() const
returns wheter an underlying grabber could be created
Definition: GenericGrabber.h:206
void useDesired(core::depth d, const utils::Size &size, core::format fmt)
sets up the grabber to use all given desired parameters
Definition: GenericGrabber.h:286
void removeAllCallbacks()
passes registered callback to the internal pointer
Definition: GenericGrabber.h:262
GenericGrabber(const utils::ProgArg &pa)
Initialized the grabber from given prog-arg.
Definition: GenericGrabber.h:70
virtual void setDesiredFormatInternal(core::format fmt)
internally set a desired format
T getDesired() const
returns the desired value for the given type T
Definition: GenericGrabber.h:311
core::depth getDesiredDepthInternal() const
returns the desired format
Definition: GenericGrabber.h:241
std::string type
type of the device (e.g. dc, pwc, sr or dc800)
Definition: GrabberDeviceDescription.h:50
virtual core::format getDesiredFormatInternal() const
returns the desired format
void setUndistortionInterpolationMode(core::scalemode mode)
sets how undistortion is interpolated (supported modes are interpolateNN and interpolateLIN)
Definition: GenericGrabber.h:350
std::string getType() const
return the actual grabber type
Definition: GenericGrabber.h:182
virtual utils::Size getDesiredSizeInternal() const
returns the desired format
bool desiredUsed() const
returns whether the desired parameter for the given type is used
Definition: GenericGrabber.h:271
Grabber * getGrabber() const
returns the wrapped grabber itself
Definition: GenericGrabber.h:188
defines and explains an available grabber device
Definition: GrabberDeviceDescription.h:41
const core::ImgBase * grab(core::ImgBase **dst=0)
grab function calls the Grabber-specific acquireImage-method and applies distortion if necessary
format
determines the color-format, that is associated with the images channels
Definition: Types.h:70
virtual void setDesiredSizeInternal(const utils::Size &size)
internally set a desired format
void init(const GrabberDeviceDescription &dev)
initializes the grabber from given FoundDevice instance
Definition: GenericGrabber.h:389
bool desiredUsed() const
returns whether the desired parameter for the given type is used
Definition: Grabber.h:200
T getDesired() const
returns the desired value for the given type T
Definition: Grabber.h:222
#define ICLASSERT_RETURN_VAL(X, VALUE)
Definition: Macros.h:148
void enableUndistortion(const utils::ProgArg &pa)
enables undistortion from given programm argument.
Definition: GenericGrabber.h:333
This class provides the getter and setter methods of an internally set Configurable.
Definition: ConfigurableProxy.h:40
const ProgArg pa(const std::string &id, unsigned int subargidx=0)
returns given program argument
Definition: ProgArg.h:304
void enableUndistortion(const ImageUndistortion &udist)
enables the undistortion plugin for the grabber using radial and tangential distortion parameters
Definition: GenericGrabber.h:325
#define ICLIO_API
Definition: CompatMacros.h:176
void enableUndistortion(const core::Img32f &warpMap)
enables undistortion for given warp map
Definition: GenericGrabber.h:340
void setUndistortionInterpolationMode(core::scalemode mode)
sets how undistortion is interpolated (supported modes are interpolateNN and interpolateLIN)
virtual void removeAllCallbacks()
removes all registered image callbacks
Size class of the ICL.
Definition: Size.h:61
Common interface class for all grabbers.
Definition: Grabber.h:153
void disableUndistortion()
disables distortion
std::string id
ID of the device (e.g. 0 or 1)
Definition: GrabberDeviceDescription.h:53
ICLQt_API core::Img< T > filter(const core::Img< T > &image, const std::string &filter)
applies a filter operation on the source image (affinity for float)
Programm argument utility class.
Definition: ProgArg.h:80
core::format getDesiredFormatInternal() const
returns the desired format
Definition: GenericGrabber.h:234
void enableUndistortion(const std::string &filename)
enables the undistorion
Definition: GenericGrabber.h:318
void registerCallback(Configurable::Callback cb)
Definition: ConfigurableProxy.h:96
void ignoreDesired()
sets up the grabber to ignore all desired parameters
Definition: GenericGrabber.h:302
GenericGrabber(const std::string &devicePriorityList, const std::string &params, bool notifyErrors=true)
Create a generic grabber instance with given device priority list.
Definition: GenericGrabber.h:76
virtual core::depth getDesiredDepthInternal() const
returns the desired format
const core::Img32f * getUndistortionWarpMap() const
returns the internal warp map or NULL if undistortion is not enabled
Definition: GenericGrabber.h:371
scalemode
for scaling of Img images theses functions are provided
Definition: Types.h:84
depth
determines the pixel type of an image (8Bit-int or 32Bit-float)
Definition: Types.h:60
void ignoreDesired()
set the grabber to ignore the desired param of type T
Definition: Grabber.h:212
void setDesiredSizeInternal(const utils::Size &size)
internally set a desired format
Definition: GenericGrabber.h:220
const core::Img32f * getUndistortionWarpMap() const
returns the internal warp map or NULL if undistortion is not enabled
ConfigurableRemoteServer * m_remoteServer
<< internal protection for re-initialization
Definition: GenericGrabber.h:63
const core::ImgBase * grab(core::ImgBase **dst=0)
grab function calls the Grabber-specific acquireImage-method and applies distortion if necessary
Definition: GenericGrabber.h:198
bool isUndistortionEnabled() const
returns whether distortion is currently enabled
utils::Size getDesiredSizeInternal() const
returns the desired format
Definition: GenericGrabber.h:248
void registerCallback(Grabber::callback cb)
passes registered callback to the internal pointer
Definition: GenericGrabber.h:255
virtual void registerCallback(callback cb)
registers a callback that is called each time, a new image is available
void enableUndistortion(const std::string &filename)
enables the undistorion
utils::Mutex m_mutex
Definition: GenericGrabber.h:61
Common interface class for all grabbers.
Definition: GenericGrabber.h:55
#define ICLASSERT_RETURN(X)
Definition: Macros.h:141
GenericGrabber()
Empty default constructor, which creates a null-instance.
Definition: GenericGrabber.h:85
bool isUndistortionEnabled() const
returns whether distortion is currently enabled
Definition: GenericGrabber.h:364
virtual void setDesiredDepthInternal(core::depth d)
internally set a desired format
Definition: ImageUndistortion.h:39
Mutex class of the ICL.
Definition: Mutex.h:54
ImgBase is the Image-Interface class that provides save access to underlying Img-template .
Definition: ImgBase.h:131
Locks a mutex on the stack (mutex is unlocked when the stack's section is released.
Definition: Mutex.h:120
void setDesiredFormatInternal(core::format fmt)
internally set a desired format
Definition: GenericGrabber.h:213
void ignoreDesired()
set the grabber to ignore the desired param of type T
Definition: GenericGrabber.h:295
void useDesired(const T &t)
sets desired parameters (only available for core::depth,utils::Size and core::format)
Definition: GenericGrabber.h:279