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

📄 ltkshaperecoutil.cpp

📁 An open source handwriting recongnition package!!!
💻 CPP
📖 第 1 页 / 共 2 页
字号:

            if(!isPositiveInteger)
            {
                LOG( LTKLogger::LTK_LOGLEVEL_ERR)<<"Error" <<
                    "NumShapes should be set to  dynamic or the number of training classes"  <<
                    " LTKShapeRecoUtil::isProjectDynamic()"  <<endl;

                LTKReturnError(EINVALID_NUM_OF_SHAPES);
            }
            else
            {
                tempNumShapes = atoi(valueFromCFG.c_str());
                if(tempNumShapes==0)
                {
                    LOG( LTKLogger::LTK_LOGLEVEL_ERR)<<"Error" <<
                        "NumShapes should be set to  dynamic or the number of training classes"  <<
                        " LTKShapeRecoUtil::isProjectDynamic()"  <<endl;

                    LTKReturnError(EINVALID_NUM_OF_SHAPES);
                }
                else
                {
                    //Numshapes was not dynamic
                    outIsDynamic = false;
                }

            }

        }

        numShapes = tempNumShapes;
        strNumShapes = valueFromCFG;
        LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<  
            "NumShapes in the project is " <<  valueFromCFG <<endl;


    }
    catch(LTKException e)
    {	
        delete projectCfgAttrs;	
        throw e;
    }	

    delete projectCfgAttrs;
    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<  
        "Exiting LTKShapeRecoUtil::isProjectDynamic()"  <<endl;

    return SUCCESS;
}



/**********************************************************************************
 * AUTHOR		: Saravanan. R
 * DATE			: 30-01-2007
 * NAME          : readInkFromFile
 * DESCRIPTION   : This method reads the Ink file and check from empty traces
 * ARGUMENTS     : string : Holds the Path of the unipen ink file
string : Holds the Path of the lipi root				  
 * RETURNS       : 
 * NOTES         :
 * CHANGE HISTROY
 * Author            Date                Description
 *************************************************************************************/
int LTKShapeRecoUtil::readInkFromFile(const string& path, const string& lipiRootPath,
        LTKTraceGroup& inTraceGroup, 
        LTKCaptureDevice& captureDevice,
        LTKScreenContext& screenContext)
{
    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<  
        "Entering LTKShapeRecoUtil::readInkFromFile()"  <<endl;

    //inTraceGroup.emptyAllTraces();

    string tempPath = path;

    //Check and convert Relative path to Absolute path
    string outPath = "";
    getAbsolutePath(tempPath, lipiRootPath, outPath);

    //Print the path name
    cout << outPath << endl;	

    //Read Ink file to inTraceGroup
    //    errorVal = LTKInkFileReader::readUnipenInkFile(tempPath,inTraceGroup,captureDevice,screenContext);
    int errorCode = LTKInkFileReader::readUnipenInkFile(outPath,inTraceGroup,captureDevice,screenContext);

    if (errorCode != SUCCESS)
    {
        LOG( LTKLogger::LTK_LOGLEVEL_ERR)<<"Error: " <<
            getErrorMessage(errorCode) << 
            " LTKShapeRecoUtil::readInkFromFile()"  <<endl;

        LTKReturnError(errorCode);
    }

    //Check for empty traces in inTraceGroup
    
    if (inTraceGroup.containsAnyEmptyTrace())
    {
        LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<"Error: " <<
            "TraceGroup has empty traces" << 
            " LTKShapeRecoUtil::readInkFromFile()"  <<endl;

        LTKReturnError(EEMPTY_TRACE);
    }


    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<  
        "Exiting LTKShapeRecoUtil::readInkFromFile()"  <<endl;

    return SUCCESS;
}

/**********************************************************************************
 * AUTHOR		: Saravanan. R
 * DATE			: 30-01-2007
 * NAME          : checkEmptyTraces
 * DESCRIPTION   : This method checks for empty traces
 * ARGUMENTS     : inTraceGroup : LTKTraceGroup :
 * RETURNS       : 1 if it contains empty trace group, 0 otherwise
 * NOTES         :
 * CHANGE HISTROY
 * Author            Date                Description
 *************************************************************************************/
/*
int LTKShapeRecoUtil::checkEmptyTraces(const LTKTraceGroup& inTraceGroup)
{
    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<  
        "Entering LTKShapeRecoUtil::checkEmptyTraces()"  <<endl;

    int returnVal = SUCCESS;

    vector<LTKTrace> tracesVec = inTraceGroup.getAllTraces();  //traces in trace group

    int numTraces = tracesVec.size();

    int numTracePoints = 0;

    LTKTrace trace;							//	a trace of the trace group

    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<  "numTraces = " << numTraces  <<endl;


    for(int traceIndex=0; traceIndex < numTraces; ++traceIndex) 
    {
        trace = tracesVec.at(traceIndex);

        numTracePoints=trace.getNumberOfPoints();

        if(numTracePoints==0)
        {
            LOG( LTKLogger::LTK_LOGLEVEL_ERR)<<"Error: "<<
                getError(EEMPTY_TRACE) <<
                "Exiting LTKShapeRecoUtil::checkEmptyTraces()"  <<endl;
            LTKReturnError(EEMPTY_TRACE);
        }

    }

    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<  
        "Exiting LTKShapeRecoUtil::checkEmptyTraces()"  <<endl;
    return SUCCESS;
}
*/
int LTKShapeRecoUtil::convertHeaderToStringStringMap(const string& header, stringStringMap& headerSequence)
{
    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<  
        "Entering LTKShapeRecoUtil::convertHeaderToStringStringMap()"  <<endl;

    vector<string> tokens;
    vector<string> strList;

    int returnStatus = SUCCESS;

    LTKStringUtil::tokenizeString(header, "<>", tokens);

    for(int i=0 ; i < tokens.size(); ++i)
    {
        returnStatus = LTKStringUtil::tokenizeString(tokens[i],  "=",  strList);
        if(returnStatus != SUCCESS)
        {
            LOG( LTKLogger::LTK_LOGLEVEL_ERR)<<"Error: " <<
                getErrorMessage(returnStatus) << 
                " LTKShapeRecoUtil::convertHeaderToStringStringMap()"  <<endl;
            LTKReturnError(returnStatus);
        }
        if(strList.size() == 2)
        {
            headerSequence[strList[0]] = strList[1];
        }
    }
    LOG( LTKLogger::LTK_LOGLEVEL_DEBUG)<<  
        "Exiting LTKShapeRecoUtil::convertHeaderToStringStringMap()"  <<endl;

    return SUCCESS;
}


/**********************************************************************************
* AUTHOR		: Saravanan. R
* DATE			: 14-03-2007
* NAME          : shapeFeatureVectorToFloatVector
* DESCRIPTION   : This method converts the ShapeFeatureVector to float vector
* ARGUMENTS     : 
* RETURNS       : 
* NOTES         :
* CHANGE HISTROY
* Author            Date                Description
*************************************************************************************/
int LTKShapeRecoUtil::shapeFeatureVectorToFloatVector(const vector<LTKShapeFeaturePtr>& shapeFeature, 
                                                   floatVector& outFloatVector)
{
    int returnVal = SUCCESS;
    
	//Iterators for the LTKShapeFeature
	vector<LTKShapeFeaturePtr>::const_iterator shapeFeatureIter = shapeFeature.begin();
	vector<LTKShapeFeaturePtr>::const_iterator shapeFeatureIterEnd = shapeFeature.end();


	vector<float> shapeFeatureFloatvector;

	for(; shapeFeatureIter != shapeFeatureIterEnd; ++shapeFeatureIter)
	{
	
		//Convert the shapefeature to float vector
		returnVal = (*shapeFeatureIter)->toFloatVector(shapeFeatureFloatvector);

        if ( returnVal != SUCCESS )
        {
            break;
        }
        
		outFloatVector.insert(outFloatVector.end(),
			                  shapeFeatureFloatvector.begin(),
							  shapeFeatureFloatvector.end());
		
		shapeFeatureFloatvector.clear();
	
	}
	
	return returnVal;
}

⌨️ 快捷键说明

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