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

motion_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 <motion_Filter.h>
00037 
00038 #include <phError.h>
00039 #include <phMemory.h>
00040 #include <phPrint.h>
00041 
00042 /* ---------------------------------------------------------------------- */
00043 motion_Filter::motion_Filter() :
00044     phFilter("motion_Filter")
00045 
00046 {
00047     this->m_format = phImagePackedFormatMask;
00048 
00049     this->m_lastimg     = NULL;
00050     this->m_lastimgSize = 0;
00051     this->m_output      = NULL;
00052     this->m_outputSize  = 0;
00053 }
00054 
00055 /* ---------------------------------------------------------------------- */
00056 motion_Filter::~motion_Filter()
00057 {
00058     phFree(this->m_lastimg);
00059     phFree(this->m_output);
00060 }
00061 
00062 /* ------------------------------------------------------------------------ */
00063 phFilter *motion_Filter::cloneFilter()
00064 {
00065     return (phFilter *)new motion_Filter();
00066 }
00067 
00068 /* ---------------------------------------------------------------------- */
00069 int motion_Filter::filter() 
00070 { 
00071     phFUNCTION("motion_Filter::filter")
00072     
00073     const int32_t   threshold   = 40;
00074     uint32_t        i           = 0;
00075     uint32_t        d           = 0;
00076     uint8_t        *outptr      = NULL;
00077     uint8_t        *lastptr     = NULL;
00078     uint8_t        *imgptr      = NULL;
00079     const uint32_t  limit       = width * height;
00080     const uint32_t  size        = width * height * depth;
00081     int32_t         totalDiff   = 0;            
00082     int32_t         diff        = 0;
00083     
00084     /* check buffer allocations */
00085     phDALLOC_RESIZE(this->m_output,
00086                     this->m_outputSize,
00087                     size,
00088                     uint8_t);
00089     /* We don't want the image erased... unless maybe the dimensions change */
00090     phDALLOC_RESIZE(this->m_lastimg,
00091                     this->m_lastimgSize,
00092                     size,
00093                     uint8_t);
00094 
00095     /* Begin filter */
00096     imgptr = Image;
00097     outptr = this->m_output;
00098     lastptr = this->m_lastimg;
00099 
00100     for (i = 0, totalDiff = 0; i < limit; ++i, outptr += depth, totalDiff = 0 )
00101     {
00102         /* Calculate the total difference across the pixel channels */
00103         for (d = 0; d < depth; ++d, ++imgptr, ++lastptr)
00104         {
00105             diff = (int32_t)*imgptr - (int32_t)*lastptr;
00106             if (diff < 0) diff *= -1;
00107             totalDiff += diff;
00108         }
00109         
00110         /* if the average difference across the channels  > threshold,
00111          * the set the pixel, otherwise clear it */
00112         if ((totalDiff / (int32_t)depth) > threshold)
00113             phMemset(outptr,255,depth);
00114         else
00115             phMemset(outptr,0,depth);
00116     }
00117     
00118     phMemcpy(this->m_lastimg,(void *)(Image), size );
00119     phMemcpy((void *)(Image), this->m_output, size );
00120 
00121     return phSUCCESS;
00122 error:
00123     return phFAIL;
00124 }
00125 
00126 




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:11 2007 for phission by  doxygen 1.4.4