www.pudn.com > hbp0.1.zip > classmotion.cpp


/***************************************************************************
                          classmotion.h

  Produces a motion image

    begin                : Sat Nov 23 2002
    copyright            : (C) 2002 by Bob Mottram
    email                : fuzzgun@btinternet.com
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include 
#include "classimage.h"
#include "classmotion.h"

//------------------------------------------------------------------------------------------------------------------------
//  constructor
//------------------------------------------------------------------------------------------------------------------------
classmotion::classmotion()
{
  initialised=false;
  threshold=0;
  enableSecondaryUpdate=false; 
  firstTime=true;
}


//------------------------------------------------------------------------------------------------------------------------
//  destructor
//------------------------------------------------------------------------------------------------------------------------
classmotion::~classmotion()
{
}


//------------------------------------------------------------------------------------------------------------------------
//  initialise
//------------------------------------------------------------------------------------------------------------------------
void classmotion::init()
{
  int x,y;

  image2 = new unsigned char**[width]; 
  for (x=0;xthreshold) 
      { 
        if (dp>255) dp=255; 
        for (c=0;c<3;c++) image[x][y][c] = dp; 
      } 
      else 
        for (c=0;c<3;c++) image[x][y][c] = 0; 
 
      av += image[x][y][0]; 
    } 
  } 
 
  totMotion /= width * height; 
 
  min_thresh = (int)(totMotion * 3); //5 
  for (x=0;ximage,img->width,img->height);
}

//------------------------------------------------------------------------------------------------------------------------
//  secondary update phase
//------------------------------------------------------------------------------------------------------------------------
void classmotion::update_secondary(unsigned char ***img)
{
  int x,y,c;

  if ((initialised) && (enableSecondaryUpdate))
  {
    for (x=0;x