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

📄 mftraining.cpp

📁 一OCR的相关资料。.希望对研究OCR的朋友有所帮助.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		case 'n':			ShowInsignificantProtos = FALSE;			break;		case 'p':			ShowSignificantProtos = FALSE;			break;		case 'd':			ShowAllSamples = FALSE;			break;		case 'C':			ParametersRead = sscanf( optarg, "%lf", &(Config.Confidence) );			if ( ParametersRead != 1 ) Error = TRUE;			else if ( Config.Confidence > 1 ) Config.Confidence = 1;			else if ( Config.Confidence < 0 ) Config.Confidence = 0;			break;		case 'I':			ParametersRead = sscanf( optarg, "%f", &(Config.Independence) );			if ( ParametersRead != 1 ) Error = TRUE;			else if ( Config.Independence > 1 ) Config.Independence = 1;			else if ( Config.Independence < 0 ) Config.Independence = 0;			break;		case 'M':			ParametersRead = sscanf( optarg, "%f", &(Config.MinSamples) );			if ( ParametersRead != 1 ) Error = TRUE;			else if ( Config.MinSamples > 1 ) Config.MinSamples = 1;			else if ( Config.MinSamples < 0 ) Config.MinSamples = 0;			break;		case 'B':			ParametersRead = sscanf( optarg, "%f", &(Config.MaxIllegal) );			if ( ParametersRead != 1 ) Error = TRUE;			else if ( Config.MaxIllegal > 1 ) Config.MaxIllegal = 1;			else if ( Config.MaxIllegal < 0 ) Config.MaxIllegal = 0;			break;		case 'R':			ParametersRead = sscanf( optarg, "%f", &RoundingAccuracy );			if ( ParametersRead != 1 ) Error = TRUE;			else if ( RoundingAccuracy > 0.01 ) RoundingAccuracy = 0.01;			else if ( RoundingAccuracy < 0.0 ) RoundingAccuracy = 0.0;			break;		case 'S':			switch ( optarg[0] )			{			case 's': Config.ProtoStyle = spherical; break;			case 'e': Config.ProtoStyle = elliptical; break;			case 'm': Config.ProtoStyle = mixed; break;			case 'a': Config.ProtoStyle = automatic; break;			default: Error = TRUE;			}			break;			case 'D':				Directory = optarg;				break;			case 'N':				if (sscanf (optarg, "%d", &MaxNumSamples) != 1 ||					MaxNumSamples <= 0)					Error = TRUE;				break;			case '?':				Error = TRUE;				break;		}		if ( Error )		{			fprintf (stderr, "usage: %s [-D] [-P] [-N]\n", argv[0] );			fprintf (stderr, "\t[-S ProtoStyle]\n");			fprintf (stderr, "\t[-M MinSamples] [-B MaxBad] [-I Independence] [-C Confidence]\n" );			fprintf (stderr, "\t[-d directory] [-n MaxNumSamples] [ TrainingPage ... ]\n");			exit (2);		}	}}	// ParseArguments/*---------------------------------------------------------------------------*/char *GetNextFilename ()/***	Parameters: none**	Globals:**		optind			defined by getopt sys call**		Argc, Argv		global copies of argc and argv**	Operation:**		This routine returns the next command line argument.  If**		there are no remaining command line arguments, it returns**		NULL.  This routine should only be called after all option**		arguments have been parsed and removed with ParseArguments.**	Return: Next command line argument or NULL.**	Exceptions: none**	History: Fri Aug 18 09:34:12 1989, DSJ, Created.*/{	if (optind < Argc)		return (Argv [optind++]);	else		return (NULL);}	/* GetNextFilename *//*---------------------------------------------------------------------------*/LIST ReadTrainingSamples (     FILE	*File)/***	Parameters:**		File		open text file to read samples from**	Globals: none**	Operation:**		This routine reads training samples from a file and**		places them into a data structure which organizes the**		samples by FontName and CharName.  It then returns this**		data structure.**	Return: none**	Exceptions: none**	History: Fri Aug 18 13:11:39 1989, DSJ, Created.**			 Tue May 17 1998 simplifications to structure, illiminated**				font, and feature specification levels of structure.*/{	char			CharName[MAXNAMESIZE];	LABELEDLIST	CharSample;  FEATURE_SET FeatureSamples;	LIST			TrainingSamples = NIL;	CHAR_DESC		CharDesc;	int			Type, i;	while (fscanf (File, "%s %s", FontName, CharName) == 2) {		CharSample = FindList (TrainingSamples, CharName);		if (CharSample == NULL) {			CharSample = NewLabeledList (CharName);			TrainingSamples = push (TrainingSamples, CharSample);		}		CharDesc = ReadCharDescription (File);		Type = ShortNameToFeatureType(PROGRAM_FEATURE_TYPE);		FeatureSamples = FeaturesOfType(CharDesc, Type);    for (int feature = 0; feature < FeatureSamples->NumFeatures; ++feature) {      FEATURE f = FeatureSamples->Features[feature];      for (int dim =0; dim < f->Type->NumParams; ++dim)        f->Params[dim] += UniformRandomNumber(-MINSD, MINSD);    }		CharSample->List = push (CharSample->List, FeatureSamples);		for (i = 0; i < NumFeatureSetsIn (CharDesc); i++)			if (Type != i)				FreeFeatureSet (FeaturesOfType (CharDesc, i));		free (CharDesc);    }	return (TrainingSamples);}	/* ReadTrainingSamples *//*---------------------------------------------------------------------------*/LABELEDLIST FindList (     LIST	List,     char	*Label)/***	Parameters:**		List		list to search**		Label		label to search for**	Globals: none**	Operation:**		This routine searches thru a list of labeled lists to find**		a list with the specified label.  If a matching labeled list**		cannot be found, NULL is returned.**	Return: Labeled list with the specified Label or NULL.**	Exceptions: none**	History: Fri Aug 18 15:57:41 1989, DSJ, Created.*/{	LABELEDLIST	LabeledList;	iterate (List)    {		LabeledList = (LABELEDLIST) first (List);		if (strcmp (LabeledList->Label, Label) == 0)			return (LabeledList);    }	return (NULL);}	/* FindList *//*----------------------------------------------------------------------------*/MERGE_CLASS FindClass (     LIST	List,     char	*Label){	MERGE_CLASS	MergeClass;	iterate (List)    {		MergeClass = (MERGE_CLASS) first (List);		if (strcmp (MergeClass->Label, Label) == 0)			return (MergeClass);    }	return (NULL);}	/* FindClass *//*---------------------------------------------------------------------------*/LABELEDLIST NewLabeledList (     char	*Label)/***	Parameters:**		Label	label for new list**	Globals: none**	Operation:**		This routine allocates a new, empty labeled list and gives**		it the specified label.**	Return: New, empty labeled list.**	Exceptions: none**	History: Fri Aug 18 16:08:46 1989, DSJ, Created.*/{	LABELEDLIST	LabeledList;	LabeledList = (LABELEDLIST) Emalloc (sizeof (LABELEDLISTNODE));	LabeledList->Label = (char*)Emalloc (strlen (Label)+1);	strcpy (LabeledList->Label, Label);	LabeledList->List = NIL;	return (LabeledList);}	/* NewLabeledList *//*---------------------------------------------------------------------------*/MERGE_CLASS NewLabeledClass (     char	*Label){	MERGE_CLASS	MergeClass;	MergeClass = (MERGE_CLASS) Emalloc (sizeof (MERGE_CLASS_NODE));	MergeClass->Label = (char*)Emalloc (strlen (Label)+1);	strcpy (MergeClass->Label, Label);	MergeClass->Class = NewClass (MAX_NUM_PROTOS, MAX_NUM_CONFIGS);	return (MergeClass);}	/* NewLabeledClass *//*---------------------------------------------------------------------------*/void WriteTrainingSamples (     char	*Directory,     LIST	CharList)/***	Parameters:**		Directory	directory to place sample files into**		FontList	list of fonts used in the training samples**	Globals:**		MaxNumSamples	max number of samples per class to write**	Operation:**		This routine writes the specified samples into files which**		are organized according to the font name and character name**		of the samples.**	Return: none**	Exceptions: none**	History: Fri Aug 18 16:17:06 1989, DSJ, Created.*/{	LABELEDLIST	CharSample;	FEATURE_SET	FeatureSet;	LIST		FeatureList;	FILE		*File;	char		Filename[MAXNAMESIZE];	int		NumSamples;	iterate (CharList)		// iterate thru all of the fonts	{		CharSample = (LABELEDLIST) first (CharList);		// construct the full pathname for the current samples file		strcpy (Filename, "");		if (Directory != NULL)		{			strcat (Filename, Directory);			strcat (Filename, "/");		}		strcat (Filename, FontName);		strcat (Filename, "/");		strcat (Filename, CharSample->Label);		strcat (Filename, ".");		strcat (Filename, PROGRAM_FEATURE_TYPE);		printf ("\nWriting %s ...", Filename);		/* if file does not exist, create a new one with an appropriate		header; otherwise append samples to the existing file */		File = fopen (Filename, "r");		if (File == NULL)		{			File = Efopen (Filename, "w");			WriteOldParamDesc				(File, DefinitionOf (ShortNameToFeatureType (PROGRAM_FEATURE_TYPE)));		}		else		{			fclose (File);			File = Efopen (Filename, "a");		}		// append samples onto the file		FeatureList = CharSample->List;		NumSamples = 0;		iterate (FeatureList)		{			if (NumSamples >= MaxNumSamples) break;			FeatureSet = (FEATURE_SET) first (FeatureList);			WriteFeatureSet (File, FeatureSet);			NumSamples++;		}		fclose (File);	}}	/* WriteTrainingSamples *//*----------------------------------------------------------------------------*/void WriteClusteredTrainingSamples (     char	*Directory,     LIST	ProtoList,	 CLUSTERER *Clusterer,	 LABELEDLIST CharSample)/***	Parameters:**		Directory	directory to place sample files into**	Globals:**		MaxNumSamples	max number of samples per class to write**	Operation:**		This routine writes the specified samples into files which**		are organized according to the font name and character name**		of the samples.**	Return: none**	Exceptions: none**	History: Fri Aug 18 16:17:06 1989, DSJ, Created.*/{	FILE		*File;	char		Filename[MAXNAMESIZE];	strcpy (Filename, "");	if (Directory != NULL)	{		strcat (Filename, Directory);		strcat (Filename, "/");	}	strcat (Filename, FontName);	strcat (Filename, "/");	strcat (Filename, CharSample->Label);	strcat (Filename, ".");	strcat (Filename, PROGRAM_FEATURE_TYPE);	strcat (Filename, ".p");	printf ("\nWriting %s ...", Filename);	File = Efopen (Filename, "w");	WriteProtoList(File, Clusterer->SampleSize, Clusterer->ParamDesc,		ProtoList, ShowSignificantProtos, ShowInsignificantProtos);	fclose (File);}	/* WriteClusteredTrainingSamples *//*---------------------------------------------------------------------------*/void WriteMergedTrainingSamples(    char	*Directory,	LIST ClassList){	FILE		*File;	char		Filename[MAXNAMESIZE];	MERGE_CLASS MergeClass;	iterate (ClassList)	{		MergeClass = (MERGE_CLASS) first (ClassList);		strcpy (Filename, "");		if (Directory != NULL)		{			strcat (Filename, Directory);			strcat (Filename, "/");		}		strcat (Filename, "Merged/");		strcat (Filename, MergeClass->Label);		strcat (Filename, PROTO_SUFFIX);		printf ("\nWriting Merged %s ...", Filename);		File = Efopen (Filename, "w");		WriteOldProtoFile (File, MergeClass->Class);		fclose (File);		strcpy (Filename, "");		if (Directory != NULL)		{			strcat (Filename, Directory);			strcat (Filename, "/");		}		strcat (Filename, "Merged/");		strcat (Filename, MergeClass->Label);		strcat (Filename, CONFIG_SUFFIX);		printf ("\nWriting Merged %s ...", Filename);		File = Efopen (Filename, "w");		WriteOldConfigFile (File, MergeClass->Class);		fclose (File);	}

⌨️ 快捷键说明

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