示例#1
0
CBlob *CBlobResult::GetBlob(int indexblob)
{	
  if( indexblob < 0 || indexblob >= GetNumBlobs() )
    RaiseError( EXCEPTION_BLOB_OUT_OF_BOUNDS );

  return m_blobs[indexblob];
}
示例#2
0
/*
- FUNCTION: PrintBlobs
- FUNCTIONALITY: Prints some blob features in an ASCII file
- PARAMETERS:
- nom_fitxer: full path + filename to generate
- RESULT:
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
void CBlobResult::PrintBlobs( char *nom_fitxer ) const
{
  double_stl_vector area, /*perimetre,*/ exterior, mitjana, compacitat, longitud, 
    externPerimeter, perimetreConvex, perimetre;
  int i;
  FILE *fitxer_sortida;

  area      = GetSTLResult( CBlobGetArea());
  perimetre = GetSTLResult( CBlobGetPerimeter());
  exterior  = GetSTLResult( CBlobGetExterior());
  mitjana   = GetSTLResult( CBlobGetMean());
  compacitat = GetSTLResult(CBlobGetCompactness());
  longitud  = GetSTLResult( CBlobGetLength());
  externPerimeter = GetSTLResult( CBlobGetExternPerimeter());
  perimetreConvex = GetSTLResult( CBlobGetHullPerimeter());

  fitxer_sortida = fopen( nom_fitxer, "w" );

  for(i=0; i<GetNumBlobs(); i++)
  {
    fprintf( fitxer_sortida, "blob %d ->\t a=%7.0f\t p=%8.2f (%8.2f extern)\t pconvex=%8.2f\t ext=%.0f\t m=%7.2f\t c=%3.2f\t l=%8.2f\n",
      i, area[i], perimetre[i], externPerimeter[i], perimetreConvex[i], exterior[i], mitjana[i], compacitat[i], longitud[i] );
  }
  fclose( fitxer_sortida );

}
示例#3
0
/**
- FUNCTION: Filter (const version)
- FUNCTIONALITY: Get some blobs from the class based on conditions on measures
				 of the blobs.
- PARAMETERS:
	- dst: where to store the selected blobs
	- filterAction:	B_INCLUDE: include the blobs which pass the filter in the result
				    B_EXCLUDE: exclude the blobs which pass the filter in the result
	- evaluador: Object to evaluate the blob
	- Condition: How to decide if  the result returned by evaluador on each blob
				 is included or not. It can be:
				    B_EQUAL,B_NOT_EQUAL,B_GREATER,B_LESS,B_GREATER_OR_EQUAL,
				    B_LESS_OR_EQUAL,B_INSIDE,B_OUTSIDE
	- LowLimit:  numerical value to evaluate the Condition on evaluador(blob)
	- HighLimit: numerical value to evaluate the Condition on evaluador(blob).
				 Only useful for B_INSIDE and B_OUTSIDE
- RESULT:
	- It returns on dst the blobs that accomplish (B_INCLUDE) or discards (B_EXCLUDE)
	  the Condition on the result returned by evaluador on each blob
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
void CBlobResult::Filter(CBlobResult &dst,
						 int filterAction,
						 funcio_calculBlob *evaluador,
						 int condition,
						 double lowLimit, double highLimit /*=0*/)

{
	int numBlobs = GetNumBlobs();

	// do the job
	DoFilter(dst, filterAction, evaluador, condition, lowLimit, highLimit );

	// inline operation: remove previous blobs
	if( &dst == this )
	{
		// esborrem els primers blobs ( que són els originals )
		// ja que els tindrem replicats al final si passen el filtre
		Blob_vector::iterator itBlobs = m_blobs.begin();
		for( int i = 0; i < numBlobs; i++ )
		{
			delete *itBlobs;
			itBlobs++;
		}
		m_blobs.erase( m_blobs.begin(), itBlobs );
	}
}
示例#4
0
/**
- FUNCTION: Assigment operator
- FUNCTIONALITY: 
- PARAMETERS:
- RESULT:
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
CBlobResult& CBlobResult::operator=(const CBlobResult& source)
{
  // si ja són el mateix, no cal fer res
  if (this != &source)
  {
    // alliberem el conjunt de blobs antic
    for( int i = 0; i < GetNumBlobs(); i++ )
    {
      delete m_blobs[i];
    }
    m_blobs.clear();
    // creem el nou a partir del passat com a paràmetre
    m_blobs = blob_vector( source.GetNumBlobs() );
    // copiem els blobs de l'origen a l'actual
    blob_vector::const_iterator pBlobsSrc = source.m_blobs.begin();
    blob_vector::iterator pBlobsDst = m_blobs.begin();

    while( pBlobsSrc != source.m_blobs.end() )
    {
      // no podem cridar a l'operador = ja que blob_vector és un 
      // vector de CBlob*. Per tant, creem un blob nou a partir del
      // blob original
      *pBlobsDst = new CBlob(**pBlobsSrc);
      pBlobsSrc++;
      pBlobsDst++;
    }
  }
  return *this;
}
示例#5
0
/*
- FUNCTION: GetNthBlob
- FUNCTIONALITY: Gets the n-th blob ordering first the blobs with some criteria
- PARAMETERS:
    - criteri: criteria to order the blob array
    - nBlob: index of the returned blob in the ordered blob array
    - dst: where to store the result
- RESULT:
- RESTRICTIONS:
- AUTHOR: Ricard Borr�s
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
void CBlobResult::GetNthBlob( funcio_calculBlob* criteri, int nBlob, CBlob& dst ) const
{
    // verifiquem que no estem accedint fora el vector de blobs
    if ( nBlob < 0 || nBlob >= GetNumBlobs() )
    {
        //RaiseError( EXCEPTION_BLOB_OUT_OF_BOUNDS );
        dst = CBlob();
        return;
    }

    double_stl_vector avaluacioBlobs, avaluacioBlobsOrdenat;
    double valorEnessim;

    //avaluem els blobs amb la funci� pertinent
    avaluacioBlobs = GetSTLResult(criteri);

    avaluacioBlobsOrdenat = double_stl_vector( GetNumBlobs() );

    // obtenim els nBlob primers resultats (en ordre descendent)
    std::partial_sort_copy( avaluacioBlobs.begin(),
                            avaluacioBlobs.end(),
                            avaluacioBlobsOrdenat.begin(),
                            avaluacioBlobsOrdenat.end(),
                            std::greater<double>() );

    valorEnessim = avaluacioBlobsOrdenat[nBlob];

    // busquem el primer blob que t� el valor n-ssim
    double_stl_vector::const_iterator itAvaluacio = avaluacioBlobs.begin();

    bool trobatBlob = false;
    int  indexBlob  = 0;

    while ( itAvaluacio != avaluacioBlobs.end() && !trobatBlob )
    {
        if ( *itAvaluacio == valorEnessim )
        {
            trobatBlob = true;
            dst        = CBlob( GetBlob(indexBlob));
        }

        ++itAvaluacio;
        ++indexBlob;
    }
}
示例#6
0
/*
- FUNCTION: GetBlob
- FUNCTIONALITY: Gets the n-th blob (without ordering the blobs)
- PARAMETERS:
    - indexblob: index in the blob array
- RESULT:
- RESTRICTIONS:
- AUTHOR: Ricard Borr�s
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
CBlob CBlobResult::GetBlob(int indexblob) const
{
    if ( indexblob < 0 || indexblob >= GetNumBlobs() )
    {
        RaiseError( EXCEPTION_BLOB_OUT_OF_BOUNDS );
    }

    return *m_blobs[indexblob];
}
示例#7
0
/**
- FUNCTION: GetNumber
- FUNCTIONALITY: Computes the function evaluador on a blob of the class
- PARAMETERS:
    - indexBlob: index of the blob to compute the function
    - evaluador: function to apply to each blob (any object derived from the
                 COperadorBlob class )
- RESULT:
- RESTRICTIONS:
- AUTHOR: Ricard Borr�s
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
double CBlobResult::GetNumber( int indexBlob, funcio_calculBlob* evaluador ) const
{
    if ( indexBlob < 0 || indexBlob >= GetNumBlobs() )
    {
        RaiseError( EXCEPTION_BLOB_OUT_OF_BOUNDS );
    }

    return (*evaluador)( *m_blobs[indexBlob] );
}
示例#8
0
/**
- FUNCTION: GetResult
- FUNCTIONALITY: Computes the function evaluador on all the blobs of the class
and returns a vector with the result
- PARAMETERS:
- evaluador: function to apply to each blob (any object derived from the 
COperadorBlob class )
- RESULT:
- vector with all the results in the same order as the blobs
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
double_stl_vector CBlobResult::GetSTLResult( funcio_calculBlob *evaluador ) const
{
  if( GetNumBlobs() <= 0 )
  {
    return double_stl_vector();
  }

  // definim el resultat
  double_stl_vector result = double_stl_vector( GetNumBlobs() );
  // i iteradors sobre els blobs i el resultat
  double_stl_vector::iterator itResult = result.begin();
  blob_vector::const_iterator itBlobs = m_blobs.begin();

  // avaluem la funció en tots els blobs
  while( itBlobs != m_blobs.end() )
  {
    *itResult = (*evaluador)(**itBlobs);
    itBlobs++;
    itResult++;
  }
  return result;
}
示例#9
0
/**
- FUNCTION: Filter
- FUNCTIONALITY: Get some blobs from the class based on conditions on measures
of the blobs. 
- PARAMETERS:
- dst: where to store the selected blobs
- filterAction:	B_INCLUDE: include the blobs which pass the filter in the result 
B_EXCLUDE: exclude the blobs which pass the filter in the result 
- evaluador: Object to evaluate the blob
- Condition: How to decide if  the result returned by evaluador on each blob
is included or not. It can be:
B_EQUAL,B_NOT_EQUAL,B_GREATER,B_LESS,B_GREATER_OR_EQUAL,
B_LESS_OR_EQUAL,B_INSIDE,B_OUTSIDE
- LowLimit:  numerical value to evaluate the Condition on evaluador(blob)
- HighLimit: numerical value to evaluate the Condition on evaluador(blob).
Only useful for B_INSIDE and B_OUTSIDE
- RESULT:
- It returns on dst the blobs that accomplish (B_INCLUDE) or discards (B_EXCLUDE)
the Condition on the result returned by evaluador on each blob
- RESTRICTIONS:
- AUTHOR: Ricard Borràs
- CREATION DATE: 25-05-2005.
- MODIFICATION: Date. Author. Description.
*/
void CBlobResult::Filter(CBlobResult &dst, 
  int filterAction, 
  funcio_calculBlob *evaluador, 
  int condition, 
  double lowLimit, double highLimit /*=0*/)

{
  int i, numBlobs;
  bool resultavaluacio;
  double_stl_vector avaluacioBlobs;
  double_stl_vector::iterator itavaluacioBlobs;

  if( GetNumBlobs() <= 0 ) return;
  if( !evaluador ) return;
  //avaluem els blobs amb la funció pertinent	
  avaluacioBlobs = GetSTLResult(evaluador);
  itavaluacioBlobs = avaluacioBlobs.begin();
  numBlobs = GetNumBlobs();
  switch(condition)
  {
  case B_EQUAL:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs == lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }				
    }
    break;
  case B_NOT_EQUAL:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio = *itavaluacioBlobs != lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_GREATER:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs > lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_LESS:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs < lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_GREATER_OR_EQUAL:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs>= lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_LESS_OR_EQUAL:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio= *itavaluacioBlobs <= lowLimit;
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_INSIDE:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio=( *itavaluacioBlobs >= lowLimit) && ( *itavaluacioBlobs <= highLimit); 
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  case B_OUTSIDE:
    for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
    {
      resultavaluacio=( *itavaluacioBlobs < lowLimit) || ( *itavaluacioBlobs > highLimit); 
      if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
        ( !resultavaluacio && filterAction == B_EXCLUDE ))
      {
        dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
      }
    }
    break;
  }


  // en cas de voler filtrar un CBlobResult i deixar-ho en el mateix CBlobResult
  // ( operacio inline )
  if( &dst == this ) 
  {
    // esborrem els primers blobs ( que són els originals )
    // ja que els tindrem replicats al final si passen el filtre
    blob_vector::iterator itBlobs = m_blobs.begin();
    for( int i = 0; i < numBlobs; i++ )
    {
      delete *itBlobs;
      itBlobs++;
    }
    m_blobs.erase( m_blobs.begin(), itBlobs );
  }
}
示例#10
0
//! Does the Filter method job
void CBlobResult::DoFilter(CBlobResult &dst, int filterAction, funcio_calculBlob *evaluador,
						   int condition, double lowLimit, double highLimit/* = 0*/) const
{
	int i, numBlobs;
	bool resultavaluacio;
	double_stl_vector avaluacioBlobs;
	double_stl_vector::iterator itavaluacioBlobs;

	if( GetNumBlobs() <= 0 ) return;
	if( !evaluador ) return;
	//avaluem els blobs amb la funció pertinent
	avaluacioBlobs = GetSTLResult(evaluador);
	itavaluacioBlobs = avaluacioBlobs.begin();
	numBlobs = GetNumBlobs();
	switch(condition)
	{
		case B_EQUAL:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs == lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_NOT_EQUAL:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio = *itavaluacioBlobs != lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_GREATER:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs > lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_LESS:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs < lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_GREATER_OR_EQUAL:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs>= lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_LESS_OR_EQUAL:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio= *itavaluacioBlobs <= lowLimit;
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_INSIDE:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio=( *itavaluacioBlobs >= lowLimit) && ( *itavaluacioBlobs <= highLimit);
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
		case B_OUTSIDE:
			for(i=0;i<numBlobs;i++, itavaluacioBlobs++)
			{
				resultavaluacio=( *itavaluacioBlobs < lowLimit) || ( *itavaluacioBlobs > highLimit);
				if( ( resultavaluacio && filterAction == B_INCLUDE ) ||
					( !resultavaluacio && filterAction == B_EXCLUDE ))
				{
					dst.m_blobs.push_back( new CBlob( GetBlob( i ) ));
				}
			}
			break;
	}
}
示例#11
0
/*!
 * Draw all blobs onto given image.
 */
void BlobResult::draw(cv::Mat & image, CvScalar color, int offsetx, int offsety) {
    for(int i=0; i<GetNumBlobs(); i++)
    {
        m_blobs[i]->draw(image, color, offsetx, offsety);
    }
}