Home || Visual Search || Applications || Architecture || Important Messages || OGL || Src

FrameRegionTable.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Table_FrameRegionTable_h
00002 #define Impala_Core_Table_FrameRegionTable_h
00003 
00004 #include "Util/DatabaseReadString.h"
00005 #include "Core/Table/TableTem.h"
00006 #include "Core/Table/Read.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Tracking
00013 {
00014 
00018 class FrameRegion
00019 {
00020 public:
00021     FrameRegion(int videoId, int frame, int left, int top, int right, int bottom) :
00022         mRect(left, top, right, bottom)
00023     {
00024         mVideoId = videoId;
00025         mFrame = frame;
00026     }
00027 
00028     int GetFrameNumber()
00029     {
00030         return mFrame;
00031     }
00032 
00033     Geometry::Rectangle GetRectangle()
00034     {
00035         return mRect;
00036     }
00037 
00038     int mVideoId;
00039     int mFrame;
00040     Geometry::Rectangle mRect;
00041 };
00042 
00043 
00044 typedef int VideoId;
00045 
00046 typedef Table::TableTem<Column::ColumnTem<VideoId>,
00047                         Column::ColumnTem<int>,
00048                         Column::ColumnTem<int>,
00049                         Column::ColumnTem<int>,
00050                         Column::ColumnTem<int>,
00051                         Column::ColumnTem<int> >
00052         FrameRegionTableBaseType;
00053 
00054 
00059 class FrameRegionTable : public FrameRegionTableBaseType
00060 {
00061 public:
00062 
00063     typedef Column::ColumnTem<int> ColumnInt;
00064 
00065     FrameRegionTable() :
00066         FrameRegionTableBaseType(ColumnInt(0), ColumnInt(0), ColumnInt(0),
00067                                  ColumnInt(0), ColumnInt(0), ColumnInt(0))
00068     {
00069         SetColName(1, "videoid");
00070         SetColName(2, "frame number");
00071         SetColName(3, "x");
00072         SetColName(4, "y");
00073         SetColName(5, "w");
00074         SetColName(6, "h");
00075 
00076     }
00077 
00078     FrameRegion GetRegion(int i)
00079     {
00080         return FrameRegion(Get1(i), Get2(i), Get3(i), Get4(i), Get5(i), Get6(i));
00081     }
00082 
00083     void Add(Geometry::Rectangle r)
00084     {
00085         // assume video id and framenum are same as last entry.
00086         int vid=0, frame=0;
00087         if(mLast != 0)
00088         {
00089             vid = Get1(mLast - 1);
00090             frame = Get2(mLast - 1) + 1;
00091         }
00092         FrameRegionTableBaseType::Add(vid, frame, r.mLeft, r.mTop,
00093                                       r.mRight, r.mBottom);
00094     }
00095 
00096     void Add(FrameRegion fr)
00097     {
00098         FrameRegionTableBaseType::Add(fr.mVideoId, fr.mFrame, fr.mRect.mLeft,
00099                                       fr.mRect.mTop, fr.mRect.mRight, fr.mRect.mBottom);
00100     }
00101 
00102     void WriteTo(std::ostream& os)
00103     {
00104         // does not write vid id, this is the file format for PhD student use,
00105         // not in a 'system'
00106         int i;
00107         for(i=0 ; i<mLast ; ++i)
00108         {
00109             os << Get2(i) << " "
00110                << Get3(i) << " " << Get4(i) << " "
00111                << Get5(i) << " " << Get6(i) << "\n";
00112         }
00113     }
00114 
00115     void ReadFrom(std::istream& is)
00116     {
00117         // does not read vid id, this is the file format for PhD student use,
00118         // not in a 'system'
00119         while(!is.eof())
00120         {
00121             int frame = -1;
00122             int left, top, right, bottom;
00123             is >> frame >> left >> top >> right >> bottom;
00124             if(frame != -1)
00125             FrameRegionTableBaseType::Add(0, frame, left, top, right, bottom);
00126         }
00127     }
00128 };
00129 
00130 } // namespace Tracking
00131 } // namespace Core
00132 } // namespace Impala
00133 
00134 #endif

Generated on Thu Jan 13 09:04:39 2011 for ImpalaSrc by  doxygen 1.5.1