Beispiel #1
0
int HolisticRecognizer::initialize(string& strProjectName, string &strProfileName)
{
	LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << 
        "Entered HolisticShapeRecognizer::Initialize" << endl;

	string LipiRootPath = string(getLipiPath());	
	string tempStr = "";
    string preprocDllPath = "";
	headerInfo[PROJNAME] = strProjectName;
	int returnStatus=0;
	string strNumShapes = "";

	ltkShapeRecPtr = NULL;	

	//path for holistic.cfg
	m_holisticCfgFile = LipiRootPath + PROJECTS_PATH_STRING + strProjectName + PROFILE_PATH_STRING + strProfileName + SEPARATOR + HOLISTIC + CONFIGFILEEXT;

	//path for holistic.mdt
	m_referenceModelFile = LipiRootPath + PROJECTS_PATH_STRING + strProjectName + PROFILE_PATH_STRING + strProfileName + SEPARATOR + HOLISTIC + DATFILEEXT;

	m_confMapFile = LipiRootPath + PROJECTS_PATH_STRING + strProjectName + PROFILE_PATH_STRING + strProfileName + SEPARATOR;
                
	// Read number of shapes from project.cfg
	tempStr = LipiRootPath + PROJECTS_PATH_STRING + strProjectName + PROFILE_PATH_STRING + PROJECT_CFG_STRING;
	try
	{
		//To find whether the project was dynamic or not
		//to read read number of shapes from project.cfg
		m_projectTypeDynamic = shaperecUtilInst->isProjectDynamic(tempStr, m_numShapes, returnStatus, strNumShapes);
		
		headerInfo[NUMSHAPES] = strNumShapes;
		
		preprocDllPath = LipiRootPath + SEPARATOR + "lib" + SEPARATOR + PREPROC + DLL_EXT;

		// initialize preprocessor
		returnStatus = 0;
		ltkShapeRecPtr = shaperecUtilInst->initializePreprocessor(preprocDllPath,
						returnStatus);

	}
	
	catch(LTKException e)
	{
		LOG( LTKLogger::LTK_LOGLEVEL_ERR) << e.getExceptionMessage() << endl;
		LTKReturnError(returnStatus);
	}
	
	//setPreprocMap(); // To add function name and the function address into the mapping variable.

	//Assigning Default Values
	assignDefaultValues();

	//Reading pca configuration file
	returnStatus = readClassifierConfig();

	return returnStatus;
}
/*****************************************************************************
* AUTHOR		: Deepu V.
* DATE			: 22-AUG-2005
* NAME			: initializeWordRecognizer
* DESCRIPTION	: Initialization of Boxed word Recognizer. This function performs
*                      -Create & initialize shape recognizer
* ARGUMENTS		:
* RETURNS		:
* NOTES			:
* CHANGE HISTROY
* Author			Date				Description of
*****************************************************************************/
BoxedFieldRecognizer::BoxedFieldRecognizer(const LTKControlInfo& controlInfo)
:LTKWordRecognizer(BOXFLD),
m_shapeRecognizer(NULL),
m_numShapeRecoResults(DEFAULT_SHAPE_RECO_CHOICES),
m_shapeRecoMinConfidence(DEFAULT_SHAPE_RECO_MIN_CONFID),
m_module_createShapeRecognizer(NULL),
m_module_deleteShapeRecognizer(NULL),
m_numCharsProcessed(0),
m_numTracesProcessed(0),
m_boxedShapeProject(""),
m_boxedShapeProfile(""),
m_lipiRoot(""),
m_boxedConfigFile(""),
m_logFile(""),
m_logLevel(LTKLogger::LTK_LOGLEVEL_ERR),
m_toolkitVersion(""),
m_OSUtilPtr(LTKOSUtilFactory::getInstance())
{

	string boxedShapeProfile;   //profile name

	int errorCode = 0;

	LTKControlInfo tempControlInfo = controlInfo;

    if ( tempControlInfo.lipiRoot.empty() )
    {
        throw LTKException(ELIPI_ROOT_PATH_NOT_SET);
    }

    if ( tempControlInfo.projectName.empty() )
    {
        throw LTKException(EINVALID_PROJECT_NAME);
    }

    if( (tempControlInfo.profileName).empty() )
	{
		tempControlInfo.profileName = DEFAULT_PROFILE;
	}

    if ( tempControlInfo.toolkitVersion.empty() )
    {
        throw LTKException(ENO_TOOLKIT_VERSION);
    }

    // initialize the data members
    m_lipiRoot          = tempControlInfo.lipiRoot;
    m_toolkitVersion    = tempControlInfo.toolkitVersion;


	//constructing the boxed Config filename
	m_boxedConfigFile  = m_lipiRoot + PROJECTS_PATH_STRING +
		                 tempControlInfo.projectName + PROFILE_PATH_STRING +
		                 tempControlInfo.profileName + SEPARATOR + BOXFLD + CONFIGFILEEXT;

	readClassifierConfig();


	LOG(LTKLogger::LTK_LOGLEVEL_DEBUG)
	    <<"Entering: BoxedFieldRecognizer::BoxedFieldRecognizer(const LTKControlInfo& )"
	    <<endl;

	//Creating the shape recognizer object
	if((errorCode = createShapeRecognizer(m_boxedShapeProject, m_boxedShapeProfile,&m_shapeRecognizer)) != SUCCESS)
	{
		 LOG(LTKLogger::LTK_LOGLEVEL_ERR)
        <<"Error: BoxedFieldRecognizer::BoxedFieldRecognizer(const LTKControlInfo&)"<<endl;

	   throw LTKException(errorCode);
	}

	if(m_shapeRecognizer == NULL)
	{
		LOG(LTKLogger::LTK_LOGLEVEL_ERR)
		    <<"Error : "<< ECREATE_SHAPEREC <<":"<< getErrorMessage(ECREATE_SHAPEREC)
            <<" BoxedFieldRecognizer::BoxedFieldRecognizer(const LTKControlInfo&)" <<endl;

		throw LTKException(ECREATE_SHAPEREC);
	}

	//loading the model data file
	if( (errorCode = (m_shapeRecognizer->loadModelData())) != SUCCESS )
	{
		m_module_deleteShapeRecognizer(m_shapeRecognizer);
		m_shapeRecognizer = NULL;

		LOG(LTKLogger::LTK_LOGLEVEL_ERR)
        	<<"Error: BoxedFieldRecognizer::BoxedFieldRecognizer(const LTKControlInfo&)"<<endl;

		throw LTKException(errorCode);
	}

	m_numCharsProcessed = 0;  //initializing number of characters processed
	m_numTracesProcessed = 0; //initializing number of traces processed


	LOG(LTKLogger::LTK_LOGLEVEL_DEBUG)
	    <<"Exiting: BoxedFieldRecognizer::BoxedFieldRecognizer(const LTKControlInfo&)"
	    <<endl;
}
int featurefilewriter::Initalize(const string& cfgFilepath,
								 const string& strLipiPath,
								 const string& strOutputPath)
{
	try
	{
		LTKControlInfo tmpControlInfo;
		tmpControlInfo.lipiRoot = strLipiPath;
		tmpControlInfo.toolkitVersion = SUPPORTED_MIN_VERSION;
		tmpControlInfo.cfgFilePath = cfgFilepath;
		
	    if( (tmpControlInfo.lipiRoot).empty() )
	    {
	        throw LTKException(ELIPI_ROOT_PATH_NOT_SET);
	    }
	    if ( tmpControlInfo.toolkitVersion.empty() )
	    {
	        throw LTKException(ENO_TOOLKIT_VERSION);
	    }
	    if ( tmpControlInfo.cfgFilePath.empty() )
	    {
	        throw LTKException(EINVALID_CFG_FILE_ENTRY);
	    }

	    assignDefaultValues();

	    m_lipiRootPath = tmpControlInfo.lipiRoot;
	    m_nnCfgFilePath = cfgFilepath;
		m_FDTFilePath = strOutputPath;

	    int errorCode = initializePreprocessor(tmpControlInfo,&m_ptrPreproc);

	    if( errorCode != SUCCESS)
	    {
	        LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << errorCode << " " <<
	            "featurefilewriter::Initalize()" <<endl;
	        throw LTKException(errorCode);
	    }


		//Reading configuration file
	    errorCode = readClassifierConfig();

	    if( errorCode != SUCCESS)
	    {
			cout<<endl<<"Encountered error in readClassifierConfig"<<endl;
	        LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << 
				errorCode << " " <<
	            "featurefilewriter::Initalize()" <<endl;
	        throw LTKException(errorCode);
	    }

	    errorCode = initializeFeatureExtractorInstance(tmpControlInfo);

	    if( errorCode != SUCCESS)
	    {
	        LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << errorCode << " " <<
	            "featurefilewriter::Initalize()" <<endl;
	        throw LTKException(errorCode);
	    }

	}
	catch(LTKException e)
	{
		deletePreprocessor();

		//Unloading the feature Extractor instance
	    deleteFeatureExtractorInstance();

		if(NULL != m_OSUtilPtr)
		{
			delete m_OSUtilPtr;
			m_OSUtilPtr = NULL;
		}
		throw e;
	}

	return 0;
}