Exemple #1
0
/**********************************************************************************
* AUTHOR        : Thanigai
* DATE          : 29-JUL-2005
* NAME          : createShapeRecognizer
* DESCRIPTION   : create an instance of shape recognizer object and call initialize
*				  function. Also loads the model data.
* ARGUMENTS     : strProjectName - project name; strProfileName - profile name
* RETURNS       : handle to the recognizer on success & NULL on error
* NOTES         :
* CHANGE HISTROY
* Author            Date                Description of
*************************************************************************************/
 int BoxedFieldRecognizer::createShapeRecognizer(const string& strProjectName, const string& strProfileName,LTKShapeRecognizer** outShapeRecPtr)
{
    LOG(LTKLogger::LTK_LOGLEVEL_DEBUG)
        <<"Entering: BoxedFieldRecognizer::createShapeRecognizer"
        <<endl;


    LTKConfigFileReader* projectCfgFileEntries = NULL;
    LTKConfigFileReader* profileCfgFileEntries = NULL;

	string cfgFilePath      = "";
	string shapeRecDllPath  = "";
	int iResult             = 0;
    string recognizerName   = "";
    string strLocalProfileName(strProfileName);


	/* invalid or no entry for project name */
	if(strProjectName == "")
	{

		*outShapeRecPtr = NULL;

		LOG( LTKLogger::LTK_LOGLEVEL_ERR)
            <<"Invalid or no entry for project name" <<endl;

        LOG(LTKLogger::LTK_LOGLEVEL_ERR)
		    <<"Error : "<< EINVALID_PROJECT_NAME <<":"<< getErrorMessage(EINVALID_PROJECT_NAME)
            <<" BoxedFieldRecognizer::createShapeRecognizer" <<endl;

		LTKReturnError(EINVALID_PROJECT_NAME);
	}

	if(strProfileName == "")
	{
		strLocalProfileName = DEFAULT_PROFILE; /* assume the "default" profile */
	}

	cfgFilePath = m_lipiRoot + PROJECTS_PATH_STRING + strProjectName +
                  PROFILE_PATH_STRING + PROJECT_CFG_STRING;

	try
	{
		projectCfgFileEntries = new LTKConfigFileReader(cfgFilePath);
	}
	catch(LTKException e)
	{
		delete projectCfgFileEntries;

		*outShapeRecPtr = NULL; // Error exception thrown...

		LOG(LTKLogger::LTK_LOGLEVEL_ERR)
            <<"Error: BoxedFieldRecognizer::createShapeRecognizer"<<endl;

		LTKReturnError(e.getErrorCode());


	}

	//	Read the project.cfg and ensure this is a shaperecognizer; i.e. ProjectType = SHAPEREC;
	string projectType = "";
	projectCfgFileEntries->getConfigValue(PROJECT_TYPE_STRING, projectType);

	/* Invalid configuration entry for ProjectType */
	if(projectType != PROJECT_TYPE_SHAPEREC)
	{
		*outShapeRecPtr = NULL;

		errorCode = EINVALID_CONFIG_ENTRY;

		LOG(LTKLogger::LTK_LOGLEVEL_ERR)
		    <<"Error : "<< EINVALID_CONFIG_ENTRY <<":"<< getErrorMessage(EINVALID_CONFIG_ENTRY)
            <<" BoxedFieldRecognizer::createShapeRecognizer" <<endl;

		LTKReturnError(errorCode);

	}

	//	Read the profile.cfg and find out the recognition module to load;
	cfgFilePath = m_lipiRoot + PROJECTS_PATH_STRING + strProjectName +
	              PROFILE_PATH_STRING + strLocalProfileName +
	              SEPARATOR + PROFILE_CFG_STRING;
	try
	{
		profileCfgFileEntries = new LTKConfigFileReader(cfgFilePath);
	}
	catch(LTKException e)
	{
		*outShapeRecPtr = NULL;

		delete profileCfgFileEntries;

		LOG(LTKLogger::LTK_LOGLEVEL_ERR)
            <<"Error: BoxedFieldRecognizer::createShapeRecognizer"<<endl;

		LTKReturnError(e.getErrorCode());

	}

	int errorCode = profileCfgFileEntries->getConfigValue(SHAPE_RECOGNIZER_STRING, recognizerName);

	/* No recognizer specified. */
	if(errorCode != SUCCESS)
	{

		*outShapeRecPtr = NULL;

		errorCode = ENO_SHAPE_RECOGNIZER;

		LOG(LTKLogger::LTK_LOGLEVEL_ERR)
		    <<"Error : "<< ENO_SHAPE_RECOGNIZER <<":"<< getErrorMessage(ENO_SHAPE_RECOGNIZER)
            <<" BoxedFieldRecognizer::createShapeRecognizer" <<endl;

        delete projectCfgFileEntries;
    	delete profileCfgFileEntries;

		LTKReturnError(errorCode);
	}

    m_hAlgoDLLHandle = NULL;
    errorCode = m_OSUtilPtr->loadSharedLib(m_lipiRoot, recognizerName, &m_hAlgoDLLHandle);

	// Unable to load dll
	if(errorCode != SUCCESS)
	{
		*outShapeRecPtr = NULL;

		errorCode = ELOAD_SHAPEREC_DLL;

		LOG(LTKLogger::LTK_LOGLEVEL_ERR)
		    <<"Error : "<< ELOAD_SHAPEREC_DLL <<":"<< getErrorMessage(ELOAD_SHAPEREC_DLL)
            <<" BoxedFieldRecognizer::createShapeRecognizer" <<endl;

        delete projectCfgFileEntries;
    	delete profileCfgFileEntries;

		LTKReturnError(errorCode);

	}

	// Map Algo DLL functions...

	// Unable to map the functions
	if((errorCode = mapShapeAlgoModuleFunctions()) != SUCCESS)
	{
		*outShapeRecPtr = NULL;
	    delete projectCfgFileEntries;
    	delete profileCfgFileEntries;

		LOG(LTKLogger::LTK_LOGLEVEL_ERR)
            <<"Error: BoxedFieldRecognizer::createShapeRecognizer"<<endl;

		LTKReturnError(errorCode)
	}