00001
00002
00003 #ifndef SAMS_FRAME_HPP
00004 #define SAMS_FRAME_HPP
00005
00006 #include <string>
00007 #include <vector>
00008 #include "image/Image.hpp"
00009 #include "sams/detector.hpp"
00010 #include "sams/descriptor.hpp"
00011 #include "sams/feature.hpp"
00012
00013 namespace jafar {
00014 namespace sams {
00015
00016
00017
00018 class Frame {
00019 public:
00020
00021
00022 Frame() : mImg(0) {};
00023 Frame(int width_, int height_) : mImg(new jafar::image::Image(width_,height_,IPL_DEPTH_8U,JfrImage_CS_GRAY)) {};
00024 Frame(const jafar::image::Image& img_) : mImg(0) {
00025 attachImage(img_);
00026 };
00027 Frame(const std::string filename_) : mImg(0) {
00028 attachImage(filename_);
00029 };
00030
00031 ~Frame() {
00032 clean();
00033 if (mImg)
00034 delete mImg;
00035 };
00036
00037
00038 operator jafar::image::Image const & () const {
00039 return *mImg;
00040 };
00041
00042 operator jafar::image::Image & () {
00043 return *mImg;
00044 };
00045
00046 operator jafar::image::Image * const () const {
00047 return mImg;
00048 };
00049
00050 operator jafar::image::Image * () {
00051 return mImg;
00052 };
00053
00054 inline int size() const {
00055 return mFeatures.size();
00056 };
00057
00058 inline Feature * const ptr(int i) const {
00059 return mFeatures[i];
00060 };
00061
00062 inline Feature * ptr(int i) {
00063 return mFeatures[i];
00064 };
00065
00066 inline Feature const & operator[] (int i) const {
00067 return *(mFeatures[i]);
00068 };
00069
00070 inline Feature& operator[] (int i) {
00071 return *(mFeatures[i]);
00072 };
00073
00074
00075 void attachImage(const jafar::image::Image& img_) {
00076 JFR_PRECOND((img_.depth() == IPL_DEPTH_8U) && (img_.channels() == 1),
00077 "Frame: wrong source image type. must be U8 single channel");
00078 if (mImg)
00079 delete mImg;
00080 mImg = new jafar::image::Image(img_);
00081 };
00082
00083 void attachImage(const std::string filename_) {
00084 if (mImg)
00085 delete mImg;
00086 mImg = jafar::image::Image::loadImage(filename_.c_str(),0);
00087 };
00088
00089 void detachImage(bool erase_=false) {
00090 clean();
00091 if (erase_)
00092 delete mImg;
00093 mImg = 0;
00094 };
00095
00096 void generateFeatures(const jafar::sams::Detector& det_);
00097
00098 void generateDescriptors(const jafar::sams::DescriptorFactory& desc_);
00099
00100 inline void clean() {
00101 for(int i=0; i< size(); i++)
00102 delete mFeatures[i];
00103 mFeatures.clear();
00104 };
00105 private:
00106 jafar::image::Image * mImg;
00107 std::vector<jafar::sams::Feature *> mFeatures;
00108
00109 };
00110 }
00111 }
00112
00113 #endif // SAMS_FRAME_HPP