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

📄 ltkrecognitioncontext.cpp

📁 An open source handwriting recongnition package!!!
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************************
* 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 "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)
	{

⌨️ 快捷键说明

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