⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clabel.cpp

📁 face recognition test source code
💻 CPP
字号:
#include "header.h"
#include "clabel.h"

CLabel::CLabel()
	{   
   label = NULL;
	num_label = 0;
	num_alloc_label = 0;
	}

CLabel::~CLabel()
	{   
	if (label != NULL)
		free(label);
	}

/*********************************************************************************************
* Set the data_entry *current as belonging to the class named str_label
* It creates a table assigning a number, which will be used in the LVQ processing, to each single
* class.
*********************************************************************************************/
int CLabel::SetLabel(struct data_entry *current, char *str_label)
	{
	int i;
	
	/*try to find the matching label*/
	for (i = 0; i < num_label; i++)
		{
		if (strnicmp((label[i]).str, str_label, min(sizeof((label[i]).str), strlen(str_label))) 
				== 0)
			break;
		}
		
	if (!((i == 0 && label != NULL) || (i < num_label)))
		{ /*current belongs to a new class, a new entry in the label table has to be created*/
		if (num_label >= num_alloc_label)
			{ /*need to allocate memory*/
			if (num_label == 0)
				{ /*for the first time*/
				num_alloc_label = LABEL_INIT;
				label = (PLABEL)calloc(num_alloc_label, sizeof(LAB));
				if (label == NULL)
					return -1;
				}
			else
				{ /*next times*/
				num_alloc_label += LABEL_INC;
				label = (PLABEL)realloc(label, num_alloc_label*sizeof(LAB));
				if (label == NULL)
					return -1;
				}
			}
		strncpy((label[num_label]).str, str_label, sizeof((label[num_label]).str));
		num_label++;
		(label[num_label-1]).integer = num_label;
		}
	
	if (current != NULL)
		set_entry_label(current, (label[i]).integer);
	return (label[i]).integer;
	}

/*********************************************************************************************
* GetLabel gets the name of the class of the data_entry *current 
*********************************************************************************************/
char *CLabel::GetLabel(struct data_entry *current)
	{
	int i, val;
	
	if (label == NULL)
		return NULL;
	
	val = get_entry_label(current);
	for (i = 0; i < num_label; i++)
		{
		if ((label[i]).integer == val)
			break;
		}
	if (i < num_label)
		return (label[i]).str;
	else
		return NULL;
	}

int CLabel::GetLabelInt(char *str)
	{
	int i, val;
	
	if (label == NULL)
		return NULL;
	
	for (i = 0; i < num_label; i++)
		{
		if (strcmp((label[i]).str, str) == 0)
			return (label[i]).integer;
		}
   return -1;
	}

int CLabel::GetClassInt(int i)
	{
	if (label != NULL && i < num_label)
		return (label[i]).integer;
	return -1;
	}
	
char *CLabel::GetClassStr(int i)
	{
	if (label != NULL && i < num_label)
		return (label[i]).str;
	return NULL;
	}

int CLabel::NumClass()
	{return num_label;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -