diff options
Diffstat (limited to 'src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7')
8 files changed, 1863 insertions, 0 deletions
diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.cpp new file mode 100644 index 00000000..16eaaca4 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.cpp @@ -0,0 +1,673 @@ +/***************************************************************************************** +* 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-02-20 10:03:51 +0530 (Wed, 20 Feb 2008) $ + * $Revision: 423 $ + * $Author: sharmnid $ + * + ************************************************************************/ +/************************************************************************ + * FILE DESCR : Implementation of L7ShapeFeature class + * AUTHOR : Naveen Sundar G. + * DATE : August 30, 2005 + * CHANGE HISTORY : + * Author Date Description of change + ************************************************************************/ + +#include "L7ShapeFeature.h" +#include "LTKStringUtil.h" +#include <sstream> + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : L7ShapeFeature +* DESCRIPTION : Constructor for the L7ShapeFeature class. +* ARGUMENTS : none +* RETURNS : +* NOTES : Initializes the string delimiter used in writing feature values to a file. +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +L7ShapeFeature::L7ShapeFeature(): +m_data_delimiter(",") +{ +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 12-Dec-2007 +* NAME : L7ShapeFeature +* DESCRIPTION : Parameterized Constructor for the L7ShapeFeature class. +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*****************************************************************************/ +L7ShapeFeature::L7ShapeFeature(float inX, float inY, float inXFirstDerv, + float inYFirstDerv, float inXSecondDerv, + float inYSecondDerv, float inCurvature, + bool inPenUp): +m_x(inX), +m_y(inY), +m_xFirstDerv(inXFirstDerv), +m_yFirstDerv(inYFirstDerv), +m_xSecondDerv(inXSecondDerv), +m_ySecondDerv(inYSecondDerv), +m_curvature(inCurvature), +m_penUp(inPenUp), +m_data_delimiter(",") +{ +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : ~L7ShapeFeature +* DESCRIPTION : Destructor for the L7ShapeFeature class +* ARGUMENTS : none +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +L7ShapeFeature::~L7ShapeFeature() +{ + +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : getX +* DESCRIPTION : Get method for the x co-ordinate value +* ARGUMENTS : none +* RETURNS : X co-ordinate of the shape feature +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +float L7ShapeFeature::getX() const +{ + return m_x; +} + + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : getY +* DESCRIPTION : Get method for the y co-ordinate value +* ARGUMENTS : none +* RETURNS : Y co-ordinate of the shape feature +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +float L7ShapeFeature::getY() const +{ + return m_y; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : getXFirstDerv +* DESCRIPTION : Get method for the first derivative value along the X axis +* ARGUMENTS : none +* RETURNS : First derivative value along the X axis. +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +float L7ShapeFeature::getXFirstDerv() const +{ + return m_xFirstDerv; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : getYFirstDerv +* DESCRIPTION : Get method for the first derivative value along the Y axis +* ARGUMENTS : none +* RETURNS : First derivative value along the Y axis. +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +float L7ShapeFeature::getYFirstDerv() const +{ + return m_yFirstDerv; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : getXSecondDerv +* DESCRIPTION : Get method for the second derivative value along the X axis. +* ARGUMENTS : none +* RETURNS : Second derivative value along the X axis. +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +float L7ShapeFeature::getXSecondDerv() const +{ + return m_xSecondDerv; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : getYSecondDerv +* DESCRIPTION : Get method for the second derivative value along the Y axis. +* ARGUMENTS : none +* RETURNS : Second derivative value along the Y axis. +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +float L7ShapeFeature::getYSecondDerv() const +{ + return m_ySecondDerv; +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : getCurvature +* DESCRIPTION : Get method for the curvature +* ARGUMENTS : none +* RETURNS : The curvature value +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +float L7ShapeFeature::getCurvature() const +{ + return m_curvature; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : isPenUp +* DESCRIPTION : Get method for the penUp +* ARGUMENTS : none +* RETURNS : The PenUp value +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +* Balaji MNA 01-July-2009 Rename getPenUp to isPenUp +*************************************************************************************/ +bool L7ShapeFeature::isPenUp() const +{ + return m_penUp; + +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : setX +* DESCRIPTION : Set method for the X co-ordinate value +* ARGUMENTS : X co-ordinate value to be set +* RETURNS : none +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::setX(float x) +{ + m_x = x; +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : setY +* DESCRIPTION : Set method for the Y co-ordinate value +* ARGUMENTS : Y co-ordinate value to be set +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::setY(float y) +{ + m_y = y; +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : setXFirstDerv +* DESCRIPTION : Set method for the first derivative along the X axis +* ARGUMENTS : The first derivative value along the X axis +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::setXFirstDerv(float xFirstDerv) +{ + m_xFirstDerv = xFirstDerv; +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : setYFirstDerv +* DESCRIPTION : Set method for the first derivative along the Y axis +* ARGUMENTS : The first derivative value along the Y axis to be set +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::setYFirstDerv(float yFirstDerv) +{ + m_yFirstDerv = yFirstDerv; +}/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : setXSecondDerv +* DESCRIPTION : Set method for the second derivative along the X axis +* ARGUMENTS : The second derivative value along the X axis to be set +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::setXSecondDerv(float xSecondDerv) +{ + m_xSecondDerv = xSecondDerv; +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : setYSecondDerv +* DESCRIPTION : Set method for the second derivative value along the y axis +* ARGUMENTS : The second derivative value along the Y axis to be set +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::setYSecondDerv(float ySecondDerv) +{ + m_ySecondDerv = ySecondDerv; +}/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : setCurvature +* DESCRIPTION : This method sets the curvature +* ARGUMENTS : The curvature value to be set +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::setCurvature(float curvature) +{ + m_curvature=curvature; +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : setPenUp +* DESCRIPTION : This method sets the penUp +* ARGUMENTS : The penUp value to be set +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::setPenUp(bool penUp) +{ + m_penUp=penUp; + + +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : clone +* DESCRIPTION : Clone method for an L7ShapeFeature object +* ARGUMENTS : none +* RETURNS : A copy of the invoking L7ShapeFeature object +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +LTKShapeFeaturePtr L7ShapeFeature::clone() const +{ + L7ShapeFeature* l7Inst = new L7ShapeFeature(); + + l7Inst->setX(this->getX()); + l7Inst->setY(this->getY()); + l7Inst->setXFirstDerv(this->getXFirstDerv()); + l7Inst->setYFirstDerv(this->getYFirstDerv()); + l7Inst->setXSecondDerv(this->getXSecondDerv()); + l7Inst->setYSecondDerv(this->getYSecondDerv()); + l7Inst->setCurvature(this->getCurvature()); + l7Inst->setPenUp(this->isPenUp()); + + return (LTKShapeFeaturePtr)l7Inst; +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : getDistance +* DESCRIPTION : Returns the distance between two L7ShapeFeature objects +* ARGUMENTS : An L7ShapeFeature object the distance of which is to be found from the invoking L7ShapeFeature object +* RETURNS : The squared Euclidean distance +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const +{ + float xDiff = 0, yDiff = 0; + float xFirstDervDiff=0, yFirstDervDiff=0, xSecondDervDiff=0, ySecondDervDiff=0; + float curvatureDiff=0; + + L7ShapeFeature *inFeature = (L7ShapeFeature*)(shapeFeaturePtr.operator ->()); + + xDiff = m_x - inFeature->getX(); + yDiff = m_y - inFeature->getY(); + xFirstDervDiff = m_xFirstDerv - inFeature->getXFirstDerv(); + xFirstDervDiff = m_yFirstDerv - inFeature->getYFirstDerv(); + xSecondDervDiff = m_xSecondDerv - inFeature->getXSecondDerv(); + ySecondDervDiff = m_ySecondDerv - inFeature->getYSecondDerv(); + curvatureDiff = m_curvature - inFeature->getCurvature(); + + outDistance = ( (xDiff * xDiff) + (yDiff * yDiff) ); + outDistance += ( (xFirstDervDiff * xFirstDervDiff) + (yFirstDervDiff * yFirstDervDiff) ); + outDistance += ( (xSecondDervDiff * xSecondDervDiff) + (ySecondDervDiff * ySecondDervDiff) ); + outDistance += ( (curvatureDiff * curvatureDiff)); +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : initialize +* DESCRIPTION : This method initializes an L7ShapeFeature object from a string +* ARGUMENTS : The string containing the feature values +* RETURNS : SUCCESS on successful completion +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int L7ShapeFeature::initialize(const string& initString) +{ + stringVector tokens; + + LTKStringUtil::tokenizeString(initString, m_data_delimiter, tokens); + + //Token size must be eight + if(tokens.size() != 8) + return FAILURE; //Returning an error + + m_x = LTKStringUtil::convertStringToFloat(tokens[0]); + m_y = LTKStringUtil::convertStringToFloat(tokens[1]); + m_xFirstDerv = LTKStringUtil::convertStringToFloat(tokens[2]); + m_yFirstDerv = LTKStringUtil::convertStringToFloat(tokens[3]); + m_xSecondDerv = LTKStringUtil::convertStringToFloat(tokens[4]); + m_ySecondDerv = LTKStringUtil::convertStringToFloat(tokens[5]); + m_curvature= LTKStringUtil::convertStringToFloat(tokens[6]); + + if(atoi(tokens[7].c_str()) == 1) + m_penUp = true; + else + m_penUp = false; + + return SUCCESS; +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : toString +* DESCRIPTION : This method prints the components of the feature object a string. +* ARGUMENTS : pointer to char +* RETURNS : The feature object in string format +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeature::toString(string& strFeat) const +{ + ostringstream tempString; + + tempString << m_x << m_data_delimiter << m_y << m_data_delimiter << + m_xFirstDerv << m_data_delimiter << + m_yFirstDerv << m_data_delimiter << + m_xSecondDerv << m_data_delimiter << + m_ySecondDerv << m_data_delimiter << + m_curvature << m_data_delimiter << + m_penUp ; + + + strFeat = tempString.str(); + +} +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : addFeature +* DESCRIPTION : This method adds the passed L7ShapeFeature object to the invoking L7ShapeFeature object +* ARGUMENTS : The feature instance to be added +* RETURNS : The result feature object +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int L7ShapeFeature::addFeature(const LTKShapeFeaturePtr& secondFeature, + LTKShapeFeaturePtr& outResult ) const +{ + L7ShapeFeature* resultFeature = new L7ShapeFeature(); + + L7ShapeFeature *inFeature = (L7ShapeFeature*)(secondFeature.operator ->()); + + resultFeature->setX(m_x + inFeature->getX()); + resultFeature->setY(m_y + inFeature->getY()); + resultFeature->setXFirstDerv(m_xFirstDerv + inFeature->getXFirstDerv()); + resultFeature->setYFirstDerv(m_yFirstDerv + inFeature->getYFirstDerv()); + resultFeature->setXSecondDerv(m_xSecondDerv + inFeature->getXSecondDerv()); + resultFeature->setYSecondDerv(m_ySecondDerv + inFeature->getYSecondDerv()); + resultFeature->setCurvature(m_curvature + inFeature->getCurvature()); + resultFeature->setPenUp(m_penUp); + + outResult = LTKShapeFeaturePtr(resultFeature); + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : subtractFeature +* DESCRIPTION : This method subtracts the elements of the passed L7ShapeFeature object from the invoking L7ShapeFeature object. +* ARGUMENTS : +* RETURNS : The result feature object +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int L7ShapeFeature::subtractFeature(const LTKShapeFeaturePtr& secondFeature, + LTKShapeFeaturePtr& outResult ) const +{ + L7ShapeFeature* resultFeature = new L7ShapeFeature(); + + L7ShapeFeature *inFeature = (L7ShapeFeature*)(secondFeature.operator ->()); + + resultFeature->setX(m_x-inFeature->getX()); + resultFeature->setY(m_y-inFeature->getY()); + resultFeature->setXFirstDerv(m_xFirstDerv - inFeature->getXFirstDerv()); + resultFeature->setYFirstDerv(m_yFirstDerv - inFeature->getYFirstDerv()); + resultFeature->setXSecondDerv(m_xSecondDerv - inFeature->getXSecondDerv()); + resultFeature->setYSecondDerv(m_ySecondDerv - inFeature->getYSecondDerv()); + resultFeature->setCurvature(m_curvature - inFeature->getCurvature()); + resultFeature->setPenUp(m_penUp); + + outResult = LTKShapeFeaturePtr(resultFeature); + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : scaleFeature +* DESCRIPTION : This method mulitplies the elements of the invoking L7ShapeFeature object by alpha. +* ARGUMENTS : alpha which is the scaling factor +* RETURNS : The scaled feature object +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int L7ShapeFeature::scaleFeature(float alpha, LTKShapeFeaturePtr& outResult) const +{ + L7ShapeFeature* resultFeature = new L7ShapeFeature(); + + resultFeature->setX(m_x * alpha); + resultFeature->setY(m_y * alpha); + resultFeature->setXFirstDerv(m_xFirstDerv * alpha); + resultFeature->setYFirstDerv(m_yFirstDerv * alpha); + resultFeature->setXSecondDerv(m_xSecondDerv * alpha); + resultFeature->setYSecondDerv(m_ySecondDerv * alpha); + resultFeature->setCurvature(m_curvature * alpha); + resultFeature->setPenUp(m_penUp); + + outResult = LTKShapeFeaturePtr(resultFeature); + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : toFloatVector +* DESCRIPTION : This method converts the feature instance to a floatVector. +* ARGUMENTS : The float vector passed by reference +* RETURNS : 0 on success. +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int L7ShapeFeature::toFloatVector(floatVector& floatVec) +{ + floatVec.push_back(m_x); + floatVec.push_back(m_y); + floatVec.push_back(m_xFirstDerv); + floatVec.push_back(m_yFirstDerv); + floatVec.push_back(m_xSecondDerv); + floatVec.push_back(m_ySecondDerv); + floatVec.push_back(m_curvature); + + if(m_penUp == true) + floatVec.push_back(1.0); + else + floatVec.push_back(0.0); + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : toIntVector +* DESCRIPTION : This method converts the feature instance to an intVector. +* ARGUMENTS : The integer vector passed by reference +* RETURNS : 0 on success. +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int L7ShapeFeature::toIntVector(intVector& intVec) +{ + intVec.push_back(m_x); + intVec.push_back(m_y); + intVec.push_back(m_xFirstDerv); + intVec.push_back(m_yFirstDerv); + intVec.push_back(m_xSecondDerv); + intVec.push_back(m_ySecondDerv); + intVec.push_back(m_curvature); + intVec.push_back(m_penUp); + + return SUCCESS; +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 23-Apr-2008 +* NAME : initialize +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author: Date Description: + +*****************************************************************************/ +int L7ShapeFeature::initialize(const floatVector& initFloatVector) +{ + + if (initFloatVector.size() == 0) + { + return FAILURE; + } + + m_x = initFloatVector[0]; + m_y = initFloatVector[1]; + m_xFirstDerv = initFloatVector[2]; + m_yFirstDerv = initFloatVector[3]; + m_xSecondDerv = initFloatVector[4]; + m_ySecondDerv = initFloatVector[5]; + m_curvature = initFloatVector[6]; + + if(initFloatVector[7] == 1) + { + m_penUp = true; + } + else + { + m_penUp = false; + } + + return SUCCESS; +} + +/*************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 23-Apr-2008 +* NAME : getFeatureDimension +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author: Date Description: + +*****************************************************************************/ + +int L7ShapeFeature::getFeatureDimension() +{ + return 8; +} diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.h b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.h new file mode 100644 index 00000000..6c767112 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeature.h @@ -0,0 +1,267 @@ +/***************************************************************************************** +* 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-02-20 10:03:51 +0530 (Wed, 20 Feb 2008) $ + * $Revision: 423 $ + * $Author: sharmnid $ + * + ************************************************************************/ +#include "LTKShapeFeature.h" + + + +/** @ingroup L7ShapeFeatureExtractor +* @brief The feature representation class for L7 features +* This class represents X and Y coordinates, Normalized X and Y First Derivatives, Normalized X and Y Second Derivatives and the Curvature values of a point. +* @class L7ShapeFeature +* +*/ +class L7ShapeFeature : public LTKShapeFeature +{ + /** @name private data members */ + //@{ + +private: + /** @brief X value */ + float m_x; + + /** @brief Y value */ + float m_y; + + /** @brief Normalized First Derivative w.r.t X */ + float m_xFirstDerv; + + /** @brief Normalized First Derivative w.r.t Y */ + float m_yFirstDerv; + + /** @brief Normalized Second Derivative w.r.t X */ + float m_xSecondDerv; + + /** @brief Normalized Second Derivative w.r.t Y */ + float m_ySecondDerv; + + /** @brief Curvature value */ + float m_curvature; + + /** @brief Pen-up information */ + bool m_penUp; + + /** @brief Delimiter character */ + string m_data_delimiter; + //@} + +public: + + /** @name Constructors and Destructor */ + //@{ + + /** + * Default Constructor. + */ + L7ShapeFeature(); + + /** parameterized constructor + */ + L7ShapeFeature(float inX, float inY, float inXFirstDerv, float inYFirstDerv, + float inXSecondDerv, float inYSecondDerv, float inCurvature, + bool inPenUp); + + /** + * Default destructor. + */ + ~L7ShapeFeature(); + + /** + * Returns the value of the class data member L7ShapeFeature::m_x + */ + float getX() const; + + /** + * Returns the value of the class data member L7ShapeFeature::m_y + */ + float getY() const; + + /** + * Returns the value of the class data member L7ShapeFeature::m_xFirstDerv + */ + float getXFirstDerv() const; + + /** + * Returns the value of the class data member L7ShapeFeature::m_yFirstDerv + */ + float getYFirstDerv() const; + + /** + * Returns the value of the class data member L7ShapeFeature::m_xSecondDerv + */ + float getXSecondDerv() const; + + /** + * Returns the value of the class data member L7ShapeFeature::m_ySecondDerv + */ + float getYSecondDerv() const; + + /** + * Returns the value of the class data member L7ShapeFeature::m_curvature + */ + float getCurvature() const; + + /** + * Returns the value of the class data member L7ShapeFeature::m_penUp + */ + bool isPenUp() const; + + /** + * Sets the value of L7ShapeFeature::m_x + */ + void setX(float x); + + /** + * Sets the value of L7ShapeFeature::m_y + */ + void setY(float y); + + /** + * Sets the value of L7ShapeFeature::m_xFirstDerv + */ + void setXFirstDerv(float xFirstDerv); + + /** + * Sets the value of L7ShapeFeature::m_yFirstDerv + */ + + void setYFirstDerv(float yFirstDerv); + /** + * Sets the value of L7ShapeFeature::m_xSecondDerv + */ + void setXSecondDerv(float xSecondDerv); + + /** + * Sets the value of L7ShapeFeature::m_ySecondDerv + */ + void setYSecondDerv(float ySecondDerv); + + /** + * Sets the value of L7ShapeFeature::m_curvature + */ + void setCurvature(float curvature); + + /** + * Sets the value of L7ShapeFeature::m_penUp + */ + void setPenUp(bool penUp); + + + /** + * @brief Initializes an instance of L7ShapeFeature from the string passed as parameter. + * + * <b>Semantics</b> + * + * - Tokenize the input string on L7ShapeFeature::m_data_delimiter using StringTokenizer::tokenizeString + * - Initialize the data members of the class with the tokens returned. + * + * @param initString : string& : Reference to the initialization string. + * + * @return FAILURE : If the initalization string contains more than or less than seven tokens (after tokenizing on L7ShapeFeature::m_data_delimiter) + * @return SUCCESS : If initialization done without any errors. + * + */ + + //see interface + int initialize(const string& initString); + + int initialize(const floatVector& initFloatVector); + + /** + * @brief Gives the string representation of the L7ShapeFeature instance + */ + //see interface + void toString(string& strFeat) const; + + /** + * This method implements the clone pattern and returns a cloned instance of the invoking L7ShapeFeature object + */ + LTKShapeFeaturePtr clone() const; + + + /** + * @brief Computes the Euclidean Distance between two L7ShapeFeature instances. + * Computes the square root of ( (m_x-passed_x)^2 + (m_y-passed_y)^2+ (m_xFirstDerv-passed_x1)^2 +(m_yFirstDerv-passed_y1)^2+(m_xSecondDerv-passed_x2)^2+(m_ySecondDerv-passed_y2)^2+(m_curvature-passed_curvature)^2). + * @param f : LTKShapeFeature* : Base class pointer holding a pointer to L7ShapeFeature instance from which the distance to the invoking object is to be computed. + * + * @return float : Distance between two points in the LocalSeven feature representation + * + */ + void getDistance(const LTKShapeFeaturePtr& shapeFeaturePtr, float& outDistance) const; + + /** + * @brief Adds two L7ShapeFeature instances. + * Computes the sum of the member variables of the passed LTKShapeFeature object and the invoking LTKShapeFeature object. The new member variables are stored in a newly created L7ShapeFeature object. Neither the invoking nor the passed object object are changed. + * new_x=m_x+ (*secondFeature).m_x; + * @param secondFeature : LTKShapeFeature* : Base class pointer holding a pointer to the L7ShapeFeature instance which is to be added to the invoking L7ShapeFeature object. + * + * @return LTKShapeFeature* : Base class pointer to the L7ShapeFeature instance holding the result of the addition operation. + * + */ + int addFeature(const LTKShapeFeaturePtr& secondFeature, LTKShapeFeaturePtr& outResult ) const; + + /** + * @brief Subtracts two L7ShapeFeature instances. + * Subtracts the member variables of the passed LTKShapeFeature object from the invoking LTKShapeFeature object. The new member variables are stored in a newly created L7ShapeFeature object, which is returned. Neither the invoking nor the passed object object are changed. + * new_x=m_x-(*secondFeature).m_x; + * + * @param secondFeature : LTKShapeFeature* : Base class pointer holding a pointer to the L7ShapeFeature instance which is to be subtracted. + * + * @return LTKShapeFeature* : Base class pointer to the L7ShapeFeature instance holding the result of the subtraction operation. + * + */ + int subtractFeature(const LTKShapeFeaturePtr& secondFeature, LTKShapeFeaturePtr& outResult ) const; + + /** + * @brief Scales the L7ShapeFeature feature by a scalar (float value). + * Mulitplies all the member variables of the invoking L7ShapeFeature object by alpha. The new member variables are stored in a newly created L7ShapeFeature object, which is returned. The invoking LTKShapeFeature object is not changed. + * new_x=alpha*m_x + * + * @param alpha : float: The float value by which all the member variables should be multiplied. + * @return LTKShapeFeature* : Base class pointer to the L7ShapeFeature instance holding the result of the scaling operation . + * + */ + int scaleFeature(float alpha, LTKShapeFeaturePtr& outResult) const; + + /** + * Converts the LocalSeven feature instance into a float vector. The elements of the float vector are m_x,m_y,m_xFirstDerv,m_yFirstDerv,m_xSecondDerv,m_ySecondDerv and m_curvature in this order. + * @param floatVec: vector<float>&: The float vector which will contain the member values. + * @return int : returns SUCCESS or FAILURE + * + */ + int toFloatVector(vector<float>& floatVec); + + /** + * Converts the LocalSeven feature instance into a integer vector. The elements of the int vector are m_x,m_y,m_xFirstDerv,m_yFirstDerv,m_xSecondDerv,m_ySecondDerv and m_curvature in this order. + * @param intVec: vector<int>&: The int vector which will contain the member values. + * @return int : returns SUCCESS or FAILURE + * + */ + int toIntVector(vector<int>& intVec); + + int getFeatureDimension(); +}; diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeatureExtractor.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeatureExtractor.cpp new file mode 100644 index 00000000..19e6a9c1 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeatureExtractor.cpp @@ -0,0 +1,587 @@ +/***************************************************************************************** +* 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-02-20 10:03:51 +0530 (Wed, 20 Feb 2008) $ + * $Revision: 423 $ + * $Author: sharmnid $ + * + ************************************************************************/ +/************************************************************************ + * FILE DESCR: Implementation of RunShaperec tool + * + * CONTENTS: + * extractFeatures + * getShapeFeatureInstance + * clearFeatureVector + * computeDerivativeDenominator + * computeDerivative + * + * AUTHOR: Naveen Sundar G. + * + * DATE: August 30, 2005 + * CHANGE HISTORY: + * Author Date Description of change + ************************************************************************/ + + +#include "L7ShapeFeatureExtractor.h" +#include "L7ShapeFeature.h" +#include "LTKTraceGroup.h" +#include "LTKTrace.h" +#include "LTKChannel.h" +#include "LTKTraceFormat.h" +#include "LTKConfigFileReader.h" +#include "LTKMacros.h" +#include "LTKException.h" +#include "LTKErrors.h" +#include "LTKLoggerUtil.h" + +/****************************************************************************** +* AUTHOR : Dinesh M +* DATE : 1-Oct-2007 +* NAME : L7ShapeFeatureExtractor +* DESCRIPTION : parameterized constructor +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date +*******************************************************************************/ +L7ShapeFeatureExtractor::L7ShapeFeatureExtractor(const LTKControlInfo& controlInfo): +m_radius(FEATEXTR_L7_DEF_RADIUS) +{ + string cfgFilePath = ""; + + // Config file + if ( ! ((controlInfo.lipiRoot).empty()) && + ! ((controlInfo.projectName).empty()) && + ! ((controlInfo.profileName).empty()) && + ! ((controlInfo.cfgFileName).empty())) + { + // construct the cfg path using project and profile name + cfgFilePath = (controlInfo.lipiRoot) + PROJECTS_PATH_STRING + + (controlInfo.projectName) + PROFILE_PATH_STRING + + (controlInfo.profileName) + SEPARATOR + + (controlInfo.cfgFileName) + CONFIGFILEEXT; + } + else if ( ! ((controlInfo.cfgFilePath).empty() )) + { + cfgFilePath = controlInfo.cfgFilePath; + } + else + { + throw LTKException(EINVALID_PROJECT_NAME); + } + + int returnVal = readConfig(cfgFilePath); + + if (returnVal != SUCCESS) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) << + "Error: L7ShapeFeatureExtractor::L7ShapeFeatureExtractor()" <<endl; + + throw LTKException(returnVal); + } + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting " << + "L7ShapeFeatureExtractor::L7ShapeFeatureExtractor()" << endl; + +} + +/********************************************************************************** +* AUTHOR : Dinesh M +* DATE : 1-Oct-2007 +* NAME : readConfig +* DESCRIPTION : read the config values from cfg file and set member variables +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date +*************************************************************************************/ + +int L7ShapeFeatureExtractor::readConfig(const string& cfgFilePath) +{ + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering " << + "L7ShapeFeatureExtractor::readConfig()" << endl; + + LTKConfigFileReader* configurableProperties = NULL; + string tempStringVar = ""; + + try + { + configurableProperties = new LTKConfigFileReader(cfgFilePath); + + int errorCode = configurableProperties->getConfigValue(L7RADIUS, tempStringVar); + + if( errorCode == SUCCESS) + { + if (setRadius(atoi((tempStringVar).c_str())) != SUCCESS) + { + LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << + ECONFIG_FILE_RANGE << " : " << + getErrorMessage(ECONFIG_FILE_RANGE) << + " L7ShapeFeatureExtractor::readConfig" <<endl; + + throw LTKException(ECONFIG_FILE_RANGE); + } + } + } + + catch(LTKException e) + { + delete configurableProperties; + + int eCode = e.getErrorCode(); + + LOG( LTKLogger::LTK_LOGLEVEL_ERR) << "Error: " << eCode << + " : " << getErrorMessage(eCode) << + " L7ShapeFeatureExtractor::readConfig" <<endl; + + LTKReturnError(eCode); + } + delete configurableProperties; + + LOG( LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting " << + "L7ShapeFeatureExtractor::readConfig()" << endl; + + return SUCCESS; + +} + +/********************************************************************************** +* AUTHOR : Dinesh M +* DATE : 1-Oct-2007 +* NAME : setRadius +* DESCRIPTION : set the radius(the size of window) to compute L7 features +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date +*************************************************************************************/ +int L7ShapeFeatureExtractor::setRadius(int radius) +{ + int returnVal = FAILURE; + + if ( radius > 0 ) + { + m_radius = radius; + returnVal = SUCCESS; + } + + return returnVal; +} + +/********************************************************************************** +* AUTHOR : Nidhi Sharma +* DATE : 15-Feb-2008 +* NAME : getRadius +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date +*************************************************************************************/ +int L7ShapeFeatureExtractor::getRadius() +{ + return m_radius; +} + + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : extractFeatures +* DESCRIPTION : Extracts L7 features from a trace group +* ARGUMENTS : The trace group from which features have to be extracted +* RETURNS : vector of L7ShapeFeature objects +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int L7ShapeFeatureExtractor::extractFeatures(const LTKTraceGroup& inTraceGroup, + vector<LTKShapeFeaturePtr>& outFeatureVec) +{ + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering " << + "L7ShapeFeatureExtractor::extractFeatures()" << endl; + + L7ShapeFeature* featurePtr = NULL; + float delta; + int currentStrokeSize; + int numPoints; + + int numberOfTraces = inTraceGroup.getNumTraces(); + + if (numberOfTraces == 0 ) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Error :" << + EEMPTY_TRACE_GROUP << " : " << getErrorMessage(EEMPTY_TRACE_GROUP) << + "L7ShapeFeatureExtractor::extractFeatures()" << endl; + + LTKReturnError(EEMPTY_TRACE_GROUP); + } + + + LTKTraceVector allTraces = inTraceGroup.getAllTraces(); + LTKTraceVector::iterator traceIter = allTraces.begin(); + LTKTraceVector::iterator traceEnd = allTraces.end(); + + //the feature vector + vector<float> xVec; + vector<float> yVec; + vector<bool> penUp; + + //concatentating the strokes + for (; traceIter != traceEnd ; ++traceIter) + { + floatVector tempxVec, tempyVec; + + (*traceIter).getChannelValues("X", tempxVec); + + (*traceIter).getChannelValues("Y", tempyVec); + + currentStrokeSize = tempxVec.size(); + + if (currentStrokeSize == 0) + { + LOG(LTKLogger::LTK_LOGLEVEL_ERR) << "Error :" << + EEMPTY_TRACE<< " : " << getErrorMessage(EEMPTY_TRACE) << + "L7ShapeFeatureExtractor::extractFeatures()" << endl; + + LTKReturnError(EEMPTY_TRACE); + } + + for(int point=0;point<currentStrokeSize;point++) + { + xVec.push_back(tempxVec[point]); + yVec.push_back(tempyVec[point]); + + if(point == currentStrokeSize - 1 ) + { + penUp.push_back(true); + } + else + { + penUp.push_back(false); + } + } + } + //concatentating the strokes + + numPoints=xVec.size(); + + vector<float> normfirstderv_x(numPoints); // Array to store the first normalized derivative w.r.t x + vector<float> normfirstderv_y(numPoints); // Array to store the first normalized derivative w.r.t y + vector<float> normsecondderv_x(numPoints); // Array to store the second normalized derivative w.r.t x + vector<float> normsecondderv_y(numPoints); // Array to store the second normalized derivative w.r.t y + vector<float> curvature(numPoints); // Array to store the curvature + + computeDerivative(xVec,yVec,normfirstderv_x,normfirstderv_y,m_radius); + + computeDerivative(normfirstderv_x,normfirstderv_y,normsecondderv_x,normsecondderv_y,m_radius); + + for(int i=0; i<numPoints; ++i) + { + //computing the curvature + delta= sqrt(pow(pow(normfirstderv_x[i],2)+pow(normfirstderv_y[i],2),3)); + curvature[i]= ((normfirstderv_x[i]*normsecondderv_y[i]) - (normsecondderv_x[i]*normfirstderv_y[i]))/(delta+EPS); + + featurePtr = new L7ShapeFeature(xVec[i], yVec[i], + normfirstderv_x[i], normfirstderv_y[i], + normsecondderv_x[i], normsecondderv_y[i], + curvature[i], penUp[i]); + //populating the feature vector + outFeatureVec.push_back(LTKShapeFeaturePtr(featurePtr)); + featurePtr = NULL; + } + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting " << + "L7ShapeFeatureExtractor::extractFeatures()" << endl; + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : getShapeFeatureInstance +* DESCRIPTION : Returns an L7ShapeFeature instance +* ARGUMENTS : +* RETURNS : An L7ShapeFeature instance +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +LTKShapeFeaturePtr L7ShapeFeatureExtractor::getShapeFeatureInstance() +{ + LTKShapeFeaturePtr tempPtr(new L7ShapeFeature); + return tempPtr; +} + + +/****************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : Sept-10-2007 +* NAME : convertFeatVecToTraceGroup +* DESCRIPTION : +* ARGUMENTS : +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description +******************************************************************************/ +int L7ShapeFeatureExtractor::convertFeatVecToTraceGroup( + const vector<LTKShapeFeaturePtr>& shapeFeature, + LTKTraceGroup& outTraceGroup) +{ + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering " << + "L7ShapeFeatureExtractor::convertFeatVecToTraceGroup()" << endl; + + vector<LTKChannel> channels; // channels of a trace + + LTKChannel xChannel("X", DT_INT, true); // x-coordinate channel of the trace + LTKChannel yChannel("Y", DT_INT, true); // y-coordinate channel of the trace + + //initializing the channels of the trace + channels.push_back(xChannel); + channels.push_back(yChannel); + + // composing the trace format object + LTKTraceFormat traceFormat(channels); + + vector<float> point; // a point of a trace + + LTKTrace trace(traceFormat); + + for(int count=0;count<(int)shapeFeature.size();count++) + { + float Xpoint, Ypoint; + bool penUp; + + L7ShapeFeature* ptr = (L7ShapeFeature*)(shapeFeature[count].operator ->()); + Xpoint = ptr->getX(); + Ypoint = ptr->getY(); + penUp = ptr->isPenUp(); + + + + point.push_back(Xpoint); + point.push_back(Ypoint); + + trace.addPoint(point); + point.clear(); + + + if(penUp == true) // end of a trace, clearing the trace now + { + outTraceGroup.addTrace(trace); + trace.emptyTrace(); + LTKTrace tempTrace(traceFormat); + trace = tempTrace; + } + } + + LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting " << + "L7ShapeFeatureExtractor::convertFeatVecToTraceGroup()" << endl; + return SUCCESS; + +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : computeDerivativeDenominator +* DESCRIPTION : Computes the denominator to be used in the derivative computation +* ARGUMENTS : The index used in derivative computation +* RETURNS : The denominator +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +int L7ShapeFeatureExtractor::computeDerivativeDenominator(int index) +{ + int denominator=0; + + for (int i=1;i<=index;i++) + { + + denominator=denominator+i*i; + } + return 2*denominator; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G. +* DATE : 10-AUGUST-2007 +* NAME : computeDerivative +* DESCRIPTION : Computes the derivative +* ARGUMENTS : The input and output vectors. The output vectors are the derivatives of the input vectors +* RETURNS : +* NOTES : +* CHANGE HISTROY +* Author Date Description of change +*************************************************************************************/ +void L7ShapeFeatureExtractor::computeDerivative(const vector<float>& xVec, + const vector<float>& yVec, + vector<float>& dx, + vector<float>& dy, + int index) +{ + int size = xVec.size(); + int denominator = computeDerivativeDenominator(index); + float x,y,diffx,diffy,delta; + float firstderv_x,firstderv_y; + int i,j; + + if(index<size-index) + { + for(i=index; i<size-index; ++i) + { + x= xVec[i]; + y= yVec[i]; + diffx=0; + diffy=0; + + for( j=1;j<=index;j++) + { + diffx = diffx + j*(xVec[i+j]-xVec[i-j]) ; + diffy = diffy + j*(yVec[i+j]-yVec[i-j]) ; + } + + firstderv_x = diffx/denominator; + firstderv_y = diffy/denominator; + delta = sqrt(pow(firstderv_x,2)+pow(firstderv_y,2)); + if(delta!=0) + { + dx[i] = firstderv_x/(delta); + dy[i] = firstderv_y/(delta); + } + else + { + dx[i] = 0; + dy[i] = 0; + } + + + } + + for(i=0;i<index;i++) + { + x= xVec[i]; + y= yVec[i]; + diffx=0; + diffy=0; + + for( j=1;j<=index;j++) + { + diffx = diffx + j*(xVec[i+j]-x) ; + diffy = diffy + j*(yVec[i+j]-y) ; + } + firstderv_x = diffx/denominator; + firstderv_y = diffy/denominator; + delta = sqrt(pow(firstderv_x,2)+pow(firstderv_y,2)); + if(delta!=0) + { + dx[i] = firstderv_x/(delta); + dy[i] = firstderv_y/(delta); + } + else + { + dx[i] = 0; + dy[i] = 0; + } + + } + + for(i=size-index;i<=size-1;i++) + { + x= xVec[i]; + y= yVec[i]; + diffx=0; + diffy=0; + + for( j=1;j<=index;j++) + { + diffx = diffx + j*(x-xVec[i-j]) ; + diffy = diffy + j*(y-yVec[i-j]) ; + } + firstderv_x = diffx/denominator; + firstderv_y = diffy/denominator; + delta = sqrt(pow(firstderv_x,2)+pow(firstderv_y,2)); + if(delta!=0) + { + dx[i] = firstderv_x/(delta); + dy[i] = firstderv_y/(delta); + } + else + { + dx[i] = 0; + dy[i] = 0; + } + } + } + if(index>size-index) + { + for(i=0; i<size; ++i) + { + x= xVec[i]; + y= yVec[i]; + diffx=0; + diffy=0; + if((0<i+j)&(i+j<size)) + { + for( j=1;j<=index;j++) + { + diffx = diffx + j*(xVec[i+j]-x) ; + diffy = diffy + j*(yVec[i+j]-y) ; + } + } + else + { + for(j=1;j<=index;j++) + { + diffx = diffx + j*(x-xVec[i-j]) ; + diffy = diffy + j*(y-yVec[i-j]) ; + } + } + + firstderv_x = diffx/denominator; + firstderv_y = diffy/denominator; + delta = sqrt(pow(firstderv_x,2)+pow(firstderv_y,2)); + if(delta!=0) + { + dx[i] = firstderv_x/(delta); + dy[i] = firstderv_y/(delta); + } + else + { + dx[i] = 0; + dy[i] = 0; + } + + } + } +} + diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeatureExtractor.h b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeatureExtractor.h new file mode 100644 index 00000000..9c48636d --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/L7ShapeFeatureExtractor.h @@ -0,0 +1,112 @@ +/***************************************************************************************** +* 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-02-20 10:03:51 +0530 (Wed, 20 Feb 2008) $ + * $Revision: 423 $ + * $Author: sharmnid $ + * + ************************************************************************/ +#include "LTKShapeFeatureExtractor.h" +/** @ingroup L7ShapeFeatureExtractor +* @brief The feature extractor for L7 features. +* @class L7ShapeFeatureExtractor +* +*/ +#define FEATEXTR_L7_DEF_RADIUS 2 + + +class L7ShapeFeatureExtractor : public LTKShapeFeatureExtractor +{ +private: + int m_radius; + +public: + /** @brief Constructor for the L7 feature extractor + * Gets the cfg file path from the contorInfo + * Reads the cfg variables and poputlates the member variables + * @param controlInfo: LTKControlInfo : The control information + * @return no return value as it is a constructor + */ + L7ShapeFeatureExtractor(const LTKControlInfo& controlInfo); + + /** @brief Extracts L7 features from an LTKTraceGroup + * The XY Coordinate values are extracted from the trace gruoup. + * Using the coordinate values, normalized first derivatives are computed. + * After computing the first derivatives, the normalized second derivatives and the curvature are computed. The second derivative and curvature computation occur simultaneously. + * @param inTraceGroup: LTKTraceGroup& : The trace group from which local seven features have to be extracted + * @return LTKShapeFeaturePtr* : A vector of pointers to LTKShapeFeature objects. The pointers point to instances of the L7ShapeFeature class. The vector contains local-seven features extracted from the trace group. + */ + + int extractFeatures(const LTKTraceGroup& inTraceGroup, + vector<LTKShapeFeaturePtr>& outFeatureVec); + + /** @brief Returns an instance of the L7ShapeFeature class + * @return LTKShapeFeature*: The returned empty L7ShapeFeature instance. + */ + LTKShapeFeaturePtr getShapeFeatureInstance(); + + /** @brief Converts a feature vector to trace group + * @param shapeFeature : LTKShapeFeaturePtr* : The feature vector to be converted to a trace group. + * @param outTraceGroup : LTKTraceGroup& : The output trace group + */ + //see interface + int convertFeatVecToTraceGroup(const vector<LTKShapeFeaturePtr>& shapeFeature, + LTKTraceGroup& outTraceGroup); + + int getRadius(); + +private: + + /** @brief Computes the denominator for derivative calculation + * @param index : int: The index used in derivative computation + * @return int : The denominator used in derivative computation + */ + int computeDerivativeDenominator(int index); + + /** @brief Computes the derivative for two input sequences + * @param xVec : vector<float>&: Input x vector. + * @param yVec : vector<float>&: Input y vector. + * @param dx : vector<float>&: Derivative vector of x + * @param dy : vector<float>&: Derivative vector of y + * @param index : int : The window size used in derivative computation + * + */ + void computeDerivative(const vector<float>& xVec, + const vector<float>& yVec, + vector<float>& dx, + vector<float>& dy, + int index); + + /** @brief reads the cfg file and sets the member variables + * @param cfgFilePath : const string&: The path of the cfg file to be opened + * @return int : The sucess or failure of the function + */ + int readConfig(const string& cfgFilePath); + + /** @validates the value passed and sets the member variable + * @param radius : const int: The value of the variable to be set + * @return int : The sucess or failure of the function + */ + int setRadius(int radius); + + +}; diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.cpp b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.cpp new file mode 100644 index 00000000..eca6cf84 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.cpp @@ -0,0 +1,105 @@ +/***************************************************************************************** +* 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-02-20 10:03:51 +0530 (Wed, 20 Feb 2008) $ + * $Revision: 423 $ + * $Author: sharmnid $ + * + ************************************************************************/ +// l7.cpp : Defines the entry point for the DLL application. + +#include "l7.h" +#include "L7ShapeFeatureExtractor.h" +#include "LTKShapeFeatureExtractor.h" +#include "L7ShapeFeature.h" +#include "LTKErrors.h" + + +#ifdef _WIN32 +#include <windows.h> +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 : Naveen Sundar G +* DATE : 10-Aug-2007 +* NAME : createFeatureExtractor +* DESCRIPTION : Creates instance of type l7ShapeFeatureExtractor and retuns of type + LTKShapeFeatureExtractor. (Acts as a Factory Method). +* ARGUMENTS : +* RETURNS : returns an instace of type LTKShapeFeatureExtractor. +* NOTES : +* CHANGE HISTORY +* Author Date Description +*************************************************************************************/ +int createShapeFeatureExtractor(const LTKControlInfo& controlInfo, + LTKShapeFeatureExtractor** outFeatureExtractor) +{ + try + { + *outFeatureExtractor = new L7ShapeFeatureExtractor(controlInfo); + } + catch(LTKException e) + { + *outFeatureExtractor = NULL; + + LTKReturnError(e.getErrorCode()); + } + + return SUCCESS; +} + +/********************************************************************************** +* AUTHOR : Naveen Sundar G +* DATE : 10-Aug-2007 +* NAME : deleteShapeFeatureExtractor +* DESCRIPTION : Destroy the instance by taking the address as its argument. +* ARGUMENTS : Address of LTKShapeRecognizerFeatureExtractor instnace. +* RETURNS : Returns 0 on Success +* NOTES : +* CHANGE HISTORY +* Author Date Description +*************************************************************************************/ +int deleteShapeFeatureExtractor(LTKShapeFeatureExtractor *obj) +{ + if ( obj != NULL ) + { + delete obj; + obj = NULL; + } + + return SUCCESS; +} diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.def b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.def new file mode 100644 index 00000000..9a185d39 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.def @@ -0,0 +1,3 @@ +EXPORTS + createShapeFeatureExtractor @1 + deleteShapeFeatureExtractor @2 diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.h b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.h new file mode 100644 index 00000000..c0f64a01 --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.h @@ -0,0 +1,94 @@ +/***************************************************************************************** +* 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-02-20 10:03:51 +0530 (Wed, 20 Feb 2008) $ + * $Revision: 423 $ + * $Author: sharmnid $ + * + ************************************************************************/ +// 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 L7_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 +// L7_API functions as being imported from a DLL, wheras this DLL sees symbols +// defined with this macro as being exported. +#ifdef _WIN32 +#ifdef L7_EXPORTS +#define L7_API __declspec(dllexport) +#else +#define L7_API __declspec(dllimport) +#endif //ifdef L7_EXPORTS +#else +#define L7_API +#endif //#ifdef _WIN32 + +#include "LTKTypes.h" + +class LTKShapeFeatureExtractor; +class LTKShapeFeature; + +/** @defgroup L7ShapeFeatureExtractor +*@brief The L7ShapeFeatureExtractor +*/ + +/** +* @ingroup L7ShapeFeatureExtractor +* @file L7.cpp +* <p> +* The functions exported by the DLL +* - ::createShapeFeatureExtractor +* - ::deleteShapeFeatureExtractor +* - ::getCurrentVersion +* - ::deleteShapeFeaturePtr +*/ + +/** +* @brief Returns a pointer to the instance of L7ShapeFeatureExtractor +* +* <p> +* This function is based on run-time polymorphism. It creates an instance of +* L7ShapeFeatureExtractor at run-time and returns it as a pointer to the base class <i>LTKShapeFeatureExtractor</i> +* </p> +* +* @param none +* +* @return Pointer to LTKShapeFeatureExtractor +*/ +//extern "C" L7_API int createShapeFeatureExtractor(const LTKControlInfo& controlInfo, LTKShapeFeatureExtractor**); +extern "C" L7_API int createShapeFeatureExtractor( + const LTKControlInfo& controlInfo, + LTKShapeFeatureExtractor** outFeatureExtractor); + +/** +* @brief Deletes the feature extractor instance. +* +* <p> +* This function cleans up all the memory allocations done by the feature extractor by calling it's destructor. +* </p> +* +* @param featureExtractorPtr - Pointer to LTKShapeFeatureExtractor. +* +* @return 0 on Success +*/ + +//smart pointer for LTKShapeFeatureExtractor?? +extern "C" L7_API int deleteShapeFeatureExtractor(LTKShapeFeatureExtractor *featureExtractorPtr); diff --git a/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.pro b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.pro new file mode 100644 index 00000000..2372c2cf --- /dev/null +++ b/src/plugins/lipi-toolkit/3rdparty/lipi-toolkit/src/reco/shaperec/featureextractor/l7/l7.pro @@ -0,0 +1,22 @@ +LIPILIBS = ltkcommon ltkutil featureextractorcommon +include(../../../../lipiplugin.pri) + +INCLUDEPATH += \ + ../../../../util/lib \ + ../common \ + +HEADERS += \ + l7.h \ + L7ShapeFeature.h \ + L7ShapeFeatureExtractor.h \ + +SOURCES += \ + l7.cpp \ + L7ShapeFeature.cpp \ + L7ShapeFeatureExtractor.cpp \ + +win32 { + DEFINES += L7_EXPORTS + LIBS += Advapi32.lib + #DEF_FILE = l7.def +} |