/******************************************************************************
Copyright (C) 2005 Matteo Lucarelli 
                   Angelo Moro

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.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
******************************************************************************/

// WINDOWS NEED: -lcv -lhighgui -lcxcore
// LINUX NEED: -lcv -lhighgui -lcxcore

#if !defined(CVBLOBFINDER_H_INCLUDED)
#define CVBLOBFINDER_H_INCLUDED

#include <stdlib.h>
#include <opencv/cv.h>
#include <stdio.h>
#include <opencv/highgui.h>

typedef struct CvBlob
{
	int x;
	int y;
        int width;
        int height;
        double area;
}
CvBlob;

class cvBlobFinder
{
public:

	cvBlobFinder();
	virtual ~cvBlobFinder();

	// img = 8 bit unsigned grayscale image
	// threshold = limit value
	// minarea = minimum blobs area
	// mode = 0:blob=threshold, 1:blob>=threshold, -1:blob<=threshold
	// UseMask = don't modify image (blobs are draws on Mask)
	long FindBlobs(IplImage* img,uchar threshold,double minarea,int mode,bool UseMask);
	
	CvBlob* GetBlobs();	// NULL-teminated array of found blobs
	long GetBlobCount();
	IplImage* GetMask();

private:
	
	IplImage* m_Mask;
	long m_BlobCount;
	CvBlob* m_Blob;
	void Reset();
};

#endif // !defined(CVBLOBFINDER_H_INCLUDED)