/**********************************************************************************
* AUTHOR		: Nidhi Sharma
* DATE			: 11-Dec-2007
* NAME			: getFeatureExtractorInst
* DESCRIPTION	: 
* ARGUMENTS		:
* RETURNS		: 
* NOTES			:
* CHANGE HISTROY
* Author			Date				Description of LTKFeatureExtractor
*************************************************************************************/
int LTKShapeFeatureExtractorFactory::getFeatureExtractorInst(
                                 const string& lipiRootPath,
                                 const string& feName,
                                 void** m_libHandlerFE,
                                 const LTKControlInfo& controlInfo,
                                 LTKShapeFeatureExtractor** outFeatureExtractor)
{
	FN_PTR_CREATE_SHAPE_FEATURE_EXTRACTOR createFeatureExtractorPtr;
    void *functionHandle = NULL;

    LTKOSUtil* utilPtr = LTKOSUtilFactory::getInstance();

    int returnVal = utilPtr->loadSharedLib(lipiRootPath, feName, m_libHandlerFE);

    
	if(returnVal != SUCCESS)
	{
	    LTKReturnError(ELOAD_FEATEXT_DLL);
	}

    returnVal = utilPtr->getFunctionAddress(*m_libHandlerFE, 
                                            CREATE_SHAPE_FEATURE_EXTRACTOR, 
                                            &functionHandle);

	if(returnVal != SUCCESS)
	{
	    utilPtr->unloadSharedLib(m_libHandlerFE);
        *m_libHandlerFE = NULL;

		LTKReturnError(EDLL_FUNC_ADDRESS_CREATE_FEATEXT);
	}

    createFeatureExtractorPtr = (FN_PTR_CREATE_SHAPE_FEATURE_EXTRACTOR)functionHandle;

    int errorCode = createFeatureExtractorPtr(controlInfo, outFeatureExtractor);

    if (errorCode != SUCCESS)
    {
		LTKReturnError(errorCode);
    }

    delete utilPtr;
	return SUCCESS;

}
예제 #2
0
/**********************************************************************************
* AUTHOR		: Thanigai Murugan K
* DATE			: 30-AUG-2005
* NAME			: main
* DESCRIPTION	: Main function. Process the command line options and invoke the
*				  train/test methods after instantiating LipiEngine module.
* ARGUMENTS		: Command line arguments, refer to PrintUsage() function for syntax
* RETURNS		: -1 on error 0 on success
* NOTES			:
* CHANGE HISTROY
* Author			Date				Description of change
*************************************************************************************/
int main(int argc, char** argv)
{
	//char *envstring = NULL;
	char lipienginepath[MAX_PATH]="";
	int iErrorCode;
    LTKOSUtil* utilPtr = LTKOSUtilFactory::getInstance();
    void *functionHandle = NULL;
	
	globalArg = argv;
	globalArgCount = argc;

	utilPtr->recordStartTime();
	
	// Assume the default log file, if user did not specify one...
	if(LTKSTRCMP(strLogFile, "") == 0)
	{
		strcpy(strLogFile, DEFAULT_LOG_FILE);
	}

	if(processCommandLineArgs() != 0)
	{
		printUsage();
		delete utilPtr;
		return -1;
	}

	if(bVersionRequest) /* Then display version and exit */
	{
		cout << "\n Version of runwordrec tool: " << SUPPORTED_MIN_VERSION << endl;
		delete utilPtr;
		return 0;
	}

	/* Get the LIPI_ROOT environment variable if the user has not provided in the command line */


	if(strlen(strLipiRootPath)==0)
	{
		char *tempStr=NULL;

		/* Get the LIPI_ROOT environment variable */
		tempStr=getenv(LIPIROOT_ENV_STRING);
		

		if(tempStr == NULL)
		{
			cout << "Error,LIPI_ROOT is neither provided in the command line nor set as an environment variable\n" << endl;
			delete utilPtr;
			return -1;
		}
		strcpy(strLipiRootPath,tempStr);
	}


	// Load the LipiEngine.DLL
	hLipiEngine = NULL;

    iErrorCode = utilPtr->loadSharedLib(strLipiRootPath, 
                                        LIPIENGINE_MODULE_STR, 
                                        &hLipiEngine);

	if(iErrorCode != SUCCESS)
	{
		cout << "Error loading LipiEngine module" << endl;
		delete utilPtr;
		return -1;
	}
	

	int iMajor_lipiEngine=0, iMinor_lipiEngine=0, iBugfix_lipiEngine=0;

    iErrorCode = utilPtr->getFunctionAddress(hLipiEngine, 
                                             "getToolkitVersion", 
                                             &functionHandle);

    if(iErrorCode != SUCCESS)
	{
		cout << "Error mapping the getToolkitVersion function" << endl;
		delete utilPtr;
		return -1;
	}

    LipiEngine_getCurrentVersion = (FN_PTR_GETCURRENTVERSION) functionHandle;

	LipiEngine_getCurrentVersion(&iMajor_lipiEngine, &iMinor_lipiEngine, &iBugfix_lipiEngine);

	// Version comparison START
	char toolkitVer[MAX_STRLEN];
	sprintf(toolkitVer, "%d.%d.%d",iMajor_lipiEngine,iMinor_lipiEngine,iBugfix_lipiEngine);

	LTKVersionCompatibilityCheck verTempObj;
	string supportedMinVersion(SUPPORTED_MIN_VERSION);
	string toolkitVersion(toolkitVer);

	bool compatibilityResults = verTempObj.isFirstVersionHigher(toolkitVersion, supportedMinVersion);

	if(compatibilityResults == false)
	{
		cout<< "\nIncompatible version of LipiEngine(ver: " << toolkitVersion << ") with runwordrec(ver: " << supportedMinVersion << ")" << endl;
		
		// Unload the DLL from memory
		utilPtr->unloadSharedLib(hLipiEngine);
		delete utilPtr;
		return FAILURE;
	}
	// Version comparison END

	// without reserving memory, it gives an error at the end...
	strLogFileName.reserve(MAX_PATH); 

	/* Get the function address of "createLTKLipiEngine" function from the DLL module */
    functionHandle = NULL;
    iErrorCode = utilPtr->getFunctionAddress(hLipiEngine, 
                                            "createLTKLipiEngine", 
                                            &functionHandle);

    if(iErrorCode != SUCCESS)
	{
		cout << "Error mapping the createLTKLipiEngine function" << endl;
		delete utilPtr;
		return -1;
	}

    createLTKLipiEngine = (FN_PTR_CREATELTKLIPIENGINE) functionHandle;

    functionHandle = NULL;
    
	// Create an instance of LipiEngine
	ptrObj = createLTKLipiEngine();

	// set the LIPI_ROOT path in Lipiengine module instance
	ptrObj->setLipiRootPath(strLipiRootPath);

	// set the Log File Path
	if (strlen(strLogFile) != 0 )
	{
		string tempString(strLogFile);
		ptrObj->setLipiLogFileName(tempString);
	}

	if(strlen(strLogLevel) != 0)
	{
		string tempStringLogLevel(strLogLevel);
		ptrObj->setLipiLogLevel(tempStringLogLevel);
	}


	// Initialize the LipiEngine 
	iErrorCode = ptrObj->initializeLipiEngine();
	if(iErrorCode != 0)
	{
		cout << "Error initializing lipiengine: " << getErrorMessage(iErrorCode) << endl;
		cout << "For more details, please see the log file" << endl;
		// Unload the DLL from memory
		utilPtr->unloadSharedLib(hLipiEngine);
		delete utilPtr;
		return -1;
	}

	string strProjName(strProjectName), strProfName(strProfileName);

	// Now create the word recognizer instance using the project/profile name strings
	LTKWordRecognizer *pReco;
	iErrorCode = ptrObj->createWordRecognizer(strProjName, strProfName, &pReco);

	if(iErrorCode != SUCCESS)
	{
		cout << "Error creating word recognizer: " << getErrorMessage(iErrorCode) << endl;
		cout << "For more details, please see the log file" << endl;

		// Unload the DLL from memory
		utilPtr->unloadSharedLib(hLipiEngine);
		delete utilPtr;
		return -1;
	}

	if(bComputePerformance)
    {
        utilPtr->recordStartTime();
    }
	
	iErrorCode = evaluateWordRecognizer(pReco, strTestLstFile);
	if(iErrorCode != SUCCESS)
	{

		cout << "Error during testing the word recognizer: " << getErrorMessage(iErrorCode) << endl;
		cout << "For more details, please see the log file" << endl;

		ptrObj->deleteWordRecognizer(&pReco);

		// Unload the DLL from memory
		utilPtr->unloadSharedLib(hLipiEngine);
		delete utilPtr;
		return -1;
	}

	if(bComputePerformance)
	{
		utilPtr->recordEndTime();

        string timeTaken = "";
        utilPtr->diffTime(timeTaken);
        cout << "Time taken:" << timeTaken << endl;
	}

	// Delete the word recognizer which was created...
	ptrObj->deleteWordRecognizer(&pReco);

	// Unload the DLL from memory
	utilPtr->unloadSharedLib(hLipiEngine);

    delete utilPtr;


	return 0;
}