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 : Thanigai Murugan K * DATE : 30-AUG-2005 * NAME : evaluateWordRecognizer * DESCRIPTION : Load the model data and call recognize function and display the * results. * ARGUMENTS : pReco - handle to LTKWordRecognizer object * RETURNS : -1 on error 0 on success * NOTES : * CHANGE HISTROY * Author Date Description of change *************************************************************************************/ int evaluateWordRecognizer(LTKWordRecognizer *pReco, const string& infilelist) { int iErrorCode = 0; string tempStr(REC_UNIT_INFO), tempStr1(REC_MODE); string path; string strShapeId; vector<LTKTraceGroup> fieldInk; int charIndex; wstring eolstr(L"\r\n"); int i; string strWordId; LTKRecognitionContext *recoContext = new LTKRecognitionContext(); LTKCaptureDevice deviceContext; LTKScreenContext screenContext; recoContext->setWordRecoEngine(pReco); recoContext->setFlag(tempStr,REC_UNIT_CHAR); recoContext->setFlag(tempStr1,REC_MODE_STREAMING); recoContext->setNumResults(numChoices); ifstream in(infilelist.c_str()); if(in == NULL) { LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< "Test list file open error " << infilelist <<endl; cout << "Test list file open error : " << infilelist.c_str() << endl; //delete recognition context object if(recoContext) { //ptrObj->deleteRecognitionContext(recoContext); delete recoContext; recoContext = NULL; } return FAILURE; } ofstream resultfile(strOutputFileName,ios::out|ios::binary); //a Header of 0xFEFF is required to identify this is a //16 bit unicode file const unsigned short fHeader = 0xfeff; resultfile.write((char*)&fHeader,sizeof(unsigned short)); while(in) { //Get the file name if(!getline(in,path,' ')) { break; } //Get the word ID getline(in,strWordId); //iWordID = atoi(strShapeId.c_str()); if(path.length() > 0 && path[0] == COMMENTCHAR ) { continue; } if(path.length() == 0) { LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< "Empty File name" <<endl; continue; } try { fieldInk.clear(); getAbsolutePath(path,strLipiRootPath); cout << path << endl; //read the word file if(readWordFile(path, fieldInk, deviceContext, screenContext) != SUCCESS) { LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Error reading ink file:" << path << endl; cout<<"Error reading ink file:" << path << endl; cout<<"Aborted"<<endl; //delete recognition context object if(recoContext) { //ptrObj->deleteRecognitionContext(recoContext); delete recoContext; recoContext = NULL; } return FAILURE; } recoContext->setDeviceContext(deviceContext); recoContext->setScreenContext(screenContext); if(fieldInk.size()==0) { LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Empty trace group read from:" << path << endl; continue; } for(charIndex = 0; charIndex < fieldInk.size(); ++charIndex) { recoContext->beginRecoUnit(); recoContext->addTraceGroups(LTKTraceGroupVector(1,fieldInk.at(charIndex))); recoContext->endRecoUnit(); recoContext->beginRecoUnit(); recoContext->addTraceGroups(LTKTraceGroupVector(1,LTKTraceGroup())); recoContext->endRecoUnit(); } } catch(LTKException e) { LOG(LTKLogger::LTK_LOGLEVEL_ERR) << e.getExceptionMessage() <<endl; //delete recognition context object if(recoContext) { //ptrObj->deleteRecognitionContext(recoContext); delete recoContext; recoContext = NULL; } return FAILURE; } //Calling recognize and retrieving the top result { LTKWordRecoResult result; vector<LTKWordRecoResult> r2; recoContext->recognize(); recoContext->getTopResult(result); recoContext->getNextBestResults(numChoices-1, r2); vector<unsigned short> resultVec = result.getResultWord(); if(!resultVec.empty()) { resultfile.write((char *)&(resultVec.at(0)), resultVec.size()*sizeof(unsigned short)); resultfile.write((char*)eolstr.c_str(),eolstr.length()*sizeof(unsigned short)); for(i =0; i<r2.size(); ++i) { resultVec = r2.at(i).getResultWord(); resultfile.write((char *)&(resultVec.at(0)), resultVec.size()*sizeof(unsigned short)); resultfile.write((char*)eolstr.c_str(),eolstr.length()*sizeof(unsigned short)); } } recoContext->clearRecognitionResult(); } resultfile.write((char*)eolstr.c_str(),eolstr.length()*sizeof(unsigned short)); } resultfile.close(); //delete recognition context object if(recoContext) { //ptrObj->deleteRecognitionContext(recoContext); delete recoContext; recoContext = NULL; } return SUCCESS; }