Image Component Library (ICL)
|
00001 /******************************************************************** 00002 ** Image Component Library (ICL) ** 00003 ** ** 00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** 00005 ** Neuroinformatics Group ** 00006 ** Website: www.iclcv.org and ** 00007 ** http://opensource.cit-ec.de/projects/icl ** 00008 ** ** 00009 ** File : ICLIO/src/ICLIO/GenericGrabber.h ** 00010 ** Module : ICLIO ** 00011 ** Authors: Christof Elbrechter, Viktor Richter ** 00012 ** ** 00013 ** ** 00014 ** GNU LESSER GENERAL PUBLIC LICENSE ** 00015 ** This file may be used under the terms of the GNU Lesser General ** 00016 ** Public License version 3.0 as published by the ** 00017 ** ** 00018 ** Free Software Foundation and appearing in the file LICENSE.GPL ** 00019 ** included in the packaging of this file. Please review the ** 00020 ** following information to ensure the license requirements will ** 00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** 00022 ** ** 00023 ** The development of this software was supported by the ** 00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** 00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** 00026 ** Forschungsgemeinschaft (DFG) in the context of the German ** 00027 ** Excellence Initiative. ** 00028 ** ** 00029 ********************************************************************/ 00030 00031 #pragma once 00032 00033 #include <ICLIO/Grabber.h> 00034 #include <string> 00035 #include <ICLUtils/Macros.h> 00036 #include <ICLUtils/Exception.h> 00037 #include <ICLUtils/Lockable.h> 00038 #include <ICLUtils/ProgArg.h> 00039 #include <ICLUtils/ConfigurableProxy.h> 00040 00041 namespace icl { 00042 namespace io{ 00043 00045 00051 class GenericGrabber: public utils::Uncopyable, public utils::ConfigurableProxy{ 00052 00053 Grabber *m_poGrabber; 00054 00055 GrabberDeviceDescription m_poDesc; 00056 00057 mutable utils::Mutex m_mutex; 00058 00059 public: 00060 00062 00063 GenericGrabber(const utils::ProgArg &pa) throw (utils::ICLException):m_poGrabber(0){ 00064 init(pa); 00065 } 00066 00068 00069 GenericGrabber(const std::string &devicePriorityList, 00070 const std::string ¶ms, 00071 bool notifyErrors = true) throw (utils::ICLException):m_poGrabber(0){ 00072 init(devicePriorityList,params,notifyErrors); 00073 } 00074 00075 00077 00078 GenericGrabber():m_poGrabber(0){} 00079 00081 00162 void init(const std::string &devicePriorityList, 00163 const std::string ¶ms, 00164 bool notifyErrors = true) throw (utils::ICLException); 00165 00167 void init(const utils::ProgArg &pa) throw (utils::ICLException); 00168 00170 static void resetBus(const std::string &deviceList="dc", bool verbose=false); 00171 00173 std::string getType() const { 00174 utils::Mutex::Locker __lock(m_mutex); 00175 return m_poDesc.type; 00176 } 00177 00179 Grabber *getGrabber() const { 00180 utils::Mutex::Locker __lock(m_mutex); 00181 return m_poGrabber; 00182 } 00183 00185 virtual ~GenericGrabber(); 00186 00188 00189 const core::ImgBase *grab(core::ImgBase **dst=0){ 00190 utils::Mutex::Locker __lock(m_mutex); 00191 ICLASSERT_RETURN_VAL(!isNull(),0); 00192 return m_poGrabber->grab(dst); 00193 } 00194 00196 bool isNull() const { return m_poGrabber == 0; } 00197 00199 operator bool() const { return !isNull(); } 00200 00201 00203 void setDesiredFormatInternal(core::format fmt){ 00204 ICLASSERT_RETURN(!isNull()); 00205 utils::Mutex::Locker l(m_mutex); 00206 m_poGrabber->setDesiredFormatInternal(fmt); 00207 } 00208 00210 void setDesiredSizeInternal(const utils::Size &size){ 00211 ICLASSERT_RETURN(!isNull()); 00212 utils::Mutex::Locker l(m_mutex); 00213 m_poGrabber->setDesiredSizeInternal(size); 00214 } 00215 00217 void setDesiredDepthInternal(core::depth d){ 00218 ICLASSERT_RETURN(!isNull()); 00219 utils::Mutex::Locker l(m_mutex); 00220 m_poGrabber->setDesiredDepthInternal(d); 00221 } 00222 00224 core::format getDesiredFormatInternal() const{ 00225 ICLASSERT_RETURN_VAL(!isNull(),(core::format)-1); 00226 utils::Mutex::Locker l(m_mutex); 00227 return m_poGrabber->getDesiredFormatInternal(); 00228 } 00229 00231 core::depth getDesiredDepthInternal() const{ 00232 ICLASSERT_RETURN_VAL(!isNull(),(core::depth)-1); 00233 utils::Mutex::Locker l(m_mutex); 00234 return m_poGrabber->getDesiredDepthInternal(); 00235 } 00236 00238 utils::Size getDesiredSizeInternal() const{ 00239 ICLASSERT_RETURN_VAL(!isNull(),utils::Size::null); 00240 utils::Mutex::Locker l(m_mutex); 00241 return m_poGrabber->getDesiredSizeInternal(); 00242 } 00243 00245 void registerCallback(Grabber::callback cb){ 00246 ICLASSERT_RETURN(!isNull()); 00247 utils::Mutex::Locker l(m_mutex); 00248 m_poGrabber->registerCallback(cb); 00249 } 00250 00252 void removeAllCallbacks(){ 00253 ICLASSERT_RETURN(!isNull()); 00254 utils::Mutex::Locker l(m_mutex); 00255 m_poGrabber->removeAllCallbacks(); 00256 } 00257 00259 00260 template<class T> 00261 bool desiredUsed() const{ 00262 ICLASSERT_RETURN_VAL(!isNull(),false); 00263 utils::Mutex::Locker l(m_mutex); 00264 return m_poGrabber->desiredUsed<T>(); 00265 } 00266 00268 template<class T> 00269 void useDesired(const T &t){ 00270 ICLASSERT_RETURN(!isNull()); 00271 utils::Mutex::Locker l(m_mutex); 00272 m_poGrabber->useDesired<T>(t); 00273 } 00274 00276 void useDesired(core::depth d, const utils::Size &size, core::format fmt){ 00277 ICLASSERT_RETURN(!isNull()); 00278 utils::Mutex::Locker l(m_mutex); 00279 m_poGrabber->useDesired(d, size, fmt); 00280 } 00281 00283 00284 template<class T> 00285 void ignoreDesired() { 00286 ICLASSERT_RETURN(!isNull()); 00287 utils::Mutex::Locker l(m_mutex); 00288 m_poGrabber->ignoreDesired<T>(); 00289 } 00290 00292 void ignoreDesired(){ 00293 ICLASSERT_RETURN(!isNull()); 00294 utils::Mutex::Locker l(m_mutex); 00295 m_poGrabber->ignoreDesired(); 00296 } 00297 00299 00300 template<class T> 00301 T getDesired() const { 00302 ICLASSERT_RETURN_VAL(!isNull(), T()); 00303 utils::Mutex::Locker l(m_mutex); 00304 return m_poGrabber->getDesired<T>(); 00305 } 00306 00308 void enableUndistortion(const std::string &filename){ 00309 ICLASSERT_RETURN(!isNull()); 00310 utils::Mutex::Locker l(m_mutex); 00311 m_poGrabber->enableUndistortion(filename); 00312 } 00313 00315 void enableUndistortion(const ImageUndistortion &udist){ 00316 ICLASSERT_RETURN(!isNull()); 00317 utils::Mutex::Locker l(m_mutex); 00318 m_poGrabber->enableUndistortion(udist); 00319 } 00320 00322 00323 void enableUndistortion(const utils::ProgArg &pa){ 00324 ICLASSERT_RETURN(!isNull()); 00325 utils::Mutex::Locker l(m_mutex); 00326 m_poGrabber->enableUndistortion(pa); 00327 } 00328 00330 void enableUndistortion(const core::Img32f &warpMap){ 00331 ICLASSERT_RETURN(!isNull()); 00332 utils::Mutex::Locker l(m_mutex); 00333 m_poGrabber->enableUndistortion(warpMap); 00334 } 00335 00337 00340 void setUndistortionInterpolationMode(core::scalemode mode){ 00341 ICLASSERT_RETURN(!isNull()); 00342 utils::Mutex::Locker l(m_mutex); 00343 m_poGrabber->setUndistortionInterpolationMode(mode); 00344 } 00345 00347 void disableUndistortion(){ 00348 ICLASSERT_RETURN(!isNull()); 00349 utils::Mutex::Locker l(m_mutex); 00350 m_poGrabber->disableUndistortion(); 00351 } 00352 00354 bool isUndistortionEnabled() const{ 00355 ICLASSERT_RETURN_VAL(!isNull(),false); 00356 utils::Mutex::Locker l(m_mutex); 00357 return m_poGrabber->isUndistortionEnabled(); 00358 } 00359 00361 const core::Img32f *getUndistortionWarpMap() const{ 00362 ICLASSERT_RETURN_VAL(!isNull(),0); 00363 utils::Mutex::Locker l(m_mutex); 00364 return m_poGrabber->getUndistortionWarpMap(); 00365 } 00366 00368 00375 static const std::vector<GrabberDeviceDescription> &getDeviceList(const std::string &filter, bool rescan=true); 00376 00378 00379 inline void init(const GrabberDeviceDescription &dev){ 00380 init(dev.type,dev.type+"="+dev.id,false); 00381 } 00382 }; 00383 00384 } // namespace io 00385 } 00386