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


/*************************************************************************** 
                          classColourClassifier.cpp 
 
  Used to classify the type and distribution of colours.  This is used for 
  classifying people's clothing 
 
  Comments are included in machine readable XML format, for possible future  
  production of program documentation 
 
    begin                : Thu Feb 19 2004 
    copyright            : (C) 2004 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 "stdafx.h" 
 
///  
/// Constructor 
///  
classColourClassifier::classColourClassifier() 
{ 
  clear(); 
} 
 
///  
/// Destructor 
///  
classColourClassifier::~classColourClassifier() 
{ 
} 
 
 
///  
/// Clear all data 
///  
void classColourClassifier::clear() 
{ 
  NoOfGroups=0; 
  top_x = 99999; 
  top_y = 99999; 
  bottom_x = 0; 
  bottom_y = 0; 
  tollerance=50; 
  total_pixels=0; 
  sorted=false; 
} 
 
 
 
///  
/// Sort the colours based upon the number of hits 
///  
void classColourClassifier::sort() 
{ 
  int i,j,max,winner,temp[5]; 
 
  for (i=0;i max) 
	  { 
	    max = colour_group[i][3]; 
		winner=j; 
	  } 
	} 
 
	if (winner>-1) 
	{ 
	  //swap 
	  for (j=0;j<5;j++) 
	  { 
	    temp[j] = colour_group[i][j]; 
        colour_group[i][j] = colour_group[winner][j]; 
		colour_group[winner][j] = temp[j]; 
	  } 
	} 
  } 
 
  sorted=true; 
} 
 
 
///  
/// Update 
///  
/// red component of the detected colour 
/// green component of the detected colour 
/// blue component of the detected colour 
/// x coordinate of the detected colour blob 
/// y coordinate of the detected colour blob 
void classColourClassifier::update(int r, int g, int b, int x, int y) 
{ 
  int i,dist,r2,g2,b2; 
  bool found; 
  long hits; 
 
  if (xbottom_x) bottom_x = x; 
  if (y>bottom_y) bottom_y = y; 
 
  i=0; 
  found=false; 
  while ((i 
/// Returns the data for a colour group, and its coverage in the range 0-100 
///  
/// An index number for the colour group 
/// Returned red component of the colour group 
/// Returned green component of the colour group 
/// Returned blue component of the colour group 
/// The size of the blob compared to the image, in the range 0-100 
void classColourClassifier::getGroupColour(int index, int &r, int &g, int &b, int &coverage) 
{ 
  long hits; 
 
  if (index