123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- #ifndef CACHEDEXAMPLEINCLUDE
- #define CACHEDEXAMPLEINCLUDE
- #include <assert.h>
- #include <map>
- #include "core/vector/SparseVectorT.h"
- #include "core/image/MultiChannelImageT.h"
- #include "core/basics/FileMgt.h"
- using namespace NICE;
- namespace OBJREC {
- class CachedExample
- {
- protected:
-
- int newWidth;
-
- int newHeight;
-
- int oxsize;
-
- int oysize;
-
- std::string imgfn;
-
- MultiChannelImageT<double> *dchannels;
-
- MultiChannelImageT<int> *ichannels;
-
- MultiChannelImageT<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 ();
-
- 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 NICE::Image & img );
-
-
- CachedExample( const NICE::ColorImage & img, bool disableGrayConversion = false );
-
- virtual ~CachedExample();
-
- inline std::string getFilename();
-
-
-
- inline MultiChannelImageT<double> & getDChannel ( int channel );
-
- inline MultiChannelImageT<int> & getIChannel ( int channel );
-
- inline MultiChannelImageT<long> & getLChannel ( int channel );
-
- SparseVector *getSVMap ( int svchannel, int & xsize, int & ysize, int & tm_xsize, int & tm_ysize ) const;
-
- void buildIntegralSV ( int svchannel, SparseVector *_map, int xsize_s, int ysize_s );
-
-
- void setSVMap ( int svchannel, SparseVector *_map, int xsize_s, int ysize_s );
-
- void getImageSize ( int & xsize, int & ysize ) const { xsize = oxsize; ysize = oysize; };
-
- void dropPreCached();
- template<class ImgPixelValue>
- void dropImages ( MultiChannelImageT<ImgPixelValue> *images,
- std::map<int, std::string> & temps,
- int numImages );
- };
- inline MultiChannelImageT<double> & CachedExample::getDChannel ( int channel )
- {
- assert ( (channel >= 0) && (channel < D_NUMCHANNELS) );
- if ( dchannels[channel].data == NULL ) {
- 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 std::string CachedExample::getFilename()
- {
- return imgfn;
- }
- inline MultiChannelImageT<int> & CachedExample::getIChannel ( int channel )
- {
- assert ( (channel >= 0) && (channel < I_NUMCHANNELS) );
- if ( (ichannels[channel].data == NULL) )
- {
- if ( (imgfn != "") && (channel == I_GRAYVALUES) )
- {
- readImageData();
- } else if ( (imgfn != "") && (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 MultiChannelImageT<long> & CachedExample::getLChannel ( int channel )
- {
- assert ( (channel >= 0) && (channel < L_NUMCHANNELS) );
- if ( lchannels[channel].data == NULL ) {
- 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 ( MultiChannelImageT<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 = FileMgt::createTempFile("tmp/cachedexample_%s");
-
-
- images[i].store ( tempfilename );
- temps[i] = tempfilename;
- }
- images[i].freeData();
- }
- }
- }
- #endif
|