asmlib-opencv
an ASM(Active Shape Model) implementation by C++ & OpenCV
/media/Data/chenxing/myProj/asmlib-opencv/src/shapevec.h
Go to the documentation of this file.
00001 #ifndef SHAPEVEC_H
00002 #define SHAPEVEC_H
00003 
00004 #include "similaritytrans.h"
00005 
00006 #include "cv.h"
00007 #include "highgui.h"
00008 #include <vector>
00009 using std::vector;
00010 using cv::Point_;
00011 using cv::Mat_;
00012 using cv::Mat;
00013 using cv::imread;
00014 using cv::mean;
00015 typedef unsigned int uint;
00016 
00017 namespace StatModel {
00018 
00020 class ShapeVec : public Mat_< double > {
00021   public:
00023     ShapeVec(const Mat_< double > &a):Mat_< double >(a){}
00024 
00026     ShapeVec & operator =(const Mat_< double > &a) {
00027         Mat_< double >::operator=(a);
00028         return *this;
00029     }
00030 
00032     ShapeVec(){}
00033 
00035     void alignTo(const ShapeVec & ref);
00036 
00038     void zeroGravity();
00039 
00041     void scaleToOne();
00042 
00043     void doTranslate(double vX, double vY);
00044     void doScale(double r);
00045 
00046     double getXMean() const {return mean(rowRange(0, rows / 2))[0];}
00047     double getYMean() const {return mean(rowRange(rows / 2, rows))[0];}
00048 
00049     double X(int i) const { return (*this)(i, 0); }
00050     double & X(int i) { return (*this)(i, 0); }
00051     double Y(int i) const { return (*this)(i + (rows >> 1), 0); }
00052     double & Y(int i) { return (*this)(i+(rows>>1), 0); }
00053 
00054     cv::Rect_<double> getBoundRect();
00055 
00057     void restoreToPointList(
00058       vector< Point_< int > > &v,
00059       const SimilarityTrans &st
00060     );
00061 
00063     void fromPointList(const vector< cv::Point2i > &v);
00064 
00066     int nPoints() const { return (rows >> 1); }
00067 
00069     SimilarityTrans getShapeTransformFitingSize(
00070         const cv::Size &rect,
00071         double scaleRatio=0.9, double xOffset=0, double yOffset=0);
00072 };
00073 } // Namespace
00074 #endif // SHAPEVEC_H
 All Classes Namespaces Files Functions Variables Typedefs Defines