00001 #ifndef _FDETECT_REAL_DESCRIPTOR_HPP_
00002 #define _FDETECT_REAL_DESCRIPTOR_HPP_
00003
00004 #include <boost/serialization/vector.hpp>
00005 #include <boost/archive/text_oarchive.hpp>
00006 #include <boost/archive/text_iarchive.hpp>
00007 #include "fdetect/Descriptor.hpp"
00008
00009 namespace jafar {
00010 namespace fdetect_v2 {
00016 template<typename REALTYPE>
00017 class RealDescriptor : public jafar::fdetect_v2::Descriptor {
00018 public:
00019 typedef REALTYPE RealType;
00020 RealDescriptor() : m_descr(0), m_normalizeCoef(1.0) {};
00026 RealDescriptor(const std::vector<REALTYPE> &descr,
00027 REALTYPE normalizeCoef) :
00028 fdetect_v2::Descriptor(), m_descr(descr), m_normalizeCoef(normalizeCoef) {}
00035 template <typename InputIterator>
00036 RealDescriptor(InputIterator begin, InputIterator end,
00037 REALTYPE normalizeCoef) :
00038 fdetect_v2::Descriptor(), m_descr(begin, end), m_normalizeCoef(normalizeCoef) {}
00042 REALTYPE weakComparison(const jafar::fdetect_v2::RealDescriptor<REALTYPE>& snd)
00043 {
00044 return strongComparison(snd, 0.0);
00045 }
00051 REALTYPE strongComparison(const jafar::fdetect_v2::RealDescriptor<REALTYPE> &snd, REALTYPE angle)
00052 {
00053 REALTYPE v = 0.0;
00054 typename std::vector<REALTYPE>::const_iterator it, it2;
00055 for(it = m_descr.begin(), it2 = snd.m_descr.begin();
00056 it != m_descr.end();
00057 ++it, ++it2) {
00058 REALTYPE vb = (*it) - (*it2);
00059 v += vb * vb;
00060
00061
00062
00063
00064
00065
00066 }
00067
00068 return 1.0 - v * m_normalizeCoef;
00069 }
00070
00071 public:
00072 std::vector<REALTYPE> m_descr;
00073 REALTYPE m_normalizeCoef;
00074 size_t size() const { return m_descr.size(); }
00075 virtual Type type() { return Descriptor::FLOAT; }
00076 friend class boost::serialization::access;
00077 template<class Archive>
00078 void serialize(Archive &ar, const unsigned int version)
00079 {
00080 ar & m_normalizeCoef;
00081 ar & m_descr;
00082 }
00083 };
00085 typedef RealDescriptor<float> FloatDescriptor;
00087 typedef RealDescriptor<double> DoubleDescriptor;
00089 template<typename T>
00090 std::ostream& operator<<(std::ostream& s, const RealDescriptor<T>& fd)
00091 {
00092 s << " Real Descriptor : ( ";
00093 std::copy(fd.m_descr.begin(), fd.m_descr.end(),
00094 std::ostream_iterator<T>(s, " "));
00095 s << ")";
00096 return s;
00097 }
00098 }
00099 }
00100
00101 #endif