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 : ICLQt/src/ICLQt/Quick.h ** 00010 ** Module : ICLQt ** 00011 ** Authors: Christof Elbrechter ** 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 <ICLCore/Img.h> 00034 #include <ICLUtils/StringUtils.h> 00035 #include <ICLUtils/Exception.h> 00036 00037 namespace icl{ 00038 namespace utils{} 00039 namespace math{} 00040 namespace core{} 00041 namespace filter{} 00042 namespace io{} 00043 namespace qt{} 00044 namespace geom{} 00045 namespace cv{} 00046 namespace markers{} 00047 } 00048 using namespace icl; 00049 using namespace icl::utils; 00050 using namespace icl::math; 00051 using namespace icl::core; 00052 using namespace icl::filter; 00053 using namespace icl::io; 00054 using namespace icl::qt; 00055 using namespace icl::geom; 00056 using namespace icl::cv; 00057 using namespace icl::markers; 00058 00060 using namespace std; 00061 00063 namespace icl{ 00064 namespace qt{ 00065 00066 #ifdef HAVE_QT 00067 00068 00069 std::string openFileDialog(const std::string &filter="", 00070 const std::string &caption="open file", 00071 const std::string &initialDirectory="", 00072 void *parentWidget=0) throw (utils::ICLException); 00073 00075 00076 std::string saveFileDialog(const std::string &filter="", 00077 const std::string &caption="save file", 00078 const std::string &initialDirectory="", 00079 void *parentWidget=0) throw (utils::ICLException); 00080 00082 00083 std::string execute_process(const std::string &command); 00084 #endif 00085 00086 #define ICL_QUICK_DEPTH depth32f 00087 #define ICL_QUICK_TYPE icl32f 00088 00089 00091 typedef core::Img<ICL_QUICK_TYPE> ImgQ; 00092 00094 /* {{{ open */ 00096 00100 template<class T> 00101 core::Img<T> zeros(int width, int height, int channels=1); 00102 00103 /***/ 00104 inline ImgQ zeros(int width, int height, int channels=1){ 00105 return zeros<ICL_QUICK_TYPE>(width,height,channels); 00106 } 00107 00108 00110 00114 template<class T> 00115 core::Img<T> ones(int width, int height, int channels=1); 00116 00118 inline ImgQ ones(int width, int height, int channels=1){ return ones<ICL_QUICK_TYPE>(width,height,channels); } 00121 00122 00124 template<class T> 00125 core::Img<T> load(const std::string &filename); 00126 00128 inline ImgQ load(const std::string &filename) { return load<ICL_QUICK_TYPE>(filename); } 00131 00132 00135 template<class T> 00136 core::Img<T> load(const std::string &filename, core::format fmt); 00137 00139 inline ImgQ load(const std::string &filename, core::format fmt) { return load<ICL_QUICK_TYPE>(filename,fmt); } 00142 00143 00148 template<class T> 00149 core::Img<T> create(const std::string &name, core::format fmt=formatRGB); 00150 00152 inline ImgQ create(const std::string &name, core::format fmt=formatRGB) { return create<ICL_QUICK_TYPE>(name,fmt); } 00155 00156 00163 template<class T> 00164 core::Img<T> grab(const std::string &dev, const std::string &devSpec, 00165 const utils::Size &size=utils::Size::null, core::format fmt=formatRGB, 00166 bool releaseGrabber=false); 00167 00169 inline ImgQ grab(const std::string &dev, const std::string &devSpec, 00170 const utils::Size &size=utils::Size::null, core::format fmt=formatRGB, 00171 bool releaseGrabber=false){ 00172 return grab<ICL_QUICK_TYPE>(dev,devSpec,size,fmt,releaseGrabber); 00173 } 00177 /* }}} */ 00178 00180 /* {{{ open */ 00181 00183 00186 core::Img8u cvt8u(const ImgQ &image); 00187 00189 00192 core::Img16s cvt16s(const ImgQ &image); 00193 00195 00198 core::Img32s cvt32s(const ImgQ &image); 00199 00201 00204 core::Img32f cvt32f(const ImgQ &image); 00205 00207 00210 core::Img64f cvt64f(const ImgQ &image); 00211 00213 00216 ImgQ cvt(const core::Img8u &image); 00217 00219 00220 00223 ImgQ cvt(const core::Img16s &image); 00224 00226 00229 ImgQ cvt(const core::Img32s &image); 00230 00232 00236 ImgQ cvt(const core::Img32f &image); 00237 00239 00242 ImgQ cvt(const core::Img64f &image); 00245 00246 00249 ImgQ cvt(const core::ImgBase *image); 00250 00251 00253 00256 ImgQ cvt(const core::ImgBase &image); 00258 /* }}} */ 00259 00261 /* {{{ open */ 00262 00264 00269 template<class T> 00270 core::Img<T> filter(const core::Img<T> &image, const std::string &filter); 00271 00273 inline ImgQ filter(const ImgQ &image, const std::string &filter){ 00274 return icl::qt::filter<float>(image,filter); 00275 } 00278 00279 00280 template<class T> 00281 core::Img<T> blur(const core::Img<T> &image, int maskRadius=1); 00282 00284 inline ImgQ blur(const ImgQ &image, int maskRadius=1){ 00285 return icl::qt::blur<float>(image,maskRadius); 00286 } 00289 00290 00293 ImgQ cc(const ImgQ& image, core::format fmt); 00294 00296 00297 ImgQ rgb(const ImgQ &image); 00298 00300 00301 ImgQ hls(const ImgQ &image); 00302 00304 00305 ImgQ lab(const ImgQ &image); 00306 00308 00309 ImgQ gray(const ImgQ &image); 00310 00312 00315 ImgQ scale(const ImgQ& image, float factor); 00316 00318 00322 ImgQ scale(const ImgQ& image, int width, int height); 00323 00325 00328 ImgQ channel(const ImgQ &image,int channel); 00329 00331 00337 ImgQ levels(const ImgQ &image, icl8u levels); 00338 00340 00343 ImgQ thresh(const ImgQ &image, float threshold); 00344 00346 00347 template<class T> 00348 core::Img<T> copy(const core::Img<T> &image); 00349 00351 00352 template <class T> 00353 core::Img<T> copyroi(const core::Img<T> &image); 00354 00356 00357 template<class T> 00358 core::Img<T> norm(const core::Img<T> &image); 00359 00361 00362 ImgQ flipx(const ImgQ& image); 00363 00365 00366 ImgQ flipy(const ImgQ& image); 00367 00369 /* }}} */ 00370 00372 /* {{{ open */ 00373 00375 00378 void save(const core::ImgBase &image, const std::string &filename); 00379 00381 00388 void show(const ImgBase &image); 00389 00391 00402 void showSetup(const string &showCommand="xv %s", const string &rmCommand="rm -rf %s", int msecBeforeDelete=500); 00403 00405 00406 template<class T> 00407 void print(const core::Img<T> &image); 00408 00410 /* }}} */ 00411 00413 /* {{{ open */ 00414 00416 00419 ImgQ operator+(const ImgQ &a, const ImgQ &b); 00420 00422 00425 ImgQ operator-(const ImgQ &a, const ImgQ &b); 00426 00428 00431 ImgQ operator*(const ImgQ &a, const ImgQ &b); 00432 00434 00437 ImgQ operator/(const ImgQ &a, const ImgQ &b); 00438 00440 00443 ImgQ operator+(const ImgQ &image, float val); 00444 00446 00449 ImgQ operator-(const ImgQ &image, float val); 00450 00452 00455 ImgQ operator*(const ImgQ &image, float val); 00456 00458 00461 ImgQ operator/(const ImgQ &image, float val); 00462 00464 00467 ImgQ operator+(float val, const ImgQ &image); 00468 00470 00473 ImgQ operator-(float val, const ImgQ &image); 00474 00476 00479 ImgQ operator*(float val, const ImgQ &image); 00480 00482 00485 ImgQ operator/(float val, const ImgQ &image); 00486 00488 00489 ImgQ operator-(const ImgQ &image); 00490 00492 /* }}} */ 00493 00495 /* {{{ open */ 00496 00498 00499 ImgQ exp(const ImgQ &image); 00500 00502 00503 ImgQ ln(const ImgQ &image); 00504 00506 00507 ImgQ sqr(const ImgQ &image); 00508 00510 00511 ImgQ sqrt(const ImgQ &image); 00512 00514 00515 ImgQ abs(const ImgQ &image); 00516 00518 /* }}} */ 00519 00521 /* {{{ open */ 00522 00523 00525 00528 ImgQ operator||(const ImgQ &a, const ImgQ &b); 00529 00531 00534 ImgQ operator&&(const ImgQ &a, const ImgQ &b); 00535 00537 template<class T> 00538 ImgQ binOR(const ImgQ &a, const ImgQ &b); 00539 00541 template<class T> 00542 ImgQ binXOR(const ImgQ &a, const ImgQ &b); 00543 00545 template<class T> 00546 ImgQ binAND(const ImgQ &a, const ImgQ &b); 00547 00549 /* }}} */ 00550 00552 /* {{{ open */ 00553 00555 00572 ImgQ operator,(const ImgQ &a, const ImgQ &b); 00573 00575 00578 ImgQ operator%(const ImgQ &a, const ImgQ &b); 00579 00581 00585 ImgQ operator|(const ImgQ &a, const ImgQ &b); 00586 00588 /* }}} */ 00589 00591 /* {{{ open */ 00592 00593 00595 00596 struct ImgROI{ 00598 ImgQ image; 00599 00601 00602 ImgROI &operator=(const ImgQ &i); 00603 00605 00606 ImgROI &operator=(float val); 00607 00609 00610 ImgROI &operator=(const ImgROI &r); 00611 00613 operator ImgQ(); 00614 }; 00615 00617 00638 ImgROI roi(ImgQ &r); 00639 00641 00661 ImgROI data(ImgQ &r); 00662 00664 /* }}} */ 00665 00667 /* {{{ open */ 00668 00670 00675 void color(float r, float g=-1, float b=-1, float alpha=255); 00676 00678 00683 void fill(float r, float g=-1, float b=-1, float alpha=255); 00684 00686 00689 void colorinfo(float color[4], float fill[4]); 00690 00692 00696 void cross(ImgQ &image, int x, int y); 00697 00699 00702 inline void cross(ImgQ &image, const utils::Point &p) { cross(image,p.x,p.y); } 00703 00705 00712 void rect(ImgQ &image, int x, int y, int w, int h, int rounding=0); 00713 00715 00719 inline void rect(ImgQ &image, const utils::Rect &r, int rounding=0){ rect(image,r.x,r.y,r.width,r.height,rounding); } 00720 00722 00723 void triangle(ImgQ &image, int x1,int y1, int x2, int y2, int x3, int y3); 00724 00726 inline void triangle(ImgQ &image, const utils::Point &a, const utils::Point &b, const utils::Point &c){ 00727 triangle(image,a.x,a.y,b.x,b.y,c.x,c.y); 00728 } 00729 00731 00737 void line(ImgQ &image, int x1, int y1, int x2, int y2); 00738 00740 00744 inline void line(ImgQ &image, const utils::Point &p1, const utils::Point &p2){ line(image,p1.x,p1.y, p2.x,p2.y); } 00745 00747 00750 void linestrip(ImgQ &image, const std::vector<utils::Point> &pts, bool closeLoop=true); 00751 00753 void polygon(ImgQ &image, const std::vector<utils::Point> &corners); 00754 00756 00760 void pix(ImgQ &image, int x, int y); 00761 00763 00766 inline void pix(ImgQ &image, const utils::Point &p){ pix(image,p.x,p.y); } 00767 00769 00772 void pix(ImgQ &image, const vector<utils::Point> &pts); 00773 00775 00778 void pix(ImgQ &image, const vector<vector<utils::Point> > &pts); 00779 00781 00788 void circle(ImgQ &image, int x, int y, int r); 00789 00791 00798 void text(ImgQ &image, int x, int y,const string &text); 00799 00801 00807 inline void text(ImgQ &image, const utils::Point &p,const string &sText){ text(image,p.x,p.y,sText); } 00808 00810 00814 ImgQ label(const ImgQ &image, const string &text); 00815 00817 00820 void font(int size, const string &family="Arial"); 00821 00823 00824 void fontsize(int size); 00826 /* }}} */ 00827 00829 /* {{{ open */ 00830 00832 void tic(const std::string &label=""); 00833 00835 void toc(); 00837 /* }}} */ 00838 00839 } // namespace qt 00840 } 00841