Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

match_Filter.cpp

Go to the documentation of this file.
00001 /* ---------------------------------------------------------------------------
00002     Phission :
00003         Realtime Vision Processing System
00004 
00005     Copyright (C) 2003-2006 Philip D.S. Thoren (pthoren@cs.uml.edu)
00006     University of Massachusetts at Lowell,
00007     Laboratory for Artificial Intelligence and Robotics
00008 
00009  ---------------------------------------------------------------------------
00010     <Add other copyrights here> 
00011  ---------------------------------------------------------------------------
00012 
00013     This file is part of Phission.
00014 
00015     Phission is free software; you can redistribute it and/or modify
00016     it under the terms of the GNU Lesser General Public License as published by
00017     the Free Software Foundation; either version 2 of the License, or
00018     (at your option) any later version.
00019 
00020     Phission is distributed in the hope that it will be useful,
00021     but WITHOUT ANY WARRANTY; without even the implied warranty of
00022     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023     GNU Lesser General Public License for more details.
00024 
00025     You should have received a copy of the GNU Lesser General Public License
00026     along with Phission; if not, write to the Free Software
00027     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 
00029  ---------------------------------------------------------------------------*/
00030 #ifdef HAVE_CONFIG_H
00031     #include <phissionconfig.h>
00032 #endif
00033 
00034 #include <phStandard.h>
00035 
00036 #include <match_Filter.h>
00037 
00038 #include <phError.h>
00039 #include <phMemory.h>
00040 #include <phPrint.h>
00041 
00042 #define TIMESTUFF() 0
00043 
00044 /* ---------------------------------------------------------------------- */
00045 match_Filter::match_Filter() :
00046             phFilter("match_Filter")
00047 
00048 {
00049     set(0,0,0,0,0,0,0,phMatchOnly);
00050 }
00051 /* ---------------------------------------------------------------------- */
00052 /* match() - match pixels by tolerance*/
00053 /* ---------------------------------------------------------------------- */
00054 match_Filter::match_Filter(int r, int g, int b, 
00055             int tolerance, int outChannel, phMatchFormatEnum matchFormat ) :
00056             phFilter("match_Filter")
00057 
00058 {
00059     this->m_format = phImageRGB24;
00060 
00061     set(r,g,b,tolerance,outChannel);
00062 }
00063 
00064 /* ---------------------------------------------------------------------- */
00065 match_Filter::match_Filter(int lr, int lg,int lb,       
00066                       int hr, int hg, int hb,
00067                       int outChannel, phMatchFormatEnum matchFormat ) :
00068     phFilter("match_Filter")
00069 
00070 {
00071     set( lr,  lg, lb, hr,  hg,  hb, outChannel, matchFormat);
00072 }
00073 
00074 /* ---------------------------------------------------------------------- */
00075 match_Filter::~match_Filter()
00076 {
00077 }
00078 
00079 /* ------------------------------------------------------------------------ */
00080 phFilter *match_Filter::cloneFilter()
00081 {
00082     return (phFilter *)new match_Filter(this->m_lr,
00083                             this->m_lg,
00084                             this->m_lb,
00085                             this->m_hr,
00086                             this->m_hg,
00087                             this->m_hb,
00088                             this->m_outChannel,
00089                             this->m_matchFormat );
00090 }
00091 
00092 
00093 /* ---------------------------------------------------------------------- */
00094 int match_Filter::set(int lr, int lg,int lb,       
00095                       int hr, int hg, int hb,
00096                       int outChannel,
00097                       phMatchFormatEnum matchFormat )
00098 {
00099     this->m_lr = lr;
00100     this->m_lg = lg;
00101     this->m_lb = lb;
00102     this->m_hr = hr;
00103     this->m_hg = hg;
00104     this->m_hb = hb;
00105     this->m_outChannel = outChannel;
00106     this->m_matchFormat = matchFormat;
00107 
00108     return phSUCCESS;
00109 }
00110 
00111 /* ---------------------------------------------------------------------- */
00112 int match_Filter::set(int r, int g, int b, 
00113             int tolerance, int outChannel, phMatchFormatEnum matchFormat )
00114 {
00115     this->m_lr = r - tolerance;
00116     this->m_lg = g - tolerance;
00117     this->m_lb = b - tolerance;
00118     this->m_hr = r + tolerance;
00119     this->m_hg = g + tolerance;
00120     this->m_hb = b + tolerance;
00121     this->m_outChannel = outChannel;
00122     this->m_matchFormat = matchFormat;
00123 
00124     return phSUCCESS;
00125 }
00126 
00127 /* ---------------------------------------------------------------------- */
00128 int match_Filter::setMatchFormat( phMatchFormatEnum matchFormat )
00129 {
00130     this->m_matchFormat = matchFormat;
00131     return phSUCCESS;
00132 }
00133 /* ---------------------------------------------------------------------- */
00134 /* match() - match pixels by range*/
00135 /* outChannel can be RED, GREEN, BLUE, or phCHANNEL_ALL*/
00136 /* mode is either AND, OR, XOR, or ACCUM*/
00137 /* ---------------------------------------------------------------------- */
00138 int match_Filter::filter()
00139 {
00140     phFUNCTION("match_Filter::filter")
00141     
00142     unsigned int row = 0;
00143     unsigned int pixel = 0;
00144     
00145     unsigned int h,w = 0;
00146     unsigned int matches = 0;
00147     
00148 #if TIMESTUFF()
00149     const uint32_t nStamps = 1;
00150     char *tags[nStamps] = {
00151         "matching & output color adjust"
00152     };
00153     ph_time_db      timedb = NULL;
00154     rc = ph_timedb_alloc(&timedb,"match_Filter");
00155     phPRINT_RC(rc,NULL,"ph_timedb_alloc");
00156 #endif /* TIMESTUFF() */
00157 
00158 
00159     /* Begin filter */
00160     
00161 #if TIMESTUFF()
00162     rc = ph_timedb_start(timedb,tags[0]);
00163     phPRINT_RC(rc,NULL,"ph_timedb_start");
00164 #endif
00165     for( h = 0; h < height; h++ )
00166     {
00167         row = h * width;
00168         for( w = 0; w < width; w++ ) 
00169         {
00170             pixel = (row + w) * depth;
00171             if (
00172                     (this->m_lr == -1 || 
00173                      ((Image)[pixel + phCHANNEL_RED] >= this->m_lr && 
00174                       (Image)[pixel + phCHANNEL_RED] <= this->m_hr))
00175                     &&
00176                     (this->m_lg == -1 || 
00177                      ((Image)[pixel + phCHANNEL_GREEN] >= this->m_lg && 
00178                       (Image)[pixel + phCHANNEL_GREEN] <= this->m_hg))
00179                     &&
00180                     (this->m_lb == -1 ||
00181                      ((Image)[pixel + phCHANNEL_BLUE] >= this->m_lb && 
00182                       (Image)[pixel + phCHANNEL_BLUE] <= this->m_hb))
00183                     ) {
00184                 /* maybe add a normalizer here so the outputs are 
00185                  * between 100-255ish for more varied usage? */
00186                 matches++;
00187                 if (this->m_outChannel == phCHANNEL_ALL) {
00188                     phMemset((void *)&((Image)[pixel]), 255, depth);
00189                 } else {
00190                     phMemset((void *)&((Image)[pixel]), 0, depth);
00191                     (Image)[pixel + this->m_outChannel ] = 255;
00192                 }
00193             } else { /* no match*/
00194                 if (this->m_matchFormat == phMatchOnly)
00195                 {
00196                     phMemset((void *)&((Image)[pixel]), 0, depth);
00197                 }
00198                 /* else MATCH_OVERLAY == do nothing */
00199             }
00200         }
00201     }
00202 #if TIMESTUFF()
00203     rc = ph_timedb_stop(timedb);
00204     phPRINT_RC(rc,NULL,"ph_timedb_stop");
00205 #endif
00206 
00207 #if TIMESTUFF() /* phTIME_REPORT_ALL & */
00208     rc = ph_timedb_report( timedb, phTIME_REPORT_SUM );
00209     phPRINT_RC(rc,NULL,"ph_timedb_report");
00210     
00211     if (timedb)
00212     {
00213         rc = ph_timedb_free(&timedb);
00214         phPRINT_RC(rc,NULL,"ph_timedb_free");
00215     }
00216 #endif
00217     return matches;
00218 }
00219 
00220 




Copyright (C) 2002 - 2007 Philip D.S. Thoren ( pthoren@users.sourceforge.net )
University Of Massachusetts at Lowell
Robotics Lab
SourceForge.net Logo

Generated on Sat Jun 16 02:44:09 2007 for phission by  doxygen 1.4.4