Bufferer.cpp

00001 
00008 #include <string>
00009 #include<fstream>
00010 
00011 #include "opencv/cv.h"
00012 #include "opencv/cxcore.h"
00013 #include "opencv/highgui.h"
00014 
00015 #include "options.h"
00016 #include "utils/libutils.h"
00017 #include "video/libvideo.h"
00018 #include "stats/libstats.h"
00019 #include "dytex/libdytex.h"
00020 
00021 #include "bufferer/Bufferer.hpp"
00022 
00023 using namespace std;
00024 using namespace cv;
00025 
00041 Bufferer::Bufferer(string fpath,ios_base::openmode mode):buff(fpath.c_str(),mode)
00042 {
00043                         
00044 }
00045 
00061 long Bufferer::writeHeader(const string &str)
00062 {
00063         write(str);
00064         write(string("1.0"));
00065         long spos=buff.tellp();
00066         int dsize=0;
00067         buff.write((char*)(&dsize),4); //Write dummy size
00068         return spos;
00069 }
00070 
00071 
00087 void Bufferer::readHeader(const string &str)
00088 {
00089         //match header
00090         char tempB[100];
00091         memset(tempB,0,100);
00092         buff.get(tempB,100,0);
00093         long pos=buff.tellg();
00094         buff.seekg(pos+1); //skip 1 char        
00095         string tstr(tempB);
00096         if(tstr!=str)
00097                 CV_Error(-1,"Header Mismatch!");
00098 
00099         //match version 
00100         memset(tempB,0,100);
00101         buff.get(tempB,100,0);
00102         pos=buff.tellg();
00103         buff.seekg(pos+1); //skip 1 char
00104         tstr=tempB;
00105         if(tstr!="1.0")
00106                 CV_Error(-1,"Version Mismatch!");
00107 
00108         //read/skip size of the type
00109         int size;
00110         buff.read((char*)(&size),4);
00111 }
00112 
00125 void Bufferer::writeSize(long spos)
00126 {
00127         long epos=buff.tellp();
00128         int size=epos-spos-4;
00129         buff.seekp(spos);
00130         buff.write((char*)(&size),4);
00131         buff.seekp(epos);  //REST BACK
00132 }
00133 
00134 
00145 void Bufferer::write(const string &str)
00146 {
00147         buff.write(str.c_str(),str.length()+1); //write the null string
00148 }
00149 
00160 void Bufferer::read(string &str)
00161 {       
00162         char tempB[1024];
00163         memset(tempB,0,1024);
00164         buff.get(tempB,1024,0);
00165         long pos=buff.tellg();
00166         buff.seekg(pos+1); //skip 1 char        
00167         str=tempB;
00168 }
00169 
00183 void Bufferer::write(string name,const std::vector<string> &vec)
00184 {
00185         long spos=writeHeader(name);            
00186         int len=vec.size();
00187 
00188         buff.write((char*)(&len),4);
00189 
00190         for(int i=0;i<len;i++)
00191         {               
00192                 write(vec[i]);  
00193         }
00194 
00195         writeSize(spos);
00196 }
00197 
00198 
00212 void Bufferer::read(string name,std::vector<string> &vec)
00213 {
00214         vec.clear();
00215         readHeader(name);               
00216         int len;
00217         buff.read((char*)(&len),4);
00218 
00219         for(int i=0;i<len;i++)
00220         {
00221                 string temp;
00222                 read(temp);
00223                 vec.push_back(temp);
00224         }
00225 }
00226 
00227 
00241 void Bufferer::write(string name,const std::vector< std::vector<int> > &vec)
00242 {
00243         long spos=writeHeader(name);            
00244         int len=vec.size();
00245 
00246         buff.write((char*)(&len),4);
00247 
00248         for(int i=0;i<len;i++)
00249         {               
00250                 write("vec",vec[i]);    
00251         }
00252 
00253         writeSize(spos);
00254 }
00255 
00256 
00270 void Bufferer::read(string name,std::vector< std::vector<int> > &vec)
00271 {
00272         vec.clear();
00273         readHeader(name);               
00274         int len;
00275         buff.read((char*)(&len),4);
00276 
00277         for(int i=0;i<len;i++)
00278         {
00279                 std::vector<int> temp;
00280                 read("vec",temp);
00281                 vec.push_back(temp);
00282         }
00283 }
00284 
00285 
00299 void Bufferer::write(string name,int val)
00300 {
00301         long spos=writeHeader(name);    
00302         buff.write((char*)(&val),4);
00303         writeSize(spos);
00304 }
00305 
00319 void Bufferer::read(string name,int &val)
00320 {
00321         readHeader(name);       
00322         buff.read((char*)(&val),4);     
00323 }
00324 
00325 
00339 void Bufferer::write(string name,const std::vector<int> &vec)
00340 {
00341         long spos=writeHeader(name);            
00342         int len=vec.size();
00343 
00344         buff.write((char*)(&len),4);
00345 
00346         for(int i=0;i<len;i++)
00347         {
00348                 int temp=vec[i];
00349                 buff.write((char*)(&temp),4);
00350         }
00351 
00352         writeSize(spos);
00353 }
00354 
00368 void Bufferer::read(string name,std::vector<int> &vec)
00369 {
00370         readHeader(name);               
00371         int len;
00372         buff.read((char*)(&len),4);
00373 
00374         for(int i=0;i<len;i++)
00375         {
00376                 int temp;
00377                 buff.read((char*)(&temp),4);
00378                 vec.push_back(temp);
00379         }
00380 }
00381 
00382 
00396 void Bufferer::write(string name,bool val)
00397 {
00398         long spos=writeHeader(name);    
00399         buff.write((char*)(&val),1);
00400         writeSize(spos);
00401 }
00402 
00416 void Bufferer::read(string name,bool &val)
00417 {
00418         readHeader(name);       
00419         buff.read((char*)(&val),1);     
00420 }
00421 
00435 void Bufferer::write(string name,const std::vector<bool> &vec)
00436 {
00437         long spos=writeHeader(name);            
00438         int len=vec.size();
00439 
00440         buff.write((char*)(&len),4);
00441 
00442         for(int i=0;i<len;i++)
00443         {
00444                 bool temp=vec[i];
00445                 buff.write((char*)(&temp),1);
00446         }
00447 
00448         writeSize(spos);
00449 }
00450 
00464 void Bufferer::read(string name,std::vector<bool> &vec)
00465 {
00466         readHeader(name);               
00467         int len;
00468         buff.read((char*)(&len),4);
00469 
00470         for(int i=0;i<len;i++)
00471         {
00472                 bool temp;
00473                 buff.read((char*)(&temp),1);
00474                 vec.push_back(temp);
00475         }
00476 }
00477 
00491 void Bufferer::write(string name,unsigned char val)
00492 {
00493         long spos=writeHeader(name);    
00494         buff.write((char*)(&val),1);
00495         writeSize(spos);
00496 }
00497 
00511 void Bufferer::read(string name,unsigned char &val)
00512 {
00513         readHeader(name);
00514         buff.read((char*)(&val),1);     
00515 }
00516 
00530 void Bufferer::write(string name,double val)
00531 {
00532         long spos=writeHeader(name);    
00533         buff.write((char*)(&val),8);
00534         writeSize(spos);
00535 }
00536 
00537 
00551 void Bufferer::write(string name,const std::vector<double> &vec)
00552 {
00553         long spos=writeHeader(name);            
00554         int len=vec.size();
00555 
00556         buff.write((char*)(&len),4);
00557 
00558         for(int i=0;i<len;i++)
00559         {
00560                 double temp=vec[i];
00561                 buff.write((char*)(&temp),8);
00562         }
00563 
00564         writeSize(spos);
00565 }
00566 
00580 void Bufferer::read(string name,std::vector<double> &vec)
00581 {
00582         readHeader(name);               
00583         int len;
00584         buff.read((char*)(&len),4);
00585 
00586         for(int i=0;i<len;i++)
00587         {
00588                 double temp;
00589                 buff.read((char*)(&temp),8);
00590                 vec.push_back(temp);
00591         }
00592 }
00593 
00594 
00595 
00609 void Bufferer::write(string name,const std::vector< std::vector<double> > &vec)
00610 {
00611         long spos=writeHeader(name);            
00612         int len=vec.size();
00613 
00614         buff.write((char*)(&len),4);
00615 
00616         for(int i=0;i<len;i++)
00617         {               
00618                 write("vec",vec[i]);    
00619         }
00620 
00621         writeSize(spos);
00622 }
00623 
00624 
00638 void Bufferer::read(string name,std::vector< std::vector<double> > &vec)
00639 {
00640         vec.clear();
00641         readHeader(name);               
00642         int len;
00643         buff.read((char*)(&len),4);
00644 
00645         for(int i=0;i<len;i++)
00646         {
00647                 std::vector<double> temp;
00648                 read("vec",temp);
00649                 vec.push_back(temp);
00650         }
00651 }
00652 
00653 
00654 
00668 void Bufferer::read(string name,double &val)
00669 {
00670         readHeader(name);
00671         buff.read((char*)(&val),8);     
00672 }
00673 
00689 void Bufferer::write(string name,const Mat &mtx)
00690 {
00691         long spos=writeHeader(name);
00692 
00693         bool isempty;
00694         if(mtx.empty())
00695         {
00696                 isempty=true;                           
00697                 write("isempty",isempty);
00698                 writeSize(spos);
00699                 return;
00700         }
00701         isempty=false;
00702         write("isempty",isempty);
00703         CV_Assert((mtx.dims==3)||(mtx.dims==2));
00704         CV_Assert( (mtx.type()==CV_64F) || (mtx.type()==CV_8U) || (mtx.type()==CV_64FC3));
00705         Point3i dims(1,1,1);
00706         
00707         if(mtx.dims==2)
00708         {
00709                 dims.y=mtx.rows;
00710                 dims.z=mtx.cols;
00711         }
00712         else 
00713         {
00714                 dims.x=mtx.size[0];
00715                 dims.y=mtx.size[1];
00716                 dims.z=mtx.size[2];
00717         }
00718         int type=mtx.type();    
00719         int els=mtx.elemSize(); 
00720         
00721         buff.write((char*)(&type),4);   
00722         write(dims);
00723         buff.write((char*)(&els),4);
00724         
00725         //writing data
00726         double tmpD;
00727         Vec3d tmpDV;
00728         unsigned char tmpU;
00729         if(mtx.dims==2)
00730         {
00731                 for(int i=0;i<mtx.rows;i++)
00732                 {
00733                         for(int j=0;j<mtx.cols;j++)
00734                         {
00735                                 switch(type)
00736                                 {
00737                                 case CV_64F:
00738                                         tmpD=mtx.at<double>(i,j);                               
00739                                         buff.write((char*)(&tmpD),8);                           
00740                                         break;
00741                                 case CV_8U:
00742                                         tmpU=mtx.at<unsigned char>(i,j);                                
00743                                         buff.write((char*)(&tmpU),1);                           
00744                                         break;
00745                             case CV_64FC3:
00746                                         tmpDV=mtx.at<Vec3d>(i,j);                               
00747                                         tmpD=tmpDV[0];
00748                                         buff.write((char*)(&tmpD),8);   
00749                                         tmpD=tmpDV[1];
00750                                         buff.write((char*)(&tmpD),8);   
00751                                         tmpD=tmpDV[2];
00752                                         buff.write((char*)(&tmpD),8);                                                           
00753                                         break;
00754                                 default:
00755                                         CV_Error(-1,"type not handled yet");
00756                                 }
00757                         }
00758                 }
00759         }
00760         else
00761         {
00762                 for(int i=0;i<dims.x;i++)
00763                 {
00764                         for(int j=0;j<dims.y;j++)
00765                         {
00766                                 for(int k=0;k<dims.z;k++)
00767                                 {
00768                                         switch(type)
00769                                         {
00770                                         case CV_64F:
00771                                                 tmpD=mtx.at<double>(i,j,k);                             
00772                                                 buff.write((char*)(&tmpD),8);                           
00773                                                 break;
00774                                         case CV_8U:
00775                                                 tmpU=mtx.at<unsigned char>(i,j,k);                              
00776                                                 buff.write((char*)(&tmpU),1);                           
00777                                                 break;
00778 
00779                                         case CV_64FC3:
00780                                                 tmpDV=mtx.at<Vec3d>(i,j,k);                             
00781                                                 tmpD=tmpDV[0];
00782                                                 buff.write((char*)(&tmpD),8);   
00783                                                 tmpD=tmpDV[1];
00784                                                 buff.write((char*)(&tmpD),8);   
00785                                                 tmpD=tmpDV[2];
00786                                                 buff.write((char*)(&tmpD),8);                                                           
00787                                                 break;
00788                                         default:
00789                                                 CV_Error(-1,"type not handled yet");
00790                                         }
00791                                 }
00792                         }
00793                 }
00794         }
00795 
00796         writeSize(spos);
00797 }
00798 
00812 void Bufferer::read(string name,Mat &mtx)
00813 {
00814         bool isempty;
00815 
00816         Point3i dims(1,1,1);
00817         readHeader(name);               
00818         read("isempty",isempty);
00819         if(isempty) //empty
00820         {
00821                 return;
00822         }
00823 
00824         int type=0;     
00825         int els=0;
00826         
00827         buff.read((char*)(&type),4);
00828 
00829 
00830         read(dims);
00831         buff.read((char*)(&els),4);
00832         
00833         int sz[]={dims.x,dims.y,dims.z};
00834         if(dims.x==1)
00835                 mtx.create(dims.y,dims.z,type);
00836         else
00837                 mtx.create(3,sz,type);
00838                 
00839 
00840         //writing data
00841         double tmpD;
00842         unsigned char tmpU;
00843         Vec3d tmpDV;
00844         if(dims.x==1)
00845         {
00846                 for(int i=0;i<dims.y;i++)
00847                 {
00848                         for(int j=0;j<dims.z;j++)
00849                         {
00850                                 switch(type)
00851                                 {
00852                                 case CV_64F:                                                            
00853                                         buff.read((char*)(&tmpD),8);                            
00854                                         mtx.at<double>(i,j)=tmpD;
00855                                         break;
00856                                 case CV_8U:                                                             
00857                                         buff.read((char*)(&tmpU),1);                            
00858                                         mtx.at<unsigned char>(i,j)=tmpU;
00859                                         break;
00860                                 case CV_64FC3:                                                          
00861                                         buff.read((char*)(&tmpD),8);
00862                                         tmpDV[0]=tmpD;
00863                                         buff.read((char*)(&tmpD),8);
00864                                         tmpDV[1]=tmpD;
00865                                         buff.read((char*)(&tmpD),8);
00866                                         tmpDV[2]=tmpD;
00867                                         mtx.at<Vec3d>(i,j)=tmpDV;
00868                                         break;
00869                                 default:
00870                                         CV_Error(-1,"type not handled yet");
00871                                 }
00872                         }
00873                 }
00874         }
00875         else
00876         {
00877                 for(int i=0;i<dims.x;i++)
00878                 {
00879                         for(int j=0;j<dims.y;j++)
00880                         {
00881                                 for(int k=0;k<dims.z;k++)
00882                                 {
00883                                         switch(type)
00884                                         {
00885                                         case CV_64F:                                                            
00886                                                 buff.read((char*)(&tmpD),8);                            
00887                                                 mtx.at<double>(i,j,k)=tmpD;
00888                                                 break;
00889                                         case CV_8U:                                                             
00890                                                 buff.read((char*)(&tmpU),1);                            
00891                                                 mtx.at<unsigned char>(i,j,k)=tmpU;
00892                                                 break;
00893 
00894                                         case CV_64FC3:                                                          
00895                                                 buff.read((char*)(&tmpD),8);
00896                                                 tmpDV[0]=tmpD;
00897                                                 buff.read((char*)(&tmpD),8);
00898                                                 tmpDV[1]=tmpD;
00899                                                 buff.read((char*)(&tmpD),8);
00900                                                 tmpDV[2]=tmpD;
00901                                                 mtx.at<Vec3d>(i,j,k)=tmpDV;
00902                                                 break;
00903                                         default:
00904                                                 CV_Error(-1,"type not handled yet");
00905                                         }
00906                                 }
00907                         }
00908                 }
00909         }
00910 
00911 }
00912 
00926 void Bufferer::write(string name,const std::vector<Mat> &vec)
00927 {
00928         long spos=writeHeader(name);            
00929         int len=vec.size();
00930 
00931         buff.write((char*)(&len),4);
00932 
00933         for(int i=0;i<len;i++)
00934         {
00935                 Mat temp=vec[i];
00936                 write("Mat",temp);
00937         }
00938 
00939         writeSize(spos);
00940 }
00941 
00955 void Bufferer::read(string name,std::vector<Mat> &vec)
00956 {
00957         readHeader(name);               
00958         int len;
00959         buff.read((char*)(&len),4);
00960 
00961         for(int i=0;i<len;i++)
00962         {
00963                 
00964                 Mat temp;
00965                 read("Mat",temp);
00966                 vec.push_back(temp);
00967         }
00968 }
00969 
00980 void Bufferer::write(const Point3i &p)
00981 {       
00982         long spos=writeHeader("Point3i");       
00983         write("x",p.x);
00984         write("y",p.y);
00985         write("z",p.z);
00986         writeSize(spos);
00987 }
00988 
00999 void Bufferer::read(Point3i &p)
01000 {
01001         readHeader("Point3i");
01002         read("x",p.x);
01003         read("y",p.y);
01004         read("z",p.z);
01005 }
01006 
01020 void Bufferer::write(string name,const std::vector<Point3i> &vec)
01021 {
01022         long spos=writeHeader(name);            
01023         int len=vec.size();
01024 
01025         buff.write((char*)(&len),4);
01026 
01027         for(int i=0;i<len;i++)
01028         {
01029                 Point3i temp=vec[i];
01030                 buff.write((char*)(&temp.x),4);
01031                 buff.write((char*)(&temp.y),4);
01032                 buff.write((char*)(&temp.z),4);
01033         }
01034 
01035         writeSize(spos);
01036 }
01037 
01051 void Bufferer::read(string name,std::vector<Point3i> &vec)
01052 {
01053         readHeader(name);               
01054         int len;
01055         buff.read((char*)(&len),4);
01056 
01057         for(int i=0;i<len;i++)
01058         {
01059                 Point3i temp;
01060                 int temp1;
01061                 buff.read((char*)(&temp1),4);
01062                 temp.x=temp1;
01063                 buff.read((char*)(&temp1),4);
01064                 temp.y=temp1;
01065                 buff.read((char*)(&temp1),4);
01066                 temp.z=temp1;
01067                 vec.push_back(temp);
01068         }
01069 }
01070 
01071 
01085 void Bufferer::write(string name,const std::vector<Point2i> &vec)
01086 {
01087         long spos=writeHeader(name);            
01088         int len=vec.size();
01089 
01090         buff.write((char*)(&len),4);
01091 
01092         for(int i=0;i<len;i++)
01093         {
01094                 Point2i temp=vec[i];
01095                 buff.write((char*)(&temp.x),4);
01096                 buff.write((char*)(&temp.y),4);
01097         }
01098 
01099         writeSize(spos);
01100 }
01101 
01115 void Bufferer::read(string name,std::vector<Point2i> &vec)
01116 {
01117         readHeader(name);               
01118         int len;
01119         buff.read((char*)(&len),4);
01120 
01121         for(int i=0;i<len;i++)
01122         {
01123                 Point2i temp;
01124                 int temp1;
01125                 buff.read((char*)(&temp1),4);
01126                 temp.x=temp1;
01127                 buff.read((char*)(&temp1),4);
01128                 temp.y=temp1;
01129                 vec.push_back(temp);
01130         }
01131 }
01132 
01143 void Bufferer::write(const DytexOptions &opt)
01144 {
01145         long spos=writeHeader("DytexOptions");
01146         write("n",opt.n);
01147         write("m",opt.m);
01148         write("Ropt",(unsigned char)opt.Ropt);
01149         write("Sopt",(unsigned char)opt.Sopt);
01150         write("Yopt",(unsigned char)opt.Yopt);
01151         writeSize(spos);
01152 }
01153 
01164 void Bufferer::read(DytexOptions &opt)
01165 {
01166         readHeader("DytexOptions");
01167         read("n",opt.n);
01168         read("m",opt.m);
01169         unsigned char temp;
01170         read("Ropt",temp);
01171         opt.Ropt=(CovMatrix::cov_type)temp;
01172         read("Sopt",temp);
01173         opt.Sopt=(CovMatrix::cov_type)temp;
01174         read("Yopt",temp);
01175         opt.Yopt=(DytexOptions::Ymean_type)temp;
01176 }
01177 
01188 void Bufferer::write(const DytexRegOptions &opt)
01189 {       
01190         long spos=writeHeader("DytexRegOptions");       
01191         write("Ropt",(unsigned char)opt.Ropt);
01192         write("Qopt",(unsigned char)opt.Qopt);
01193         write("Sopt",(unsigned char)opt.Sopt);
01194         write("Aopt",(unsigned char)opt.Aopt);
01195         write("Rval",opt.Rval);
01196         write("Qval",opt.Qval);
01197         write("Sval",opt.Sval);
01198         write("Aval",opt.Aval); 
01199         
01200         writeSize(spos);
01201 }
01202 
01213 void Bufferer::read(DytexRegOptions &opt)
01214 {
01215         readHeader("DytexRegOptions");
01216         unsigned char temp;
01217         read("Ropt",temp);
01218         opt.Ropt=(CovMatrix::cov_reg_type)temp;
01219         read("Qopt",temp);
01220         opt.Qopt=(CovMatrix::cov_reg_type)temp;
01221         read("Sopt",temp);
01222         opt.Sopt=(CovMatrix::cov_reg_type)temp;
01223         read("Aopt",temp);
01224         opt.Aopt=(CovMatrix::cov_reg_type)temp;
01225         read("Rval",opt.Rval);
01226         read("Qval",opt.Qval);
01227         read("Sval",opt.Sval);
01228         read("Aval",opt.Aval);
01229 }
01230 
01241 void Bufferer::write(const CovMatrix &cm)
01242 {
01243         long spos=writeHeader("CovMatrix");
01244 
01245         write("n",cm.n);
01246         write("covopt",(unsigned char)cm.covopt);
01247         write("regopt",(unsigned char)cm.regopt);
01248         write("regval",cm.regval);
01249         write("mtx",cm.mtx);
01250 
01251         writeSize(spos);
01252 }
01253 
01264 void Bufferer::read(CovMatrix &cm)
01265 {
01266         readHeader("CovMatrix");
01267         read("n",cm.n);
01268         unsigned char temp;
01269         read("covopt",temp);
01270         cm.covopt=(CovMatrix::cov_type)temp;
01271         
01272         read("regopt",temp);
01273         cm.regopt=(CovMatrix::cov_reg_type)temp;
01274 
01275         read("regval",cm.regval);
01276         read("mtx",cm.mtx);
01277 }
01278 
01289 void Bufferer::write(const PatchOptions &popt)
01290 {       
01291         long spos=writeHeader("PatchOptions");  
01292         write(popt.win);
01293         write(popt.step);
01294         write("normopt",(unsigned char)popt.normopt);
01295         write("minvar",popt.minvar);            
01296         writeSize(spos);
01297 }
01298 
01309 void Bufferer::read(PatchOptions &popt)
01310 {       
01311         readHeader("PatchOptions");
01312         read(popt.win);
01313         read(popt.step);
01314         unsigned char temp;
01315         read("normopt",temp);
01316         popt.normopt=(PatchOptions::norm_type)temp;
01317         read("minvar",popt.minvar);             
01318 }
01319 
01330 void Bufferer::write(const PatchExtractor &pe)
01331 {       
01332         long spos=writeHeader("PatchExtractor");        
01333         write(pe.patopt);
01334         write("vrows",pe.vrows);
01335         write("vcols",pe.vcols);
01336         write("locyx",pe.locyx);
01337         write("locyx_mask",pe.locyx_mask);
01338         write("locz",pe.locz);
01339         write("curz",pe.curz);
01340         write("nextz",pe.nextz);
01341         write(pe.coff);
01342         write("allx",pe.allx);
01343         write("ally",pe.ally);
01344         write("vbuf",pe.vbuf);
01345         write("vbuf_zm",pe.vbuf_zm);
01346         write("patches",pe.patches);
01347         write("flag_zm",pe.flag_zm);
01348         write("frame_center",pe.frame_center);
01349         write("frame_patches",pe.frame_patches);
01350         writeSize(spos);
01351 }
01352 
01363 void Bufferer::read(PatchExtractor &pe)
01364 {       
01365         readHeader("PatchExtractor");           
01366         read(pe.patopt);
01367         read("vrows",pe.vrows);
01368         read("vcols",pe.vcols);
01369         read("locyx",pe.locyx);
01370         read("locyx_mask",pe.locyx_mask);
01371         read("locz",pe.locz);
01372         read("curz",pe.curz);
01373         read("nextz",pe.nextz);
01374         read(pe.coff);
01375         read("allx",pe.allx);
01376         read("ally",pe.ally);
01377         read("vbuf",pe.vbuf);
01378         read("vbuf_zm",pe.vbuf_zm);
01379         pe.patches.clear();
01380         read("patches",pe.patches);
01381         read("flag_zm",pe.flag_zm);
01382         read("frame_center",pe.frame_center);
01383         read("frame_patches",pe.frame_patches);
01384 
01385          // initialize patches
01386         pe.patches.resize(pe.locyx.size());
01387         switch(pe.patopt.normopt) 
01388         {
01389                 case PatchOptions::NORM_NONE:
01390                         // setup patches on the vbuf buffer
01391                         for (int i=0; i<(int)pe.locyx.size(); i++) 
01392                         {
01393                                 pe.patches[i] = MatVid::subvid(pe.vbuf, Range(0, pe.patopt.win.z), Range(pe.locyx[i].y, pe.locyx[i].y+pe.patopt.win.y),  Range(pe.locyx[i].x, pe.locyx[i].x+pe.patopt.win.x));
01394                         }
01395                 break;
01396 
01397                 case PatchOptions::NORM_ZM:
01398                         // setup patches on the vbuf_zm buffer
01399                         for (int i=0; i<(int)pe.locyx.size(); i++) 
01400                         {
01401                                 pe.patches[i] = MatVid::subvid(pe.vbuf_zm, Range(0, pe.patopt.win.z), Range(pe.locyx[i].y, pe.locyx[i].y+pe.patopt.win.y),Range(pe.locyx[i].x, pe.locyx[i].x+pe.patopt.win.x));
01402                         }
01403                 break;
01404                 case PatchOptions::NORM_ZMUV:
01405                         // setup patches (allocate new memory) already in new memory
01406                 break;
01407                 default:
01408                 CV_Error(-1, "bad option");
01409   }
01410     
01411   // initialize pointer to center frame
01412   pe.frame_center = MatVid::frame(pe.vbuf, pe.coff.z);
01413 
01414   // initialize pointer to center chunk of frames 
01415   int tmp = pe.patopt.step.z / 2;
01416   pe.frame_patches = MatVid::subvid(pe.vbuf, Range(pe.coff.z-tmp, pe.coff.z-tmp+pe.patopt.step.z), Range::all(), Range::all());
01417 }
01418 
01429 void Bufferer::write(const Dytex &dt)
01430 {
01431         long spos=writeHeader("Dytex");
01432         write(dt.dtopt); 
01433         write("Ymean",dt.Ymean);
01434         write("A",dt.A);
01435         write("C",dt.C);
01436         write("mu0",dt.mu0);
01437         write(dt.R);
01438         write(dt.Q);
01439         write(dt.S0);
01440         write("vrows",dt.vrows);
01441         write("vrows",dt.vcols);
01442         writeSize(spos);
01443 }
01444 
01455 void Bufferer::read(Dytex &dt)
01456 {
01457         readHeader("Dytex");
01458         read(dt.dtopt); 
01459         read("Ymean",dt.Ymean);
01460         read("A",dt.A);
01461         read("C",dt.C);
01462         read("mu0",dt.mu0);
01463         read(dt.R);
01464         read(dt.Q);
01465         read(dt.S0);
01466         read("vrows",dt.vrows);
01467         read("vrows",dt.vcols);
01468 }
01469 
01480 void Bufferer::write(const DytexMix &dtm)
01481 {               
01482         long spos=writeHeader("DytexMix");
01483         write(dtm.opt);
01484 
01485         write("K",(int)dtm.alpha.size());               
01486         //writing alpha
01487         for(int i=0;i<dtm.alpha.size();i++)
01488         {
01489                 write("alpha",dtm.alpha[i]);            
01490         }
01491 
01492         //writing DTs
01493         for(int i=0;i<dtm.dt.size();i++)
01494         {
01495                 write(dtm.dt[i]);               
01496         }
01497 
01498         write("classes",dtm.classes);
01499 
01500         writeSize(spos);
01501 }
01502 
01513 void Bufferer::read(DytexMix &dtm)
01514 {
01515         readHeader("DytexMix");
01516         read(dtm.opt);
01517         int K;
01518         read("K",K);
01519         
01520         dtm.alpha.clear();
01521         for(int i=0;i<K;i++)
01522         {
01523                 double temp;
01524                 read("alpha",temp);
01525                 dtm.alpha.push_back(temp);
01526         }
01527 
01528         dtm.dt.clear();
01529         for(int i=0;i<K;i++)
01530         {
01531                 Dytex tmpd;
01532                 read(tmpd);
01533                 dtm.dt.push_back(tmpd);
01534         }
01535         dtm.classes.clear();
01536         read("classes",dtm.classes);
01537 
01538 }
01539 
01547 void Bufferer::close()
01548 {
01549         if(buff.is_open())
01550                 buff.close();
01551 }

Generated on 18 Dec 2014 for libdt-OpenCV by  doxygen 1.6.1