/******************************************************************** ** Image Component Library (ICL) ** ** ** ** Copyright (C) 2006-2013 CITEC, University of Bielefeld ** ** Neuroinformatics Group ** ** Website: www.iclcv.org and ** ** http://opensource.cit-ec.de/projects/icl ** ** ** ** File : ICLQt/apps/color-picker/color-picker.cpp ** ** Module : ICLQt ** ** Authors: Christof Elbrechter ** ** ** ** ** ** GNU LESSER GENERAL PUBLIC LICENSE ** ** This file may be used under the terms of the GNU Lesser General ** ** Public License version 3.0 as published by the ** ** ** ** Free Software Foundation and appearing in the file LICENSE.LGPL ** ** included in the packaging of this file. Please review the ** ** following information to ensure the license requirements will ** ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt ** ** ** ** The development of this software was supported by the ** ** Excellence Cluster EXC 277 Cognitive Interaction Technology. ** ** The Excellence Cluster EXC 277 is a grant of the Deutsche ** ** Forschungsgemeinschaft (DFG) in the context of the German ** ** Excellence Initiative. ** ** ** ********************************************************************/ #include #include #include VBox gui; GenericGrabber grabber; Mutex mtex; struct XC{ XC(float a=0,float b=0,float d=0){ c[0] = a; c[1] = b; c[2] = d; } XC(const float *f){ c[0] = f[0]; c[1] = f[1]; c[2] = f[2]; } float c[3]; float &operator[](int i){return c[i]; } }; vector colorbuffer; void mouse(const MouseEvent &event){ Mutex::Locker lock(mtex); std::string colormode = gui["colormode"].as(); if(event.isPressEvent()){ const std::vector &c = event.getColor(); if(c.size() == 1){ printf("color: %d \n",(int)c[0]); }else if(c.size() > 2){ // Assertion ; input type is rgb!! if(colormode == "rgb"){ printf("rgb: %d %d %d \n",(int)c[0],(int)c[1],(int)c[2]); colorbuffer.push_back(XC(c[0],c[1],c[2])); }else if (colormode == "hls"){ icl32f hls[3]; cc_util_rgb_to_hls (c[0],c[1],c[2],hls[0],hls[1],hls[2]); printf("hls: %d %d %d \n",(int)hls[0],(int)hls[1],(int)hls[2]); colorbuffer.push_back(XC(hls)); } else if (colormode == "yuv"){ icl32s yuv[3]; cc_util_rgb_to_yuv ((int)c[0],(int)c[1],(int)c[2],yuv[0],yuv[1],yuv[2]); printf("yuv: %d %d %d \n",yuv[0],(int)yuv[1],(int)yuv[2]); colorbuffer.push_back(XC(yuv[0],yuv[1],yuv[2])); } else if(colormode == "gray"){ printf("gray: %d \n",(int)((c[0]+c[1]+c[2])/3)); } else{ printf("error color mode is (%s) \n",colormode.c_str()); } } } } void reset_list(){ Mutex::Locker lock(mtex); colorbuffer.clear(); printf("cleared! \n----------------------------------------\n"); } void calc_mean(){ Mutex::Locker lock(mtex); if(!colorbuffer.size()){ return; } XC xM,xV; for(unsigned int i=0;i()){ Thread::sleep(0.1); } gui["image"] = grabber.grab(); } int main(int n,char **ppc){ return ICLApplication(n,ppc,"[m]-input|-i(device,device-params)",init,run).exec(); }