diff options
Diffstat (limited to 'src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec')
12 files changed, 3672 insertions, 0 deletions
diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/BoxFieldRecognizer.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/BoxFieldRecognizer.cpp new file mode 100644 index 00000000..dbcdca58 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/BoxFieldRecognizer.cpp @@ -0,0 +1,1336 @@ +/***************************************************************************************** +* Copyright (c) 2006 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in +* the Software without restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +* Software, and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +* OR THE US E OR OTHER DEALINGS IN THE SOFTWARE. +*****************************************************************************************/ + +/************************************************************************ + * SVN MACROS + * + * $LastChangedDate: 2011-02-08 16:57:52 +0530 (Tue, 08 Feb 2011) $ + * $Revision: 834 $ + * $Author: mnab $ + * + ************************************************************************/ +/************************************************************************ + * FILE DESCR: Implementation of BoxedFieldRecognizer + * CONTENTS: + * + * AUTHOR: Deepu V. + * + * DATE: March 23, 2005 + * CHANGE HISTORY: + * Author Date Description of + ************************************************************************/ + +#include "BoxFieldRecognizer.h" +#include "LTKLoggerUtil.h" +#include "LTKTrace.h" +#include "LTKInc.h" +#include "LTKTypes.h" +#include "LTKErrors.h" +#include "LTKErrorsList.h" +#include "LTKTraceGroup.h" +#include "LTKWordRecoConfig.h" + +#include "LTKShapeRecognizer.h" +#include "LTKRecognitionContext.h" + +#include "LTKScreenContext.h" +#include "LTKCaptureDevice.h" +#include "LTKConfigFileReader.h" +#include "LTKMacros.h" +#include "LTKStrEncoding.h" +#include "LTKException.h" +#include "LTKOSUtilFactory.h" +#include "LTKOSUtil.h" +#include "LTKStringUtil.h" + +#include <functional> + +extern void *m_hAlgoDLLHandle; + + + +/***************************************************************************** +* 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_lipiLib(""), +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_lipiLib = tempControlInfo.lipiLib; + 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; +} + +/****************************************************************************** + * AUTHOR : Nidhi Sharma + * DATE : 28-Sept-2007 + * NAME : readClassifierConfig + * DESCRIPTION : Reads the boxfld.cfg and initializes the data members of the class + * ARGUMENTS : none + * RETURNS : SUCCESS - If config file read successfully + * errorCode - If failure + * NOTES : + * CHANGE HISTROY + * Author Date Description + ******************************************************************************/ +int BoxedFieldRecognizer::readClassifierConfig() +{ + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::readClassifierConfig" + <<endl; + + LTKConfigFileReader* boxedFldConfigMap = NULL; + string cfgFileValue = ""; + int errorCode = FAILURE; + + try + { + boxedFldConfigMap = new LTKConfigFileReader(m_boxedConfigFile); + } + catch(LTKException fofe) + { + delete boxedFldConfigMap; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::readClassifierConfig"<<endl; + + LTKReturnError(ECONFIG_FILE_OPEN); // Error while reading project.cfg + } + + //initializing the number of shape recognition choices required from the file + + errorCode = boxedFldConfigMap->getConfigValue(NUMSHAPECHOICES, cfgFileValue); + + if ( errorCode == SUCCESS ) + { + m_numShapeRecoResults = atoi(cfgFileValue.c_str()); + + if(m_numShapeRecoResults <= 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENON_POSITIVE_NUM <<":"<< getErrorMessage(ENON_POSITIVE_NUM) + <<" BoxedFieldRecognizer::readClassifierConfig" <<endl; + + LTKReturnError(ENON_POSITIVE_NUM); + } + + } + else + { + LOG(LTKLogger::LTK_LOGLEVEL_INFO) + <<"Assuming default value for number of shape recognizer choices:" + <<m_numShapeRecoResults<<endl; + } + + + + //initializing the minimum confidence threshold + + cfgFileValue = ""; + errorCode = boxedFldConfigMap->getConfigValue(MINSHAPECONFID, cfgFileValue); + + if ( errorCode == SUCCESS ) + { + m_shapeRecoMinConfidence = LTKStringUtil::convertStringToFloat(cfgFileValue); + + if(m_shapeRecoMinConfidence < 0 || m_shapeRecoMinConfidence > 1) + { + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EINVALID_CONFIDENCE_VALUE <<":"<< getErrorMessage(EINVALID_CONFIDENCE_VALUE) + <<" BoxedFieldRecognizer::readClassifierConfig" <<endl; + + + LTKReturnError(EINVALID_CONFIDENCE_VALUE); + } + } + else + { + LOG(LTKLogger::LTK_LOGLEVEL_INFO) + <<"Assuming default value for minimum shape recognizer confidence:" + <<m_shapeRecoMinConfidence<<endl; + + } + + //retrieving the boxed shape project and profile + cfgFileValue = ""; + errorCode = boxedFldConfigMap->getConfigValue(BOXEDSHAPEPROJECT, cfgFileValue); + + if ( errorCode == SUCCESS ) + { + m_boxedShapeProject = cfgFileValue; + + if(m_boxedShapeProject.empty()) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EINVALID_PROJECT_NAME <<":"<< getErrorMessage(EINVALID_PROJECT_NAME) + <<" BoxedFieldRecognizer::readClassifierConfig" <<endl; + + LTKReturnError(EINVALID_PROJECT_NAME); + } + } + else + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENO_SHAPE_RECO_PROJECT <<":"<< getErrorMessage(ENO_SHAPE_RECO_PROJECT) + <<" BoxedFieldRecognizer::readClassifierConfig" <<endl; + + LTKReturnError(ENO_SHAPE_RECO_PROJECT); + } + + + //retrieving the boxed shape project and profile + cfgFileValue = ""; + errorCode = boxedFldConfigMap->getConfigValue(BOXEDSHAPEPROFILE, cfgFileValue); + + if( errorCode == SUCCESS ) + { + m_boxedShapeProfile = cfgFileValue; + + if(m_boxedShapeProfile.empty()) + { + LOG(LTKLogger::LTK_LOGLEVEL_INFO) + <<"No profile specified for shape recognizer project.Assuming 'default' profile"<<endl; + + m_boxedShapeProfile = DEFAULT_PROFILE; + } + + + } + else + { + LOG(LTKLogger::LTK_LOGLEVEL_INFO) + <<"No profile specified for shape recognizer project. Assuming 'default' profile"<<endl; + + m_boxedShapeProfile = DEFAULT_PROFILE; + + } + + delete boxedFldConfigMap; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::readClassifierConfig" + <<endl; + + return SUCCESS; +} + +/***************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-AUG-2005 +* NAME : processInk +* DESCRIPTION : This method is called from recognition context whenever new traces +* : are added to it. The Recognizer need to process the new traces +* : in this methods and updates the internal state. +* ARGUMENTS : rc - The recognition context for the current recognition +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of +******************************************************************************/ +int BoxedFieldRecognizer::processInk (LTKRecognitionContext& rc) +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::processInk" + <<endl; + + string tempStr = REC_UNIT_INFO; + + int tempFlagValue=0; + + int errorCode=0; + + if((errorCode=rc.getFlag(tempStr,tempFlagValue))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::processInk"<<endl; + + LTKReturnError(errorCode); + } + + //give an error if the Ink is not segmented into characters + if(tempFlagValue != REC_UNIT_CHAR) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EINVALID_SEGMENT <<":"<< getErrorMessage(EINVALID_SEGMENT) + <<" BoxedFieldRecognizer::processInk" <<endl; + + LTKReturnError(EINVALID_SEGMENT); + } + + tempStr = REC_MODE; + + + if((errorCode=rc.getFlag(tempStr,tempFlagValue))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::processInk"<<endl; + + LTKReturnError(errorCode); + } + + //if the recognizer mode is correct + if (tempFlagValue == REC_MODE_STREAMING) + { + //recognize the newly added strokes + recognizeTraces(rc); + } + else + { + //give an error otherwise + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EINVALID_REC_MODE <<":"<< getErrorMessage(EINVALID_REC_MODE) + <<" BoxedFieldRecognizer::processInk" <<endl; + + + LTKReturnError(EINVALID_REC_MODE); + } + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::processInk" + <<endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-AUG-2005 +* NAME : endRecoUnit +* DESCRIPTION : This function notifies the recognizer that end of current ink is +* : the end of a logic segment. This information could be used in +* : constraining the recognizer choices +* ARGUMENTS : +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of +*************************************************************************************/ +void BoxedFieldRecognizer::endRecoUnit () +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::endRecoUnit"<<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::endRecoUnit" + <<endl; + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-AUG-2005 +* NAME : recognize +* DESCRIPTION : This is the recognize call +* : The results of the recognition is set on the Recognition context +* : object. In case of BATCH_MODE recognition recognition of every +* : character is performed. otherwise the recognizer updates the outputs +* : with the recognized results +* ARGUMENTS : rc - The recognition context for the current recognition +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of +*************************************************************************************/ +int BoxedFieldRecognizer::recognize (LTKRecognitionContext& rc) +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::recognize" + <<endl; + + string tempStr = REC_UNIT_INFO; //temp string required to pass the arguments to set/get Flags + + int tempFlagValue = 0; //temp int to hold flag values + + int errorCode = 0; + + vector <LTKWordRecoResult>::iterator resultIter,resultEnd; //iterates through decoded recognition results + + int numWordRecoResults ; //Number of results required by the application + + int resultIndex ; //index to iterate through the results + + vector<unsigned short> resultString; //result + + float normConf; //normalized confidence + + //Returning FAILURE if the recognition context + //is not segmented into characters + + if((errorCode=rc.getFlag(tempStr,tempFlagValue))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::recognize"<<endl; + + LTKReturnError(errorCode); + } + + if( tempFlagValue != REC_UNIT_CHAR) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EINVALID_SEGMENT <<":"<< getErrorMessage(EINVALID_SEGMENT) + <<" BoxedFieldRecognizer::recognize" <<endl; + + LTKReturnError(EINVALID_SEGMENT); + } + + tempStr =REC_MODE; + + if((errorCode=rc.getFlag(tempStr,tempFlagValue))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::recognize"<<endl; + + LTKReturnError(errorCode); + } + + if(tempFlagValue == REC_MODE_BATCH) + { + //clear all the recognizer state + clearRecognizerState(); + recognizeTraces(rc); + } + else if (tempFlagValue == REC_MODE_STREAMING) + { + recognizeTraces(rc); + } + else + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EINVALID_REC_MODE <<":"<< getErrorMessage(EINVALID_REC_MODE) + <<" BoxedFieldRecognizer::recognize" <<endl; + + LTKReturnError(EINVALID_REC_MODE); + } + + /* Now all the recognized results are in + * m_decodedResults. + */ + + resultEnd = m_decodedResults.end(); + + for(resultIter = m_decodedResults.begin(); resultIter != resultEnd ; ++resultIter) + { + normConf = (*resultIter).getResultConfidence(); + + normConf /= ((*resultIter).getResultWord()).size(); + + (*resultIter).setResultConfidence(normConf); + + } + + //number of requested results + numWordRecoResults = rc.getNumResults(); + + //checking with existing recognition results' size + if(numWordRecoResults > m_decodedResults.size()) + { + LOG(LTKLogger::LTK_LOGLEVEL_INFO) + << "Don't have enough results to populate. Num of results available = " + << m_decodedResults.size() <<", however, results asked for =" + << numWordRecoResults <<endl; + } + + resultEnd = m_decodedResults.end(); + for(resultIndex =0,resultIter = m_decodedResults.begin();(resultIndex <numWordRecoResults)&&(resultIter != resultEnd); ++resultIndex,++resultIter) + { + //map the shape ids to unicode IDs + if((errorCode = LTKStrEncoding::shapeStrToUnicode(m_boxedShapeProject,(*resultIter).getResultWord(),resultString)) != SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::recognize"<<endl; + + LTKReturnError(errorCode); + } + + //adding the recognition result to recognition context + rc.addRecognitionResult(LTKWordRecoResult(resultString, + (*resultIter).getResultConfidence())); + + resultString.clear(); + + } + + //clearing state of the recognizer + clearRecognizerState(); + + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::recognize" + <<endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-AUG-2005 +* NAME : recognize +* DESCRIPTION : This method reset the recognizer +* ARGUMENTS : resetParam - This parameter could specify what to reset +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of +*************************************************************************************/ + int BoxedFieldRecognizer::reset (int resetParam) +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::reset"<<endl; + + clearRecognizerState(); + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::reset" + <<endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-AUG-2005 +* NAME : recognize +* DESCRIPTION : This method reset the recognizer +* ARGUMENTS : resetParam - This parameter could specify what to reset +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of +*************************************************************************************/ + int BoxedFieldRecognizer::unloadModelData() +{ + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::unloadModelData" + <<endl; + + //clear the recognition state + clearRecognizerState(); + + int errorCode=FAILURE; + + //unload the model data and + //delete the shape recognizer + if( m_shapeRecognizer && (m_module_deleteShapeRecognizer != NULL) ) + { + + if((errorCode = m_shapeRecognizer->unloadModelData()) != SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::unloadModelData"<<endl; + + + LTKReturnError(errorCode); + } + + if((errorCode = m_module_deleteShapeRecognizer(m_shapeRecognizer)) != SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::unloadModelData"<<endl; + + + LTKReturnError(errorCode); + } + + m_shapeRecognizer = NULL; + } + + //Freeing the shape recognition library + if(m_hAlgoDLLHandle) + { + m_OSUtilPtr->unloadSharedLib(m_hAlgoDLLHandle); + m_hAlgoDLLHandle = NULL; + } + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::unloadModelData" + <<endl; + + return SUCCESS; +} +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-AUG-2005 +* NAME : ~BoxedFieldRecognizer +* DESCRIPTION : destructor +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of +*************************************************************************************/ + +BoxedFieldRecognizer::~BoxedFieldRecognizer() +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::~BoxedFieldRecognizer" + <<endl; + + //unload the model data + + int errorCode = FAILURE; + if((errorCode = unloadModelData()) != SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::~BoxedFieldRecognizer"<<endl; + + throw LTKException(errorCode); + } + + delete m_OSUtilPtr; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::~BoxedFieldRecognizer" + <<endl; + + +} + + +//PRIVATE FUNCTIONS + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-AUG-2005 +* NAME : clearRecognizerState +* DESCRIPTION : Erase the state information of the recognizer +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of +*************************************************************************************/ + +void BoxedFieldRecognizer::clearRecognizerState() +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::clearRecognizerState" + <<endl; + + m_numCharsProcessed = 0; //initializing number of characters processed + m_numTracesProcessed = 0; //initializing number of traces processed + m_decodedResults.clear(); //clearing all the partially decoded results + m_boxedChar = LTKTraceGroup(); //assigning a new empty LTKTraceGroup + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::clearRecognizerState" + <<endl; + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-AUG-2005 +* NAME : recognizeTraces +* DESCRIPTION : performs the recognition of the new strokes added to rc +* : pre condition - markers are present in this vector +* : - m_numTracesProcessed and m_numCharsProcessed +* : set to proper value +* ARGUMENTS : rc - The recognitino context +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of +*************************************************************************************/ +int BoxedFieldRecognizer::recognizeTraces(LTKRecognitionContext& rc ) +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::recognizeTraces" + <<endl; + + vector<LTKTrace>::const_iterator traceIter,traceEnd,traceBegin; + //iterator for the traces + + int errorCode = FAILURE; + + int recUnit; //unit for recognition (should be char) + + LTKTraceGroup emptyChar; + //TraceGroup object that buffers + //all ink corresponding to a character + + vector<int> subSet; + //passing a null arguement for shape subset + + vector<LTKShapeRecoResult> shapeRecoResults; + //The object to hold the output from shape recognizer + + LTKScreenContext screenContext = rc.getScreenContext(); + //retrieving the screen context + + LTKCaptureDevice captureDevice = rc.getDeviceContext(); + //retrieving the device context + + const LTKTraceVector & traces = rc.getAllInk(); + //retrieving the traces from recognition context + + string tempStr; //temporary string object + + + if(m_shapeRecognizer == NULL) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) <<"Shape recognizer not initialized" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENULL_POINTER <<":"<< getErrorMessage(ENULL_POINTER) + <<" BoxedFieldRecognizer::recognizeTraces" <<endl; + + LTKReturnError(ENULL_POINTER); + + } + else if( (errorCode = m_shapeRecognizer->setDeviceContext(captureDevice)) != SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Unable to set device context in shape rec : " << getErrorMessage(errorCode) <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::recognizeTraces"<<endl; + + LTKReturnError(errorCode); + } + + shapeRecoResults.reserve(m_numShapeRecoResults+1);//reserving memory + + + if(m_numTracesProcessed > traces.size()) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Invalid number of traces processed. " + << "Traces processed = " << m_numTracesProcessed + << " > total number of traces" << traces.size() <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EINVALID_NUM_OF_TRACES <<":"<< getErrorMessage(EINVALID_NUM_OF_TRACES) + <<" BoxedFieldRecognizer::recognizeTraces" <<endl; + + LTKReturnError(EINVALID_NUM_OF_TRACES); + } + //Start processing from the number of traces processed. + traceBegin = traces.begin() + m_numTracesProcessed; + traceEnd = traces.end();int r=0; + + for(traceIter = traceBegin; traceIter != traceEnd; ++traceIter) + { + /* Marker strokes are inserted to detect + * end of segment. The marker strokes are + * identified by 9number of channels == 0) + */ + if((*traceIter).getNumberOfPoints() == 0) + { + tempStr = REC_UNIT_INFO; + if((errorCode = rc.getFlag(tempStr,recUnit)) != SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::recognizeTraces"<<endl; + + LTKReturnError(errorCode); + } + switch(recUnit) + { + + /* The segment is character + * This algorithm recognizes + * only character segments + */ + case REC_UNIT_CHAR: + shapeRecoResults.clear(); + //calling the shape recognizer's recognize method. + + if(m_boxedChar.getNumTraces() == 0) + { + LTKShapeRecoResult T; + T.setShapeId(SHRT_MAX); + T.setConfidence(1.0); + shapeRecoResults.push_back(T); + } + else if( (errorCode = m_shapeRecognizer->recognize(m_boxedChar,screenContext,subSet, + m_shapeRecoMinConfidence, m_numShapeRecoResults, shapeRecoResults ))!= SUCCESS ) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Shape recognition failed : " << getErrorMessage(errorCode) <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::recognizeTraces"<<endl; + + LTKReturnError(errorCode); + } + + + //This updates the recognition results using + //current shape recognition results + + if((errorCode = updateRecognitionResults(shapeRecoResults,rc)) != SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: BoxedFieldRecognizer::recognizeTraces"<<endl; + + LTKReturnError(errorCode); + } + + for(r=0;r<shapeRecoResults.size();++r) + { + LTKShapeRecoResult& tempResult=shapeRecoResults[r]; + + } + + m_boxedChar = emptyChar;//making the trace group empty again + break; + + default: + LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Unsupported reccognizer mode by Box Field" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EINVALID_RECOGNITION_MODE <<":"<< getErrorMessage(EINVALID_RECOGNITION_MODE) + <<" BoxedFieldRecognizer::recognizeTraces" <<endl; + + LTKReturnError(EINVALID_RECOGNITION_MODE); + + } + ++m_numCharsProcessed; //incrementing number of characters processed + } + else + { + m_boxedChar.addTrace(*traceIter); //buffering the trace to the temp TraceGroup for recognition + } + ++m_numTracesProcessed; //incrementing the number of traces processed + } + + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::recognizeTraces" + <<endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-AUG-2005 +* NAME : updateRecognitionResults +* DESCRIPTION : This function tries to update the +* : shape recognition choices with new shape recognition results +* ARGUMENTS : results - new results for updating the results +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of +*************************************************************************************/ +int BoxedFieldRecognizer::updateRecognitionResults(const vector<LTKShapeRecoResult>& results, LTKRecognitionContext& rc) +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::updateRecognitionResults" + <<endl; + + multimap< float, pair<int,int>, greater<float> >backTrace; + //A multi map is used for finding best N paths + multimap< float, pair<int,int>, greater<float> >::iterator iter, iterend; + //Iterator for accessing elements of the map + pair<int,int> combination; + //Temporary variable that keeps a (int,int) pair + int wordResultIndex, shapeResultIndex; + //loop index variables + float wordConfidence, shapeConfidence; + //word level and shape level confidences + unsigned short newSymbol; + //temporary storage for shape recognizer id + float newConf; //temporary storage for shape recognizer confidence + + vector<LTKWordRecoResult> newResultVector; + //new results after finding the best N paths + + int numWordRecoResults = rc.getNumResults(); + //number of word recognition results requested + int numShapeRecoResults = results.size(); + //number of choices from the shape recognizer + vector<unsigned short>initVec; + //for initializing the trellis + + + + //If there is no decoded results (First shape recognition in the word) + if(m_decodedResults.empty()) + { + //Initializing the results vector + m_decodedResults.assign(numShapeRecoResults,LTKWordRecoResult()); + + //iterating through different word recognition choices + for(wordResultIndex = 0; (wordResultIndex<numShapeRecoResults); ++wordResultIndex) + { + //Retrieving the shape recognition choices + + newSymbol = results.at(wordResultIndex).getShapeId(); + newConf = results.at(wordResultIndex).getConfidence(); + + //updating the results + + initVec.assign(1,newSymbol); + m_decodedResults.at(wordResultIndex).setWordRecoResult(initVec,newConf); + + } + } + + else + { + //initializing a temporary result vector + //newResultVector.assign(smallerResultNumber,LTKWordRecoResult()); + + //iterating through each word recognition result + for(wordResultIndex=0; wordResultIndex<m_decodedResults.size(); ++wordResultIndex) + { + wordConfidence = (m_decodedResults.at(wordResultIndex)).getResultConfidence(); + + //iterating through each shape recognition results + for(shapeResultIndex =0; shapeResultIndex<numShapeRecoResults; ++shapeResultIndex ) + { + //adding total confidence to the map. so that later they + //can be retrieved in the sorted order + shapeConfidence = (results.at(shapeResultIndex)).getConfidence(); + backTrace.insert( pair<float, pair<int,int> >( (shapeConfidence+wordConfidence), + pair<int,int>(wordResultIndex,shapeResultIndex))); + } + } + + iterend = backTrace.end(); + + //iterating through the map to retrieve the largest confidences. + for(wordResultIndex = 0,iter = backTrace.begin(); (wordResultIndex<numWordRecoResults)&&(iter!= iterend); ++wordResultIndex,++iter) + { + + //confidence + wordConfidence = (*iter).first; + + //the combination that gave this + //confidence + combination = (*iter).second; + + //copying the word reco result corresponding to + //the combination to new result vector + //newResultVector.at(wordResultIndex) = m_decodedResults.at(combination.first); + LTKWordRecoResult tempWordRecoResult = m_decodedResults.at(combination.first); + + //retrieving the shape recognition result id + //and confidence corresponding to the combination + newSymbol = results.at(combination.second).getShapeId(); + newConf = results.at(combination.second).getConfidence(); + + //updating the word reco result with new id and confidence + //newResultVector.at(wordResultIndex).updateWordRecoResult(newSymbol, newConf); + + tempWordRecoResult.updateWordRecoResult(newSymbol,newConf); + newResultVector.push_back(tempWordRecoResult); + } + + //assigning the newly created result vector + m_decodedResults = newResultVector; + } + + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::updateRecognitionResults" + <<endl; + + + return SUCCESS; +} + + +/********************************************************************************** +* 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; + + int 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_lipiLib, 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) + } + + // Construct LTKControlInfo object + LTKControlInfo controlInfo; + controlInfo.projectName = strProjectName; + controlInfo.profileName = strLocalProfileName; + controlInfo.lipiRoot = m_lipiRoot; + controlInfo.lipiLib = m_lipiLib; + controlInfo.toolkitVersion = m_toolkitVersion; + + *outShapeRecPtr = NULL; + + /* Error, unable to create shape recognizer instance */ + if((errorCode = m_module_createShapeRecognizer(controlInfo,outShapeRecPtr)) != SUCCESS) + { + + *outShapeRecPtr = NULL; + + delete projectCfgFileEntries; + delete profileCfgFileEntries; + + errorCode = ECREATE_SHAPEREC; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ECREATE_SHAPEREC <<":"<< getErrorMessage(ECREATE_SHAPEREC) + <<" BoxedFieldRecognizer::createShapeRecognizer" <<endl; + + + + LTKReturnError(errorCode); + } + + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << + "Exiting BoxedFieldRecognizer::createShapeRecognizer" << endl; + + delete projectCfgFileEntries; + delete profileCfgFileEntries; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::createShapeRecognizer" + <<endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Thanigai +* DATE : 29-JUL-2005 +* NAME : mapShapeAlgoModuleFunctions +* DESCRIPTION : To map function addresses of the methods exposed by +* the shape recognition modules +* ARGUMENTS : None +* RETURNS : 0 on success and other values on error +* NOTES : +* CHANGE HISTROY +* Author Date Description of +*************************************************************************************/ +int BoxedFieldRecognizer::mapShapeAlgoModuleFunctions() +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Entering: BoxedFieldRecognizer::mapShapeAlgoModuleFunctions" + <<endl; + + int returnVal = SUCCESS; + m_module_createShapeRecognizer = NULL; + + void* functionHandle = NULL; + returnVal = m_OSUtilPtr->getFunctionAddress(m_hAlgoDLLHandle, + CREATESHAPERECOGNIZER_FUNC_NAME, + &functionHandle); + + if(returnVal != SUCCESS) + { + LOG( LTKLogger::LTK_LOGLEVEL_ERR) << + "Exported function not found in module : createShapeRecognizer "<<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EDLL_FUNC_ADDRESS <<":"<< getErrorMessage(EDLL_FUNC_ADDRESS) + <<" BoxedFieldRecognizer::mapShapeAlgoModuleFunctions" <<endl; + + LTKReturnError(EDLL_FUNC_ADDRESS); + // ERROR: Unable to link with createShapeRecognizer function in module */ + } + + m_module_createShapeRecognizer = (FN_PTR_CREATESHAPERECOGNIZER)functionHandle; + + functionHandle = NULL; + + + // map delete shape recognizer function + returnVal = m_OSUtilPtr->getFunctionAddress(m_hAlgoDLLHandle, + DELETESHAPERECOGNIZER_FUNC_NAME, + &functionHandle); + + if(returnVal != SUCCESS) + { + LOG( LTKLogger::LTK_LOGLEVEL_ERR) << + "Exported function not found in module : deleteShapeRecognizer " << endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EDLL_FUNC_ADDRESS <<":"<< getErrorMessage(EDLL_FUNC_ADDRESS) + <<" BoxedFieldRecognizer::mapShapeAlgoModuleFunctions" <<endl; + + LTKReturnError(EDLL_FUNC_ADDRESS); + } + + m_module_deleteShapeRecognizer = (FN_PTR_DELETESHAPERECOGNIZER)functionHandle; + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) + <<"Exiting: BoxedFieldRecognizer::mapShapeAlgoModuleFunctions" + <<endl; + + return SUCCESS; +} + + + diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/BoxFieldRecognizer.h b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/BoxFieldRecognizer.h new file mode 100644 index 00000000..e0703b5a --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/BoxFieldRecognizer.h @@ -0,0 +1,231 @@ +/***************************************************************************************** +* Copyright (c) 2006 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in +* the Software without restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +* Software, and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +* THE SOFTWARE. +******************************************************************************/ + +/************************************************************************ + * SVN MACROS + * + * $LastChangedDate: 2008-07-18 15:00:39 +0530 (Fri, 18 Jul 2008) $ + * $Revision: 561 $ + * $Author: sharmnid $ + * + ************************************************************************/ +/************************************************************************ + * FILE DESCR: Definitions for DP word recognizer + * + * CONTENTS: + * + * AUTHOR: Deepu V. + * + * DATE: August 17, 2005 + * CHANGE HISTORY: + * Author Date Description of + ************************************************************************/ + +#ifndef __BOXFIELDRECOGNIZER_H +#define __BOXFIELDRECOGNIZER_H + +#include "LTKWordRecognizer.h" +#include "LTKLoggerUtil.h" +#include "LTKWordRecoResult.h" +#include "LTKShapeRecoResult.h" + +class LTKShapeRecognizer; +class LTKWordRecoConfig; +class LTKOSUtil; + +typedef int (*FN_PTR_CREATESHAPERECOGNIZER)(const LTKControlInfo&, + LTKShapeRecognizer**); + +typedef int (*FN_PTR_DELETESHAPERECOGNIZER)(LTKShapeRecognizer*); + + +/** +* @class BoxedFieldWordRecognizer +* <p> This class contains the implementation of the Boxed Field +* word recognizer</p> +*/ + +class BoxedFieldRecognizer : public LTKWordRecognizer +{ +private: + + /** Boxed Field Recognizer config file name */ + string m_boxedConfigFile; + + /** Lipi root */ + string m_lipiRoot; + + /** Lipi libraries */ + string m_lipiLib; + + /** Isolated shape recognizer project used for recognizing each box */ + string m_boxedShapeProject; + + /** Profile for the shape recognition project */ + string m_boxedShapeProfile; + + /** + * @name shape recognizer related + */ + + // @{ + LTKShapeRecognizer *m_shapeRecognizer; // shape recognizer + + /** Number of results from shape recognizer */ + int m_numShapeRecoResults; + + /** The confidence parameter input to shape recognizer */ + float m_shapeRecoMinConfidence; + + /** Temporary trace group that holds the strokes for recognition */ + LTKTraceGroup m_boxedChar; + + string m_logFile; + + LTKLogger::EDebugLevel m_logLevel; + + string m_toolkitVersion; + + LTKOSUtil* m_OSUtilPtr; + // @} + + /** + * @name Shape recognizer loading + */ + + /** Factory method to create the shape recognizer */ + FN_PTR_CREATESHAPERECOGNIZER m_module_createShapeRecognizer; + + /** Factory method to delete the shape recognizer */ + FN_PTR_DELETESHAPERECOGNIZER m_module_deleteShapeRecognizer; + + //void * m_hAlgoDLLHandle; //handle to the wordrecognition algorithm + + /** + * @name state of recognizer + */ + // @{ + + /** Number of characters processed so far */ + int m_numCharsProcessed; + + /** Number of traces processed so far */ + int m_numTracesProcessed; + + /** maintains decoded recognition results after each trace, upto max style length */ + vector <LTKWordRecoResult> m_decodedResults; + + // @} + +public: + /** + * @name Constructors and Destructor + */ + // @{ + + + /** + * Parameterized Constructor + */ + + BoxedFieldRecognizer(const LTKControlInfo& controlInfo); + /** + * Destructor + */ + + virtual ~BoxedFieldRecognizer(); + // @} + + + /** + * This method is called from recognition context whenever new traces + * are added to it. The Recognizer need to process the new traces + * in this methods and updates the internal state. + * @param rc The recognition context for the current recognition + */ + int processInk (LTKRecognitionContext& rc); + + /** + * This function notifies the recognizer that end of current ink is + * the end of a logic segment. This information could be used in + * constraining the recognizer choices + */ + void endRecoUnit () ; + + /** + * This is the recognize call. In case of trace by trace recognition + * The results of the recognition is set on the Recognition context + * object. + * @param rc The recognition context for the current recognition + */ + int recognize (LTKRecognitionContext& rc) ; + + /** + * This method unloads all the training data + * To re-initialize the recognizer call the + * API initialize again + */ + int unloadModelData(); + + + /** + * This method reset the recognizer. + * @param resetParam This parameter could specify what to reset + */ + int reset (int resetParam = 0) ; + // @} +private: + + /** + * performs the recognition of the new strokes added to recognition context + * @param rc The recognitino context + */ + + int recognizeTraces(LTKRecognitionContext& rc); + + /** + * Erase the state information of the recognizer + */ + void clearRecognizerState(); + + /** + * This function tries to update the + * shape recognition choices with new shape recognition results + * @param results New results for updating the results + */ + int updateRecognitionResults(const vector<LTKShapeRecoResult>& results, LTKRecognitionContext& rc); + + /** + * This function loads and create a shape recognizer + * from DLL/shared object + **/ + int createShapeRecognizer(const string& strProjectName, const string& strProfileName,LTKShapeRecognizer** outShapeRecPtr); + + /** + * This function loads functions pointers + * from the shape recognizer DLL/SO + **/ + int mapShapeAlgoModuleFunctions(); + + + int readClassifierConfig(); + +}; +#endif //#ifndef __BOXFIELDRECOGNIZER_H diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.cfg b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.cfg new file mode 100644 index 00000000..b727da97 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.cfg @@ -0,0 +1,13 @@ +#Number of characters per field +MaxBoxCount = 30 + +#The shaperecognizer project and profile name +BoxedShapeProject = numerals +BoxedShapeProfile = default + +#Min confidence from shape recognizer +MinShapeConfid = 0 + +#Number of choices requested from the shape recognizer +NumShapeChoices = 3 + diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.cpp new file mode 100644 index 00000000..45969652 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.cpp @@ -0,0 +1,129 @@ +/***************************************************************************************** +* Copyright (c) 2006 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in +* the Software without restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +* Software, and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*****************************************************************************************/ + +/************************************************************************ + * SVN MACROS + * + * $LastChangedDate: 2011-01-11 13:48:17 +0530 (Tue, 11 Jan 2011) $ + * $Revision: 827 $ + * $Author: mnab $ + * + ************************************************************************/ +/************************************************************************ + * FILE DESCR: Implementation of boxfld dll exported functions. + * + * CONTENTS: + * + * AUTHOR: Deepu V. + * + * DATE: Aug 23, 2005 + * CHANGE HISTORY: + * Author Date Description of + ************************************************************************/ +#include "boxfld.h" +#include "LTKMacros.h" +#include "LTKException.h" + + +#ifdef _WIN32 + +//DLL MAIN for Windows +BOOL APIENTRY DllMain( HANDLE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved + ) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + +#endif + +/********************************************************************************** +* AUTHOR : Deepu V +* DATE : 23-Aug-2005 +* NAME : createWordRecognizer +* DESCRIPTION : Crates instance of type BoxField Recongnizer and retuns of type + LTKWordRecongizer. (Acts as a Factory Method). +* ARGUMENTS : +* RETURNS : returns an instace of type LTKWordRecoginzer. +* NOTES : +* CHANGE HISTORY +* Author Date Description of +*************************************************************************************/ +int createWordRecognizer(const LTKControlInfo& controlInfo,LTKWordRecognizer** boxFldRecoPtr) +{ + + try + { + *boxFldRecoPtr = (LTKWordRecognizer*) new BoxedFieldRecognizer(controlInfo); + } + catch(LTKException e) + { + *boxFldRecoPtr = NULL; + LTKReturnError(e.getErrorCode()); + } + + return SUCCESS; + +} + +/********************************************************************************** +* AUTHOR : Deepu V +* DATE : 23-Aug-2005 +* NAME : deleteWordRecognizer +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : returns an instace of type LTKWordRecoginzer. +* NOTES : +* CHANGE HISTORY +* Author Date Description of +*************************************************************************************/ +//Destroys the instance by taking its addess as its argument. +int deleteWordRecognizer(LTKWordRecognizer* obj) +{ + /*delete obj; + + obj = NULL; + + return SUCCESS;*/ + + try + { + if (obj != NULL ) + { + delete obj; + obj = NULL; + } + } + catch(LTKException e) + { + LTKReturnError(e.getErrorCode()); + } + + + return SUCCESS; +} diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.def b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.def new file mode 100644 index 00000000..452b6dd6 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.def @@ -0,0 +1,3 @@ +EXPORTS + createWordRecognizer @1 + deleteWordRecognizer @2 diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.h b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.h new file mode 100644 index 00000000..f44d2ab3 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.h @@ -0,0 +1,90 @@ +/***************************************************************************************** +* Copyright (c) 2006 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in +* the Software without restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +* Software, and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*****************************************************************************************/ + +/************************************************************************ + * SVN MACROS + * + * $LastChangedDate: 2008-07-18 15:00:39 +0530 (Fri, 18 Jul 2008) $ + * $Revision: 561 $ + * $Author: sharmnid $ + * + ************************************************************************/ +/************************************************************************ + * FILE DESCR: Definitions for boxfld dll exporting functions. + * + * CONTENTS: + * + * AUTHOR: Deepu V. + * + * DATE: Aug 23, 2005 + * CHANGE HISTORY: + * Author Date Description of + ************************************************************************/ +#ifndef __BOXFLD_H__ +#define __BOXFLD_H__ + +#ifdef _WIN32 +#include <windows.h> +// The following ifdef block is the standard way of creating macros which make exporting +// from a DLL simpler. All files within this DLL are compiled with the DTW_EXPORTS +// symbol defined on the command line. this symbol should not be defined on any project +// that uses this DLL. This way any other project whose source files include this file see +// DTW_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. +#ifdef BOXFLD_EXPORTS +#define BOXFLD_API __declspec(dllexport) +#else +#define BOXFLD_API __declspec(dllimport) +#endif +#else +#define BOXFLD_API +#endif //#ifdef _WIN32 + + +#include "LTKWordRecognizer.h" +#include "BoxFieldRecognizer.h" +#include "LTKLoggerUtil.h" +#include "LTKErrors.h" + +void *m_hAlgoDLLHandle; + +/** + * Crates instance of type PCAShaperecongnizer and retuns of type + * LTKShpeRecongizer. (Acts as a Factory Method). + * + * @param void - No argument + * + * @return LTKShapeRecognizer - an instace of type LTKShapeRecoginzer. + */ + +//Creates Instance of the Box Field recognizer and returns base class (LTKWordRecognizer) pointer +extern "C" BOXFLD_API int createWordRecognizer(const LTKControlInfo& controlInfo,LTKWordRecognizer** boxFldRecoPtr); + +/** + * Destry the instance by taking the address as its argument. + * + * @param obj - Address of LTKShapeRecognizer instnace. + * + * @return 0 on Success + */ + +//Destroys the instance by taking its addess as its argument. +extern "C" BOXFLD_API int deleteWordRecognizer(LTKWordRecognizer* obj); + +#endif //#ifndef __BOXFLD_H__ diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.pro b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.pro new file mode 100644 index 00000000..5d16d041 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/boxfld/boxfld.pro @@ -0,0 +1,20 @@ +LIPILIBS = shaperecommon ltkcommon ltkutil wordreccommon +include(../../../lipiplugin.pri) + +INCLUDEPATH += \ + ../../../util/lib \ + ../common \ + +HEADERS += \ + BoxFieldRecognizer.h \ + boxfld.h \ + +SOURCES += \ + BoxFieldRecognizer.cpp \ + boxfld.cpp \ + +win32 { + DEFINES += BOXFLD_EXPORTS + LIBS += Advapi32.lib + #DEF_FILE = boxfld.def +} diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/LTKRecognitionContext.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/LTKRecognitionContext.cpp new file mode 100644 index 00000000..4fc45305 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/LTKRecognitionContext.cpp @@ -0,0 +1,1065 @@ +/***************************************************************************************** +* Copyright (c) 2006 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in +* the Software without restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +* Software, and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*****************************************************************************************/ + +/************************************************************************ + * SVN MACROS + * + * $LastChangedDate$ + * $Revision$ + * $Author$ + * + ************************************************************************/ +/************************************************************************ + * FILE DESCR: Implementation of LTKRecognitionContext that holds the context + * for recognition + * + * CONTENTS: + * addTrace + * addTraceGroup + * beginRecoUnit + * endRecoUnit + * getAllInk + * getConfidThreshold + * getDeviceContext + * getFlag + * getLanguageModel + * getNextBestResults + * getNumResults + * getScreenContext + * getTopResult + * setConfidThreshold + * setDeviceContext + * setFlag + * setLanguageModel + * setNumResults + * setScreenContext + * addRecognitionResult + * recognize + * reset + * + * AUTHOR: Deepu V. + * + * DATE: February 22, 2005 + * CHANGE HISTORY: + * Author Date Description of change + * Thanigai 3-AUG-2005 Added default constructor and setWordRecoEngine + * methods. + * + * Deepu 30-AUG-2005 Replaced LTKWordRecoEngine with LTKWordRecognizer + * Changed the representation of m_recognitionFlags + * since there was a problem with dlls +************************************************************************/ + +#include "LTKRecognitionContext.h" +#include "LTKMacros.h" +#include "LTKErrors.h" +#include "LTKTrace.h" + +#include "LTKErrorsList.h" + +#include "LTKTraceGroup.h" + +#include "LTKWordRecoResult.h" + +#include "LTKWordRecognizer.h" + +#include "LTKLoggerUtil.h" + +#include "LTKException.h" + +/********************************************************************************** +* AUTHOR : Thanigai +* DATE : 3-AUG-2005 +* NAME : LTKRecognitionContext +* DESCRIPTION : Default constructor +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +LTKRecognitionContext::LTKRecognitionContext() +:m_confidThreshold(0), +m_numResults(0), +m_nextBestResultIndex(0), +m_wordRecPtr(NULL) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::LTKRecognitionContext()" << endl; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::LTKRecognitionContext()" << endl; +} + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-FEB-2005 +* NAME : LTKRecognitionContext +* DESCRIPTION : Initialization constructor +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +LTKRecognitionContext::LTKRecognitionContext(LTKWordRecognizer *wordRecPtr ) +:m_wordRecPtr(wordRecPtr), +m_confidThreshold(0), +m_numResults(0), +m_nextBestResultIndex(0) + +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::LTKRecognitionContext(LTKWordRecognizer*)" << endl; + + if(m_wordRecPtr == NULL) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENULL_POINTER <<":"<< getErrorMessage(ENULL_POINTER) + <<" LTKRecognitionContext::LTKRecognitionContext(LTKWordRecognizer*)" <<endl; + + throw LTKException(ENULL_POINTER); + } + + m_recognitionFlags.clear(); + m_wordRecPtr = wordRecPtr; + + + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::LTKRecognitionContext(LTKWordRecognizer*)" << endl; +} + + + +/********************************************************************************** +* AUTHOR : Thanigai +* DATE : 3-AUG-2005 +* NAME : setWordRecoEngine +* DESCRIPTION : Accepts the handle to word recognition engine and store it locally +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKRecognitionContext::setWordRecoEngine(LTKWordRecognizer *wordRecPtr) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::setWordRecoEngine()" << endl; + + if(wordRecPtr == NULL) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENULL_POINTER <<":"<< getErrorMessage(ENULL_POINTER) + <<" LTKRecognitionContext::setWordRecoEngine()" <<endl; + + LTKReturnError(ENULL_POINTER); + } + m_wordRecPtr = wordRecPtr; + + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::setWordRecoEngine()" << endl; + + return SUCCESS; +} + + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-FEB-2005 +* NAME : addTrace +* DESCRIPTION : This function adds a trace to the recognition context for +* recognition +* ARGUMENTS : trace - the trace to be added +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKRecognitionContext::addTrace (const LTKTrace& trace) +{ + int recMode; //strokes temporary string for getFlag + string tempStr; // the recognition mode + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::addTrace()" << endl; + + + m_fieldInk.push_back(trace); //pushing incoming trace to local buffer + + //if the recognition mode is set to streaming mode + //the recognizer is called at this point + + tempStr = REC_MODE; + + int errorCode; + + if((errorCode = getFlag(tempStr,recMode))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKRecognitionContext::addTrace()"<<endl; + + LTKReturnError(errorCode); + } + + if(recMode == REC_MODE_STREAMING) + { + m_wordRecPtr->processInk(*this); + } + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::addTrace()" << endl; + + + return SUCCESS; + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-FEB-2005 +* NAME : addTraceGroup +* DESCRIPTION : Adds a vector of tracegroup for recognition in the recognition context +* ARGUMENTS : fieldInk - the ink to be added. +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKRecognitionContext::addTraceGroups (const LTKTraceGroupVector& fieldInk) +{ + int numTraceGroups = fieldInk.size(); //number of trace groups + int numTraces =0; //number of traces in each trace group + string tempStr; //strokes temporary string for getFlag + int recMode =0; // the recognition mode + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::addTraceGroups()" << endl; + + for(int i =0; i<numTraceGroups; ++i) + { + //accessing each trace group + const LTKTraceGroup& traceGp = fieldInk[i]; + + //get all traces from tracegp + //const LTKTraceVector& allTraces = traceGp.getAllTraces(); + const LTKTraceVector& allTraces = traceGp.getAllTraces(); + + //push each trace to local buffer + numTraces = allTraces.size(); + + for(int j = 0; j<numTraces; ++j) + { + m_fieldInk.push_back(allTraces[j]); + } + + LOG(LTKLogger::LTK_LOGLEVEL_INFO) << "Pushed Trace Group:"<<i<<endl; + + } + + //if the recognition mode is set to streaming mode + //the recognizer is called at this point + tempStr = REC_MODE; + + int errorCode; + + if((errorCode = getFlag(tempStr,recMode))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKRecognitionContext::addTraceGroups()"<<endl; + + LTKReturnError(errorCode); + } + + if(recMode == REC_MODE_STREAMING) + { + m_wordRecPtr->processInk(*this); + } + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::addTraceGroups()" << endl; + + + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : beginRecoUnit +* DESCRIPTION : This function marks the beginning of a recognition unit of Ink. +* ARGUMENTS : none +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void LTKRecognitionContext::beginRecoUnit ( ) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::beginRecoUnit()" << endl; + + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::beginRecoUnit()" << endl; + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : clearRecognitionResult +* DESCRIPTION : clears all the recognition results +* ARGUMENTS : none +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKRecognitionContext::clearRecognitionResult ( ) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::clearRecognitionResult()" << endl; + + //clearing the results + m_results.clear(); + + //reset the index of next best result + m_nextBestResultIndex = 0; + + m_fieldInk.clear(); + + int errorCode; + + if((errorCode=m_wordRecPtr->reset())!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKRecognitionContext::clearRecognitionResult()"<<endl; + + LTKReturnError(errorCode); + } + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::clearRecognitionResult()" << endl; + + return SUCCESS; +} + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : endRecoUnit +* DESCRIPTION : This function marks the ending of a recognition unit of Ink. +* ARGUMENTS : none +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +void LTKRecognitionContext::endRecoUnit ( ) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::endRecoUnit()" << endl; + + //pushing a "marker" into the stream + m_fieldInk.push_back(LTKTrace()); + + //calling the marker of the recognizer + m_wordRecPtr->endRecoUnit(); + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::endRecoUnit()" << endl; +} + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : getAllInk +* DESCRIPTION : Access function for the internal Ink data. +* ARGUMENTS : none +* RETURNS : reference to internal Ink data +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +const LTKTraceVector& LTKRecognitionContext::getAllInk () const +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::getAllInk()" << endl; + + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::getAllInk()" << endl; + + return m_fieldInk; + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : getConfidThreshold +* DESCRIPTION : Access function for internal confidence threshold +* ARGUMENTS : none +* RETURNS : confidence threshold +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +float LTKRecognitionContext::getConfidThreshold () const +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::getConfidThreshold()" << endl; + + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::getConfidThreshold()" << endl; + + return m_confidThreshold; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : getDeviceContext +* DESCRIPTION : Access function for device context +* ARGUMENTS : none +* RETURNS : reference to LTKCapture device +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +const LTKCaptureDevice& LTKRecognitionContext::getDeviceContext ( ) const +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::getDeviceContext()" << endl; + + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::getDeviceContext()" << endl; + + return m_deviceContext; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : getFlag +* DESCRIPTION : Returns the value of the flag +* ARGUMENTS : key - index of map +* RETURNS : value of queried flag (int) +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +int LTKRecognitionContext::getFlag (const string& key,int& outValue) const +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::getFlag()" << endl; + + if(key=="") + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_STRING <<":"<< getErrorMessage(EEMPTY_STRING) + <<" LTKRecognitionContext::getFlag()" <<endl; + + LTKReturnError(EEMPTY_STRING); + } + + vector<pair<string,int> >::const_iterator iter,iterEnd; + + iterEnd = m_recognitionFlags.end(); + + //Iterating through the vector to find the key + for(iter = m_recognitionFlags.begin(); iter != iterEnd; ++iter) + { + if( (*iter).first == key ) + { + outValue = (*iter).second; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::getFlag()" << endl; + + return SUCCESS; + } + } + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EKEY_NOT_FOUND <<":"<< getErrorMessage(EKEY_NOT_FOUND) + <<" LTKRecognitionContext::getFlag()" <<endl; + + LTKReturnError(EKEY_NOT_FOUND); + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : getLanguageModel +* DESCRIPTION : returns the current language model indexed by the key +* ARGUMENTS : key - index of map +* RETURNS : value of the queried language model (string) +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +int LTKRecognitionContext::getLanguageModel (const string& key, + string& outValue) const +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::getLanguageModel()" << endl; + + if(key=="") + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_STRING <<":"<< getErrorMessage(EEMPTY_STRING) + <<" LTKRecognitionContext::getLanguageModel()" <<endl; + + LTKReturnError(EEMPTY_STRING); + } + + + stringStringMap::const_iterator iterMap; + + iterMap = this->m_languageModels.find(key); + + if(iterMap != m_languageModels.end() ) + { + outValue = iterMap->second; + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::getLanguageModel()" << endl; + return SUCCESS; + } + + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EKEY_NOT_FOUND <<":"<< getErrorMessage(EKEY_NOT_FOUND) + <<" LTKRecognitionContext::getLanguageModel()" <<endl; + + LTKReturnError(EKEY_NOT_FOUND); + + + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : getNextBestResults +* DESCRIPTION : returns the next N best results +* ARGUMENTS : numResults - number of results required +* : results - This will be populated with results +* RETURNS : SUCCESS/FAILURE +* NOTES : Maximum number of results added is limited by number of results +* : available. +* : vector is not cleared inside the function +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKRecognitionContext::getNextBestResults (int numResults, + LTKWordRecoResultVector& outWordRecResults) +{ + int lastIndex = 0;//Last index + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::getNextBestResults()" << endl; + + if(numResults<=0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENON_POSITIVE_NUM <<":"<< getErrorMessage(ENON_POSITIVE_NUM) + <<" LTKRecognitionContext::getNextBestResults()" <<endl; + + LTKReturnError(ENON_POSITIVE_NUM); + } + + vector<LTKWordRecoResult>::const_iterator resultBegin, resultEnd, resultIter; + + //Finding index of requested results + resultBegin = m_results.begin() + m_nextBestResultIndex; + + //Finding index of requested results + resultEnd = m_results.begin() + m_nextBestResultIndex + numResults; + + if(resultBegin > resultEnd +) + { + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << + "Exiting LTKRecognitionContext::getNextBestResults" <<endl; + + return SUCCESS; + } + + //limiting the end to the limits of available results + if(resultEnd > m_results.end() ) + resultEnd = m_results.end(); + + //pushing back the results + for(resultIter = resultBegin; resultIter< resultEnd; ++resultIter) + { + outWordRecResults.push_back(*resultIter); + } + + //updating next best result index + m_nextBestResultIndex += numResults; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::getNextBestResults()" << endl; + + return SUCCESS; + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : getNumResults +* DESCRIPTION : parameter number of results +* ARGUMENTS : none +* RETURNS : number of results (int) +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +int LTKRecognitionContext::getNumResults () const +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::getNumResults()" << endl; + + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::getNumResults()" << endl; + + return m_numResults; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : getScreenContext +* DESCRIPTION : access function for the screen context +* ARGUMENTS : none +* RETURNS : reference to screencontext object +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +const LTKScreenContext& LTKRecognitionContext::getScreenContext ( ) const +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::getScreenContext()" << endl; + + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::getScreenContext()" << endl; + + return m_screenContext; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : getTopResult +* DESCRIPTION : get the top result from the recognition context +* ARGUMENTS : result - will be assigned to the top recognition result +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKRecognitionContext::getTopResult (LTKWordRecoResult& outTopResult) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::getTopResult()" << endl; + + if(m_results.size() == 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_WORDREC_RESULTS <<":"<< getErrorMessage(EEMPTY_WORDREC_RESULTS) + <<" LTKRecognitionContext::getTopResult()" <<endl; + + LTKReturnError(EEMPTY_WORDREC_RESULTS); + } + + m_nextBestResultIndex = 1; + + //assigning the value to output + outTopResult = m_results[0]; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::getTopResult()" << endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : setConfidThreshold +* DESCRIPTION : set the confidence threshold +* ARGUMENTS : thresh - the threshold value to be set +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKRecognitionContext::setConfidThreshold (float thresh) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::setConfidThreshold()" << endl; + + if(thresh < 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENEGATIVE_NUM <<":" + << getErrorMessage(ENEGATIVE_NUM) + <<" LTKRecognitionContext::setConfidThreshold()" <<endl; + + LTKReturnError(ENEGATIVE_NUM); + } + + m_confidThreshold = thresh; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::setConfidThreshold()" << endl; + + return SUCCESS; +} + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : setDeviceContext +* DESCRIPTION : set the device context +* ARGUMENTS : dc - reference to device context object to be set +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void LTKRecognitionContext::setDeviceContext (const LTKCaptureDevice& dc) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::setDeviceContext()" << endl; + + m_deviceContext = dc; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::setDeviceContext()" << endl; + + + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : setFlag +* DESCRIPTION : sets the flag +* ARGUMENTS : key - index of the flag to be set +* : value - value of the flag to be set +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +int LTKRecognitionContext::setFlag (const string& key, int value) +{ + vector<pair<string,int> >::iterator iter,iterEnd;//iterators for iterating through all flags + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::setFlag()" << endl; + + if(key=="") + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_STRING <<":"<< getErrorMessage(EEMPTY_STRING) + <<" LTKRecognitionContext::setFlag()" <<endl; + + LTKReturnError(EEMPTY_STRING); + } + + iterEnd = m_recognitionFlags.end(); + + //looping through the map to check whether the flag exists + for(iter = m_recognitionFlags.begin(); iter != iterEnd; ++iter) + { + if((*iter).first == key) + { + (*iter).second = value; + break; + } + } + + //if the flag is not there in the map add a new flag + if((iter == iterEnd)||(m_recognitionFlags.empty()) ) + { + m_recognitionFlags.push_back(pair<string,int>(key,value)); + } + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::setFlag()" << endl; + + return SUCCESS; + +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : setLanguageModel +* DESCRIPTION : sets the language model +* ARGUMENTS : property - name of ppty to be set (DICTIONARY, GRAMMAR) +* : value - value to be set +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKRecognitionContext::setLanguageModel (const string& property, const string& value) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::setLanguageModel()" << endl; + + if(property=="" || value=="") + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< + "Either property or value is empty"<<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_STRING <<":"<< getErrorMessage(EEMPTY_STRING) + <<" LTKRecognitionContext::setLanguageModel()" <<endl; + + LTKReturnError(EEMPTY_STRING); + } + + m_languageModels [property] = value; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::setLanguageModel()" << endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : setNumResults +* DESCRIPTION : sets parameter number of results to be buffered from recognizer +* ARGUMENTS : numResults - the value to be set +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +int LTKRecognitionContext::setNumResults (int numResults) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::setNumResults()" << endl; + + if(numResults <= 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENON_POSITIVE_NUM <<":" + << getErrorMessage(ENON_POSITIVE_NUM) + <<" LTKRecognitionContext::setNumResults()" <<endl; + + LTKReturnError(ENON_POSITIVE_NUM); + } + + m_numResults = numResults; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::setNumResults()" << endl; + + return SUCCESS; +} + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : setScreenContext +* DESCRIPTION : sc - reference to the screencontext object to be set +* ARGUMENTS : numResults - the value to be set +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void LTKRecognitionContext::setScreenContext (const LTKScreenContext& sc) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::setScreenContext()" << endl; + + m_screenContext = sc; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::setScreenContext()" << endl; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : addRecognitionResult +* DESCRIPTION : used by the recognizer to set the results back in the recognition context +* ARGUMENTS : result - the value to be added +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void LTKRecognitionContext::addRecognitionResult (const LTKWordRecoResult& result) +{ + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::addRecognitionResult()" << endl; + + //adding the result to the internal data structure + m_results.push_back(result); + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::addRecognitionResult()" << endl; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : recognize +* DESCRIPTION : the recognize call from the application. +* : calls the recognize emthod of the recognizer +* ARGUMENTS : numResults - the value to be set +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKRecognitionContext::recognize () +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::recognize()" << endl; + + int errorCode; + + //calling recognize method of the recognizer + if(m_wordRecPtr!=NULL) + { + if( (errorCode = m_wordRecPtr->recognize(*this)) != SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKRecognitionContext::recognize()"<<endl; + + LTKReturnError(errorCode); + } + + } + else + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Recognizer is not initialized" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENULL_POINTER <<":"<< getErrorMessage(ENULL_POINTER) + <<" LTKRecognitionContext::recognize()" <<endl; + + + LTKReturnError(ENULL_POINTER); + } + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::recognize()" << endl; + + return SUCCESS; +} + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 28-FEB-2005 +* NAME : reset +* DESCRIPTION : Reset various parameters. +* ARGUMENTS : resetParam - specifies data to be rest +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +/** +* This function is used to reset the different components of recognition context +* @param resetParam : parameter that identifies the component to be reset +* @return SUCCESS/FAILURE +*/ +int LTKRecognitionContext::reset (int resetParam) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKRecognitionContext::reset()" << endl; + + if(resetParam & LTK_RST_INK) + { + m_fieldInk.clear(); + } + + if(resetParam & LTK_RST_RECOGNIZER) + { + int errorCode=0; + + if((errorCode=m_wordRecPtr->reset(resetParam))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKRecognitionContext::reset()"<<endl; + + LTKReturnError(errorCode); + } + } + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKRecognitionContext::reset()" << endl; + + return SUCCESS; +} + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 22-FEB-2005 +* NAME : LTKRecognitionContext +* DESCRIPTION : Destructor +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +LTKRecognitionContext::~LTKRecognitionContext() +{ + +} diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/LTKWordRecoConfig.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/LTKWordRecoConfig.cpp new file mode 100644 index 00000000..57fc6317 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/LTKWordRecoConfig.cpp @@ -0,0 +1,477 @@ +/***************************************************************************************** +* Copyright (c) 2006 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in +* the Software without restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +* Software, and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*****************************************************************************************/ + +/************************************************************************ + * SVN MACROS + * + * $LastChangedDate$ + * $Revision$ + * $Author$ + * + ************************************************************************/ + +/************************************************************************ + * FILE DESCR: Definition of LTKWordRecoConfig holds the config data for + * the recognizer at the time of loading. + * + * CONTENTS: + * getClassifierName + * getDictionaryPath + * getLipiRoot + * getNumClasses + * getProfile + * getScript + * getShapeSet + * readConfigFile + * setLipiRoot + * + * AUTHOR: Mudit Agrawal. + * + * DATE: Mar 2, 2005 + * CHANGE HISTORY: + * Author Date Description of change + * Deepu 24-MAR-2005 Added getGrammarPath + ************************************************************************/ + + +#include "LTKWordRecoConfig.h" + +#include "LTKMacros.h" + +#include "LTKErrors.h" + +#include "LTKErrorsList.h" + +#include "LTKException.h" + +#include "LTKLoggerUtil.h" + +#include "LTKConfigFileReader.h" + + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 01-MAR-2005 +* NAME : LTKWordRecoConfig +* DESCRIPTION : DEFAULT CONSTRUCTOR +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + + +LTKWordRecoConfig::LTKWordRecoConfig() +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKWordRecoConfig::LTKWordRecoConfig()" << endl; + m_lipiRoot = ""; + m_problemName = ""; + m_profile = ""; + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKWordRecoConfig::LTKWordRecoConfig()" << endl; + +} + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : LTKWordRecoConfig +* DESCRIPTION : Initialization Constructor +* ARGUMENTS : lipiRoot +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + + +LTKWordRecoConfig::LTKWordRecoConfig(const string& lipiRoot) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKWordRecoConfig::LTKWordRecoConfig(const string&)" << endl; + + if(lipiRoot=="") + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_STRING <<":"<< getErrorMessage(EEMPTY_STRING) + <<" LTKWordRecoConfig::LTKWordRecoConfig(const string&)" <<endl; + + throw LTKException(EEMPTY_STRING); + } + + m_lipiRoot = lipiRoot; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "m_lipiRoot = " << m_lipiRoot <<endl; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKWordRecoConfig::LTKWordRecoConfig(const string&)" << endl; +} + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : getClassifierName +* DESCRIPTION : This function returns the classifier name +* ARGUMENTS : none +* RETURNS : returns the classifier name +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + + +string LTKWordRecoConfig::getClassifierName() const +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering: LTKWordRecoConfig::getClassifierName()" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting: LTKWordRecoConfig::getClassifierName()" <<endl; + + return m_classifierName; +} + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : getDictionaryPath +* DESCRIPTION : This function returns the Dictionary Path +* ARGUMENTS : none +* RETURNS : returns the Dictionary Path +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + + +string LTKWordRecoConfig::getDictionaryPath() const +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entered: LTKWordRecoConfig::getDictionaryPath()" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting: LTKWordRecoConfig::getDictionaryPath()" <<endl; + + return m_dictionaryPath; +} + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : getDictionaryPath +* DESCRIPTION : This function returns the Dictionary Path +* ARGUMENTS : none +* RETURNS : returns the Dictionary Path +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + + +string LTKWordRecoConfig::getGrammarPath() const +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entered: LTKWordRecoConfig::getGrammarPath()" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting: LTKWordRecoConfig::getGrammarPath()" <<endl; + + return m_grammarPath; +} + + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : getLipiRoot +* DESCRIPTION : This function returns the lipi root +* ARGUMENTS : none +* RETURNS : returns the lipi root +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +string LTKWordRecoConfig::getLipiRoot() const +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering: LTKWordRecoConfig::getLipiRoot()" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting: LTKWordRecoConfig::getLipiRoot()" <<endl; + + return m_lipiRoot; +} + + + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : getProfile +* DESCRIPTION : This function returns the profile +* ARGUMENTS : none +* RETURNS : returns the profile +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +string LTKWordRecoConfig::getProfile() const +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering: LTKWordRecoConfig::getProfile()" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting: LTKWordRecoConfig::getProfile()" <<endl; + + return m_profile; +} + + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : getScript +* DESCRIPTION : This function returns the script +* ARGUMENTS : none +* RETURNS : returns the script +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +string LTKWordRecoConfig::getScript() const +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering: LTKWordRecoConfig::getScript()" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting: LTKWordRecoConfig::getScript()" <<endl; + + return m_script; +} + + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 23-MAR-2005 +* NAME : getProblemName +* DESCRIPTION : returns the problem name +* ARGUMENTS : none +* RETURNS : returns the problem name +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + + +string LTKWordRecoConfig::getProblemName() const +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering: LTKWordRecoConfig::getProblemName()" <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting: LTKWordRecoConfig::getProblemName()" <<endl; + + return m_problemName; +} + + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : setLipiRoot +* DESCRIPTION : sets the lipiRoot +* ARGUMENTS : none +* RETURNS : SUCCEESS on successful set operation +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +int LTKWordRecoConfig::setLipiRoot(const string& lipiRoot) +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering: LTKWordRecoConfig::setLipiRoot()" <<endl; + + if(lipiRoot=="") + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_STRING <<":"<< getErrorMessage(EEMPTY_STRING) + <<" LTKWordRecoConfig::LTKWordRecoConfig(const string&)" <<endl; + + LTKReturnError(EEMPTY_STRING); + } + + this->m_lipiRoot = lipiRoot; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "m_lipiRoot = " << m_lipiRoot <<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting: LTKWordRecoConfig::setLipiRoot()" <<endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : readConfigFile +* DESCRIPTION : reads the main config file and inturn other config files also (defined in main.cfg) +* ARGUMENTS : none +* RETURNS : SUCCESS on successful reads +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +int LTKWordRecoConfig::readConfigFile(const string& configFileName) +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering: LTKWordRecoConfig::readConfigFile()" <<endl; + + LTKConfigFileReader* cfgFileMap; + + try + { + cfgFileMap= new LTKConfigFileReader(configFileName); + + } + catch(LTKException e) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKWordRecoConfig::readConfigFile()"<<endl; + + LTKReturnError(e.getErrorCode()); + + } + + int errorCode = 0; + + if((errorCode=cfgFileMap->getConfigValue("script", m_script))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKWordRecoConfig::readConfigFile()"<<endl; + + LTKReturnError(errorCode); + + } + + if((errorCode=cfgFileMap->getConfigValue("problem", m_problemName))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKWordRecoConfig::readConfigFile()"<<endl; + + LTKReturnError(errorCode); + + } + + if(m_problemName=="") + { + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"problem string is empty"<<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_STRING <<":"<< getErrorMessage(EEMPTY_STRING) + <<" LTKWordRecoConfig::readConfigFile()" <<endl; + + LTKReturnError(EEMPTY_STRING); + } + + if((errorCode=cfgFileMap->getConfigValue("profile", m_profile))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKWordRecoConfig::readConfigFile()"<<endl; + + LTKReturnError(errorCode); + + } + + + if(m_profile=="") + { + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"profile string is empty"<<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_STRING <<":"<< getErrorMessage(EEMPTY_STRING) + <<" LTKWordRecoConfig::readConfigFile()" <<endl; + + LTKReturnError(EEMPTY_STRING); + } + + if((errorCode=cfgFileMap->getConfigValue("dictmap", m_dictionaryPath))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKWordRecoConfig::readConfigFile()"<<endl; + + LTKReturnError(errorCode); + + } + + if((errorCode=cfgFileMap->getConfigValue("grammarmap", m_grammarPath))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKWordRecoConfig::readConfigFile()"<<endl; + + LTKReturnError(errorCode); + + } + + if(m_lipiRoot=="") + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Lipiroot is empty"<<endl; + + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_STRING <<":"<< getErrorMessage(EEMPTY_STRING) + <<" LTKWordRecoConfig::LTKWordRecoConfig(const string&)" <<endl; + + LTKReturnError(EEMPTY_STRING); + } + + cfgFileMap = new LTKConfigFileReader(m_lipiRoot + SEPARATOR + m_problemName + + SEPARATOR + WORDFILE); + + + cfgFileMap = new LTKConfigFileReader(m_lipiRoot + SEPARATOR + m_problemName + + SEPARATOR + m_profile + SEPARATOR + + WORDPROFILEFILE); + + if((errorCode=cfgFileMap->getConfigValue("classifier", + m_classifierName))!=SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error: LTKWordRecoConfig::readConfigFile()"<<endl; + + LTKReturnError(errorCode); + } + + delete cfgFileMap; + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting: LTKWordRecoConfig::readConfigFile()" <<endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Mudit Agrawal +* DATE : 03-MAR-2005 +* NAME : LTKWordRecoConfig +* DESCRIPTION : DEFAULT DESTRUCTOR +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + + +LTKWordRecoConfig::~LTKWordRecoConfig() +{ +} + diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/LTKWordRecoResult.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/LTKWordRecoResult.cpp new file mode 100644 index 00000000..f7c60716 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/LTKWordRecoResult.cpp @@ -0,0 +1,291 @@ +/***************************************************************************************** +* Copyright (c) 2006 Hewlett-Packard Development Company, L.P. +* Permission is hereby granted, free of charge, to any person obtaining a copy of +* this software and associated documentation files (the "Software"), to deal in +* the Software without restriction, including without limitation the rights to use, +* copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the +* Software, and to permit persons to whom the Software is furnished to do so, +* subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A +* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF +* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE +* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*****************************************************************************************/ + +/************************************************************************ + * SVN MACROS + * + * $LastChangedDate$ + * $Revision$ + * $Author$ + * + ************************************************************************/ +/************************************************************************ + * FILE DESCR: Implementation of the word recognition result + * CONTENTS: setWordRecoResult + * getResultWord + * getResultConfidence + * + * AUTHOR: Deepu V. + * + * DATE: March 11, 2005 + * CHANGE HISTORY: + * Author Date Description of change + * Deepu V. 23-Aug-05 Added update word recognition result method + ************************************************************************/ + +#include "LTKMacros.h" + +#include "LTKErrors.h" + +#include "LTKErrorsList.h" + +#include "LTKException.h" + +#include "LTKWordRecoResult.h" + +#include "LTKLoggerUtil.h" + + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : LTKWordRecoResult +* DESCRIPTION : Default Constructor +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +LTKWordRecoResult::LTKWordRecoResult() +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKWordRecoResult::LTKWordRecoResult()" << endl; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKWordRecoResult::LTKWordRecoResult()" << endl; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : LTKWordRecoResult +* DESCRIPTION : Constructor that takes two arguements +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +LTKWordRecoResult::LTKWordRecoResult(const vector< unsigned short >& word, float confidence = 0) +:m_word(word) +{ + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKWordRecoResult::LTKWordRecoResult(const vector< unsigned short >&, float)" << endl; + + if(confidence < 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENEGATIVE_NUM <<":"<< getErrorMessage(ENEGATIVE_NUM) + <<" LTKWordRecoResult::LTKWordRecoResult" + <<"(vector< unsigned short >&, float)" <<endl; + + throw LTKException(ENEGATIVE_NUM); + } + + m_confidence = confidence; + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKWordRecoResult::LTKWordRecoResult(const vector< unsigned short >&, float)" << endl; +} + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : setWordRecoResult +* DESCRIPTION : assign values to the word recognition result +* ARGUMENTS : word - unicode result string +* confidence - confidence of the current word (default 0) +* RETURNS : SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKWordRecoResult::setWordRecoResult(const vector< unsigned short >& word, float confidence = 0) +{ + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKWordRecoResult::setWordRecoResult()" << endl; + + if(confidence < 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENEGATIVE_NUM <<":"<< getErrorMessage(ENEGATIVE_NUM) + <<" LTKWordRecoResult::setWordRecoResult()"<<endl; + + LTKReturnError(ENEGATIVE_NUM); + + } + + if(word.size() == 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< EEMPTY_VECTOR <<":"<< getErrorMessage(EEMPTY_VECTOR) + <<" LTKWordRecoResult::setWordRecoResult()"<<endl; + + LTKReturnError(EEMPTY_VECTOR); + } + + //assigning the values + m_word = word; + + m_confidence = confidence; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKWordRecoResult::setWordRecoResult()" << endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : getResultWord +* DESCRIPTION : returns the result word +* ARGUMENTS : +* RETURNS : Returns unicode result string +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +const vector<unsigned short>& LTKWordRecoResult::getResultWord() const +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKWordRecoResult::getResultWord()" << endl; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKWordRecoResult::getResultWord()" << endl; + + return m_word; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : getResultConfidence +* DESCRIPTION : returns the confidence of result +* ARGUMENTS : +* RETURNS : Returns float confidence value +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +float LTKWordRecoResult::getResultConfidence() const +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKWordRecoResult::getResultConfidence()" << endl; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKWordRecoResult::getResultConfidence()" << endl; + + return m_confidence; +} + + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : setResultConfidence +* DESCRIPTION : sets the confidence of result +* ARGUMENTS : +* RETURNS : Returns SUCCESS if completed successfully +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int LTKWordRecoResult::setResultConfidence(float confidence) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKWordRecoResult::setResultConfidence()" << endl; + + if(confidence < 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENEGATIVE_NUM <<":"<< getErrorMessage(ENEGATIVE_NUM) + <<" LTKWordRecoResult::setResultConfidence()"<<endl; + + LTKReturnError(ENEGATIVE_NUM); + + } + + m_confidence = confidence; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKWordRecoResult::setResultConfidence()" << endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 19-MAR-2005 +* NAME : updateWordRecoResult +* DESCRIPTION : This method adds to the existing word recognition result +* : with a new symbol +* ARGUMENTS : newSymbol - This will be appended to the existing word +* : confidence - confidence of the new symbol, will be added +* : to existing confidence +* RETURNS : Returns SUCCESS/FAILURE +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +int LTKWordRecoResult::updateWordRecoResult( unsigned short newSymbol, float confidence) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Entering: LTKWordRecoResult::updateWordRecoResult()" << endl; + + if(confidence < 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) + <<"Error : "<< ENEGATIVE_NUM <<":"<< getErrorMessage(ENEGATIVE_NUM) + <<" LTKWordRecoResult::updateWordRecoResult()"<<endl; + + LTKReturnError(ENEGATIVE_NUM); + + } + + m_word.push_back(newSymbol); + m_confidence += confidence; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << + " Exiting: LTKWordRecoResult::updateWordRecoResult()" << endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Deepu V. +* DATE : 11-MAR-2005 +* NAME : ~LTKWordRecoResult +* DESCRIPTION : Destructor +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ + +LTKWordRecoResult::~LTKWordRecoResult() +{ +} + diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/common.pro b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/common.pro new file mode 100644 index 00000000..bac16ef9 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/common/common.pro @@ -0,0 +1,10 @@ +TARGET = wordreccommon +include(../../../lipilib.pri) + +INCLUDEPATH += \ + ../../../util/lib \ + +SOURCES += \ + LTKRecognitionContext.cpp \ + LTKWordRecoConfig.cpp \ + LTKWordRecoResult.cpp diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/wordrec.pro b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/wordrec.pro new file mode 100644 index 00000000..cf49e45d --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/wordrec/wordrec.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs + +SUBDIRS += \ + common \ + boxfld + +boxfld.depends = common |