123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488 |
- #ifndef CACHEDEXAMPLEINCLUDE
- #define CACHEDEXAMPLEINCLUDE
- #include <assert.h>
- #include <map>
- #include "core/vector/SparseVectorT.h"
- #include "core/image/MultiChannelImageT.h"
- #include "core/image/MultiChannelImage3DT.h"
- #include "core/basics/FileMgt.h"
- namespace OBJREC
- {
- class CachedExample
- {
- protected:
-
- int newWidth;
-
- int newHeight;
-
- int newDepth;
-
- int oxsize;
-
- int oysize;
-
- int ozsize;
-
- std::vector<std::string> imgfn;
-
- NICE::MultiChannelImage3DT<double> *dchannels;
-
- NICE::MultiChannelImage3DT<int> *ichannels;
-
- NICE::MultiChannelImage3DT<long> *lchannels;
-
- std::map<int, std::string> dtemps;
- std::map<int, std::string> itemps;
- std::map<int, std::string> ltemps;
-
- void readImageData ();
-
- void readImageDataRGB ();
-
- void calcIntegralImage ();
-
- NICE::SparseVector **svmap;
-
- int *svmap_xsize;
- int *svmap_ysize;
- bool hasColorInformation;
- public:
-
- bool colorInformationAvailable() const;
- enum
- {
- L_INTEGRALIMAGE = 0,
- L_NUMCHANNELS
- };
-
- enum
- {
- I_GRAYVALUES = 0,
- I_COLOR,
- I_EDGES,
- I_NUMCHANNELS
- };
-
- enum
- {
- D_EOH = 0,
- D_INTEGRALPRIOR,
- D_INTEGRALEOH,
- D_INTEGRALCOLOR,
- D_NUMCHANNELS
- };
-
- enum
- {
- SVTEXTON = 0,
- SVNUMCHANNELS
- };
-
- void init ();
-
- CachedExample ( const std::string & imgfn,
- int newWidth = -1,
- int newHeight = -1 );
-
- CachedExample ( const std::vector<std::string> & imgfn,
- int newWidth = -1,
- int newHeight = -1,
- int newDepth = -1 );
-
- CachedExample ( const NICE::Image & img );
-
- CachedExample ( const NICE::MultiChannelImageT<int> & img );
-
- CachedExample ( const NICE::ColorImage & img, bool disableGrayConversion = false );
-
- CachedExample ( const NICE::MultiChannelImage3DT<int> & img,
- bool disableGrayConversion = false );
-
- virtual ~CachedExample();
-
- inline std::string getFilename(const int z = 0);
-
- inline int getNumImages ();
-
-
- inline NICE::MultiChannelImage3DT<double> & getDChannel ( int channel );
-
-
- inline NICE::MultiChannelImage3DT<int> & getIChannel ( int channel );
-
-
- inline NICE::MultiChannelImage3DT<long> & getLChannel ( int channel );
-
- NICE::SparseVector *getSVMap ( int svchannel, int & xsize, int & ysize, int & tm_xsize, int & tm_ysize ) const;
-
- void buildIntegralSV ( int svchannel, NICE::SparseVector *_map, int xsize_s, int ysize_s );
-
- void setSVMap ( int svchannel, NICE::SparseVector *_map, int xsize_s, int ysize_s );
-
- void getImageSize ( int & xsize, int & ysize ) const
- {
- xsize = oxsize;
- ysize = oysize;
- }
-
- void getImageSize3 ( int & xsize, int & ysize, int & zsize ) const
- {
- xsize = oxsize;
- ysize = oysize;
- zsize = ozsize;
- }
-
- void dropPreCached();
- template<class ImgPixelValue>
- void dropImages ( NICE::MultiChannelImage3DT<ImgPixelValue> *images,
- std::map<int, std::string> & temps,
- int numImages );
- };
- inline std::string CachedExample::getFilename( const int z )
- {
- return imgfn[z];
- }
- inline int CachedExample::getNumImages ()
- {
- return imgfn.size();
- }
- inline NICE::MultiChannelImage3DT<double> & CachedExample::getDChannel ( int channel )
- {
- assert ( ( channel >= 0 ) && ( channel < D_NUMCHANNELS ) );
- if ( dchannels[channel].channels() == 0 )
- {
- std::map<int, std::string>::const_iterator j = dtemps.find ( channel );
- if ( j == dtemps.end() )
- {
-
-
- }
- else
- {
-
- dchannels[channel].restore ( j->second );
-
- }
- }
- return dchannels[channel];
- }
- inline NICE::MultiChannelImage3DT<int> & CachedExample::getIChannel ( int channel )
- {
- assert ( ( channel >= 0 ) && ( channel < I_NUMCHANNELS ) );
- if ( ( ichannels[channel].channels() == 0 ) )
- {
- if ( ( imgfn[0] != "" ) && ( channel == I_GRAYVALUES ) )
- {
- readImageData();
- }
- else if ( ( imgfn[0] != "" ) && ( channel == I_COLOR ) )
- {
- readImageDataRGB();
- assert ( hasColorInformation );
- }
- else
- {
- std::map<int, std::string>::const_iterator j = itemps.find ( channel );
- if ( j == itemps.end() )
- {
-
-
- }
- else
- {
-
- ichannels[channel].restore ( j->second );
- }
- }
- }
- return ichannels[channel];
- }
- inline NICE::MultiChannelImage3DT<long> & CachedExample::getLChannel ( int channel )
- {
- assert ( ( channel >= 0 ) && ( channel < L_NUMCHANNELS ) );
- if ( lchannels[channel].channels() == 0 )
- {
- std::map<int, std::string>::const_iterator j = ltemps.find ( channel );
- if ( j == ltemps.end() )
- {
- if ( channel == L_INTEGRALIMAGE )
- {
- calcIntegralImage();
- }
- else
- {
-
-
- }
- }
- else
- {
-
- lchannels[channel].restore ( j->second );
- }
- }
- return lchannels[channel];
- }
- template<class ImgPixelValue>
- void CachedExample::dropImages ( NICE::MultiChannelImage3DT<ImgPixelValue> *images, std::map<int, std::string> & temps, int numImages )
- {
- for ( int i = 0 ; i < numImages; i++ )
- {
- std::map<int, std::string>::iterator j = temps.find ( i );
- if ( j == temps.end() )
- {
- std::string tempfilename = NICE::FileMgt::createTempFile ( "tmp/cachedexample_%s" );
-
-
- images[i].store ( tempfilename );
- temps[i] = tempfilename;
- }
- images[i].freeData();
- }
- }
- }
- #endif
|