// Analyzer.h: interface for the Analyzer class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_ANALYZER_H__16A23421_1475_4ACE_9984_DEB227EC978B__INCLUDED_)
#define AFX_ANALYZER_H__16A23421_1475_4ACE_9984_DEB227EC978B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

// maximum number of valid or invalid blobs at any one time
//  invalid blobs are pruned dynamically, but noise can still
//  lead to a large number of small CCs on one row
#define MAX_NUM_BLOBS      128

// maximum number of tracked objects at any one time
#define MAX_NUM_TOBS       32

// used in connected component finder -- in 2-pass algo,
//  one component can be found multiple times before it is
//  merged.  this value is the max number of such parts
#define MAX_CC_IDS         2048

#include "AbstractAnalyzer.h"

class BGModel;
class Blob;
class TrackedObject;

class Analyzer : public AbstractAnalyzer  
    {
public:
	Analyzer();
	virtual ~Analyzer();

   void Handle(PFrameData pdf);
   void OnStart(VIDEOINFOHEADER *pvih);   

protected:

   bool FindConnectedComponents(IplImage *pMask, IplImage *pLabels);
   bool FindBlobs(IplImage *pLabels, Blob **blobs, int *nBlobs, int minSize);
   bool ColorTob(IplImage *pImg, IplImage *pLabels, TrackedObject *tob, BYTE *color);
   bool MatchBlobsTobs(Blob **blobs, int nBlobs, TrackedObject **tobs, int *nTobs);
   bool BuildLabelImageFromMask(IplImage *pMask, IplImage *pLabels);
   virtual void Cleanup();

   IplImage *pFgMask, *pLabels;
   BGModel *bgm;
   POINTS *points;            // POINTS uses SHORT values and thus half the space
   int map[MAX_CC_IDS];
   Blob *blobs[MAX_NUM_BLOBS];
   int nBlobs;
   TrackedObject *tobs[MAX_NUM_TOBS];
   int nTobs;
};

#endif // !defined(AFX_ANALYZER_H__16A23421_1475_4ACE_9984_DEB227EC978B__INCLUDED_)
