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

📄 caam.cpp

📁 face recognition test source code
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		lvq.knn 			= 1;
		lvq.xdim			= 3;
		lvq.ydim			= 3;
		lvq.neigh		= NEIGH_GAUSSIAN;
		lvq.topol		= TOPOL_RECT;
		lvq.randomize	= 10;
		lvq.alpha_type	= ALPHA_INVERSE_T;
		lvq.radius		= 90;
		lvq.alpha		= 0.3;
		lvq.pdata		= pMetCmp;
		lvq.pcode		= NULL;
		
		eveninit(&lvq);
		lvq.length = 100;
		olvq1(&lvq);
		lvq.length = 1000;
		lvq1(&lvq);
		lvq.pdata = pCategorizeCmp;
		lvq.pconfusion = NULL;
		accuracy(&lvq);
		}
	else
		{	/*user defined categorization*/
		lvq.pcode = NULL;
		bSammon = FALSE;
		
		int i = 0;
		
		while(i < fs->num_cmd /*pcmd != NULL*/)
			{
			/*first : parameters*/
			PFILECMD pcmd = &(fs->pnext[i]);
			i++;
			if (stricmp(pcmd->cmd, str_LVQ_NOC) == 0)
				{
				lvq.noc = atoi(pcmd->args);
				if (lvq.noc == 0)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_NOC);
				else
					Msg(0, "noc = %i", lvq.noc);
				}
			if (stricmp(pcmd->cmd, str_LVQ_KNN) == 0)
				{
				lvq.knn = atoi(pcmd->args);
				if (lvq.knn == 0)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_KNN);
				else
					Msg(0, "knn = %i", lvq.knn);
				}
			if (stricmp(pcmd->cmd, str_LVQ_XDIM) == 0)
				{
				lvq.xdim = atoi(pcmd->args);
				if (lvq.xdim == 0)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_XDIM);
				else
					Msg(0, "xdim = %i", lvq.xdim);
				}
			if (stricmp(pcmd->cmd, str_LVQ_YDIM) == 0)
				{
				lvq.ydim = atoi(pcmd->args);
				if (lvq.ydim == 0)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_YDIM);
				else
					Msg(0, "ydim = %i", lvq.ydim);
				}
			if (stricmp(pcmd->cmd, str_LVQ_NEIGH) == 0)
				{
				lvq.neigh = NEIGH_UNKNOWN;
				if (stricmp(pcmd->args, "bubble") == 0)
					{
					lvq.neigh = NEIGH_BUBBLE;
					Msg(0, "Neighbourhood type = Bubble");
					}
				if (stricmp(pcmd->args, "gaussian") == 0)
					{
					lvq.neigh = NEIGH_GAUSSIAN;
					Msg(0, "Neighbourhood type = Gaussian");
					}
				if (lvq.neigh == NEIGH_UNKNOWN)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_NEIGH);
				}
			if (stricmp(pcmd->cmd, str_LVQ_TOPOL) == 0)
				{
				lvq.topol = TOPOL_UNKNOWN;
				if (stricmp(pcmd->args, "data") == 0)
					{
					lvq.topol = TOPOL_DATA;
					Msg(0, "Topology type = Data");
					}
				if (stricmp(pcmd->args, "LVQ") == 0)
					{
					lvq.topol = TOPOL_LVQ;
					Msg(0, "Topology type = LVQ");
					}
				if (stricmp(pcmd->args, "HEXA") == 0)
					{
					lvq.topol = TOPOL_HEXA;
					Msg(0, "Topology type = Hexagonal");
					}
				if (stricmp(pcmd->args, "RECT") == 0)
					{
					lvq.topol = TOPOL_RECT;
					Msg(0, "Topology type = Rectangular");
					}
				if (lvq.topol == TOPOL_UNKNOWN)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_TOPOL);
				}
			if (stricmp(pcmd->cmd, str_LVQ_SEED) == 0)
				{
				lvq.randomize = atoi(pcmd->args);
				Msg(0, "seed = %i", lvq.randomize);
				}
			if (stricmp(pcmd->cmd, str_LVQ_ALPHA_TYPE) == 0)
				{
				lvq.alpha_type = ALPHA_UNKNOWN;
				if (stricmp(pcmd->args, "linear") == 0)
					{
					lvq.alpha_type = ALPHA_LINEAR;
					Msg(0, "Alpha decreasing = Linear");
					}
				if (stricmp(pcmd->args, "inverse_t") == 0)
					{
					lvq.alpha_type = ALPHA_INVERSE_T;
					Msg(0, "Alpha decreasing = Inverse Time");
					}
				if (lvq.alpha_type == ALPHA_UNKNOWN)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_ALPHA_TYPE);
				}
			if (stricmp(pcmd->cmd, str_LVQ_RADIUS) == 0)
				{
				lvq.radius = atof(pcmd->args);
				if (lvq.radius == 0.0)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_RADIUS);
				else
					Msg(0, "radius = %f", lvq.radius);
				}
			if (stricmp(pcmd->cmd, str_LVQ_ALPHA) == 0)
				{
				lvq.alpha = atof(pcmd->args);
				if (lvq.alpha == 0.0)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_ALPHA);
				else
					Msg(0, "initial alpha = %f", lvq.alpha);
				}
			if (stricmp(pcmd->cmd, str_LVQ_SAMMON) == 0)
				{
				if (lvq.sammon == NULL)
					{
					lvq.sammon = new CSammon();
					lvq.sammon->xdim = lvq.xdim;
					lvq.sammon->ydim = lvq.ydim;
					}

				char *str = strtok(pcmd->args, " \t");
				if (str == NULL)
					Msg(0, str_LVQ_ERR_PARAM, str, str_LVQ_SAMMON);
				lvq.sammon->times = atoi(str);
				if (lvq.sammon->times == 0)
					Msg(0, str_LVQ_ERR_PARAM, str, str_LVQ_SAMMON);
				
				str = strtok(NULL, " \t");
				if (str == NULL)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_SAMMON);
				lvq.sammon->length = atof(str);
				if (lvq.sammon->length == 0)
					Msg(0, str_LVQ_ERR_PARAM, str, str_LVQ_SAMMON);
				else
					{
					bSammon = TRUE;
					if (lvq.sammon->length > 1.0)
						Msg(0, "sammon times num = %d, run length = %.0f", lvq.sammon->times, 
							lvq.sammon->length);
					else
						Msg(0, "sammon times num = %d, max mapping error = %f", lvq.sammon->times, 
							lvq.sammon->length);
					}
				}
				
			/*second : commands*/
			if (stricmp(pcmd->cmd, str_LVQ_EVENINIT) == 0)
				{
				lvq.pdata = pMetCmp;
				Msg(0, "eveninit");
				nState = UNDEF;
				eveninit(&lvq);
				}
			if (stricmp(pcmd->cmd, str_LVQ_PROPINIT) == 0)
				{
				lvq.pdata = pMetCmp;
				Msg(0, "propinit");
				nState = UNDEF;
				propinit(&lvq);
				}
			if (stricmp(pcmd->cmd, str_LVQ_BALANCE) == 0)
				{
				lvq.pdata = pMetCmp;
				Msg(0, "balance");
				if (nState != UNDEF)
					{
					Msg(0, "You must call eveninit or propinit at the beginning of the classification process");
					break;
					}
				balance(&lvq);
				}
			if (stricmp(pcmd->cmd, str_LVQ_ACCURACY) == 0)
				{
				lvq.pdata = pCategorizeCmp;
				lvq.pconfusion = NULL;
				if (nState != LEARN)
					{
					Msg(0, "You must call one of the learning method (LVQ1, OLVQ1, LVQ2, or LVQ3) before accuracy");
					break;
					}
				Msg(0, "accuracy");
				accuracy(&lvq);
				}
			if (stricmp(pcmd->cmd, str_LVQ_SAVE) == 0)
				{
				if (lvq.pcode == NULL)
					{
					Msg(0, "Impossible to save the codebook vectors because they don't exist");
					}
				lvq.pcode->Save(pcmd->args);
				}
			if (stricmp(pcmd->cmd, str_LVQ_CLASSIFY) == 0)
				{
				lvq.pdata = pCategorizeCmp;
				lvq.pconfusion = NULL;
				Msg(0, "classify");
				if (nState != LEARN)
					{
					Msg(0, "You must call one of the learning method (LVQ1, OLVQ1, LVQ2, or LVQ3) before accuracy");
					break;
					}
				classify(&lvq);
				}
			if (stricmp(pcmd->cmd, str_LVQ_OLVQ1) == 0)
				{
				if (bSammon == FALSE && lvq.sammon != NULL)
					lvq.sammon->length = 0;
				lvq.length = atol(pcmd->args);
				if (lvq.length == 0L)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_OLVQ1);
				else
					{
					if (nState != UNDEF && nState != LEARN)
						{
						Msg(0, "You must call eveninit or propinit at the beginning of the classification process");
						break;
						}
					lvq.pdata = pMetCmp;
					Msg(0, "olvq1 iteration length = %.0f", (double)lvq.length);
					olvq1(&lvq);
					nState = LEARN;
					}
				bSammon = FALSE;
				}
			if (stricmp(pcmd->cmd, str_LVQ_LVQ1) == 0)
				{
				if (bSammon == FALSE && lvq.sammon != NULL)
					lvq.sammon->length = 0;
				lvq.length = atol(pcmd->args);
				if (lvq.length == 0L)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ1);
				else
					{
					if (nState != UNDEF && nState != LEARN)
						{
						Msg(0, "You must call eveninit or propinit at the beginning of the classification process");
						break;
						}
					lvq.pdata = pMetCmp;
					Msg(0, "lvq1 iteration length = %.0f", (double)lvq.length);
					lvq1(&lvq);
					nState = LEARN;
					}
				bSammon = FALSE;
				}
			if (stricmp(pcmd->cmd, str_LVQ_LVQ2) == 0)
				{
				if (bSammon == FALSE && lvq.sammon != NULL)
					lvq.sammon->length = 0;
				char *str = strtok(pcmd->args, " \t");
				if (str == NULL)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ2);
				lvq.length = atol(str);
				if (lvq.length == 0L)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ2);
				
				str = strtok(NULL, " \t");
				if (str == NULL)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ2);
				lvq.winlen = atof(str);
				if (lvq.winlen == 0.0)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ2);
				else
					{
					if (nState != UNDEF && nState != LEARN)
						{
						Msg(0, "You must call eveninit or propinit at the beginning of the classification process");
						break;
						}
					lvq.pdata = pMetCmp;
					Msg(0, "lvq2 iteration length = %.0f, window length = %.1f", (double)lvq.length, 
						lvq.winlen);
					lvq2(&lvq);
					nState = LEARN;
					}
				bSammon = FALSE;
				}

			if (stricmp(pcmd->cmd, str_LVQ_LVQ3) == 0)
				{
				if (bSammon == FALSE && lvq.sammon != NULL)
					lvq.sammon->length = 0;
				char *str = strtok(pcmd->args, " \t");
				if (str == NULL)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ3);
				lvq.length = atol(str);
				if (lvq.length == 0L)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ3);
				
				str = strtok(NULL, " \t");
				if (str == NULL)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ3);
				lvq.winlen = atof(str);
				if (lvq.winlen == 0.0)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ3);

				str = strtok(NULL, " \t");
				if (str == NULL)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ3);
				lvq.epsilon = atof(str);
				if (lvq.epsilon == 0.0)
					Msg(0, str_LVQ_ERR_PARAM, pcmd->args, str_LVQ_LVQ3);
				else
					{
					if (nState != UNDEF && nState != LEARN)
						{
						Msg(0, "You must call eveninit or propinit at the beginning of the classification process");
						break;
						}
					lvq.pdata = pMetCmp;    
					Msg(0, "lvq3 iteration length = %.0f, window length = %.1f, epsilon = %.1f", 
						(double)lvq.length, lvq.winlen, lvq.epsilon);
					lvq3(&lvq);
					nState = LEARN;
					}
				bSammon = FALSE;
				}
			
			pcmd = pcmd->pnext;
			}
		
		}
	
	char *str, buf[20];
	long i, i2, num_class;
	if (lvq.pconfusion != NULL)
		{
		Msg(0, "Accuracy results :");
		num_class = lvq.pconfusion->GetCol();
		str = (char*)malloc(num_class * sizeof(buf));
		if (str == NULL)
			goto end;
		
		strcpy(str, "     ");
		for (i = 0; i < num_class; i++)
			{
			_snprintf(buf, sizeof(buf)," %s", GetClassStr(i));
			NChar(buf, 7);
			strcat(str, buf);
			}
		Msg(0, str);
			
		lvq.pconfusion->Lock();
		for (i = 1; i <= num_class; i++)
			{
			_snprintf(buf, sizeof(buf), "%s", GetClassStr(i-1));
			NChar(buf, 7);
			strcpy(str, buf);
			total = 0.0;
			for (i2 = 1; i2 <= num_class; i2++)
				{
				total += lvq.pconfusion->GetAt(i, i2);
				}
			for (i2 = 1; i2 <= num_class && total != 0; i2++)
				{
				_snprintf(buf, sizeof(buf), "%.0f%%%% ", lvq.pconfusion->GetAt(i, i2)/total*100.0);
				NChar(buf, 7);
				strcat(str, buf);
				}
			Msg(0, str);
			}
		lvq.pconfusion->Unlock();

		free(str);
		}

⌨️ 快捷键说明

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