53 #ifdef DRWN_USE_PTHREADS
54 pthread_mutex_t _mutex;
58 unsigned _dbImagesLocked;
59 unsigned _dbImagesLoaded;
71 int maxLevels = DRWN_INT_MAX,
bool bGreyImages = GREY_IMAGES,
72 bool bBigMemory = BIG_MEMORY);
75 int minSize = 32,
int maxLevels = DRWN_INT_MAX,
bool bGreyImages = GREY_IMAGES,
76 bool bBigMemory = BIG_MEMORY);
81 void initialize(
const vector<string>& filenames);
84 void append(
const string& filename);
91 bool empty()
const {
return (_imagesLoaded == 0); }
93 size_t size()
const {
return _imagesLoaded; }
95 size_t numLocked()
const {
return _imagesLoaded - _free_list.size(); }
97 size_t memory()
const {
return _memoryUsed; }
100 const string&
filename(
unsigned indx)
const {
return _filenames[indx]; }
103 int index(
const string& filename)
const {
104 vector<string>::const_iterator it = find(_filenames.begin(), _filenames.end(), filename);
105 if (it == _filenames.end())
return -1;
106 return (
int)(it - _filenames.begin());
110 void lock(
unsigned indx);
112 void lock(
const string& filename) {
lock((
unsigned)index(filename)); }
115 inline size_t levels(
unsigned indx)
const {
return _images[indx].size(); }
117 inline size_t levels(
const string& filename)
const {
118 return _images[(unsigned)index(filename)].size();
122 inline const cv::Mat&
get(
unsigned indx,
unsigned level = 0)
const {
123 return _images[indx][level];
126 inline const cv::Mat&
get(
const string& filename,
unsigned level = 0)
const {
127 return _images[(unsigned)index(filename)][level];
131 void unlock(
unsigned indx);
133 void unlock(
const string& filename) {
unlock((
unsigned)index(filename)); }
136 cv::Mat copy(
unsigned indx,
unsigned level = 0);
138 cv::Mat
copy(
const string& filename,
unsigned level = 0) {
139 return copy((
unsigned)index(filename), level);
144 void enforceLimits();
147 size_t memory(
const vector<cv::Mat>& images)
const;
150 vector<cv::Mat> load(
const string& filename)
const;
list< unsigned > _free_list
index of images that can be safely released in least-recently-used order
Definition: drwnImagePyramidCache.h:41
const string & filename(unsigned indx) const
return the filename for image indx
Definition: drwnImagePyramidCache.h:100
int _minImageSize
minimum image dimension
Definition: drwnImagePyramidCache.h:49
vector< list< unsigned >::iterator > _free_list_map
ref to location in _free_list
Definition: drwnImagePyramidCache.h:37
void lock(const string &filename)
lock an image pyramid for use (loads if not already in the cache)
Definition: drwnImagePyramidCache.h:112
int index(const string &filename) const
returns the index for filename (slow)
Definition: drwnImagePyramidCache.h:103
size_t numLocked() const
returns number of locked image pyramids in the cache
Definition: drwnImagePyramidCache.h:95
bool empty() const
returns true if the cache is empty (but may still be initialized with filenames)
Definition: drwnImagePyramidCache.h:91
bool _bBigMemoryModel
load all images into memory (ignores MAX_IMAGES and MAX_MEMORY)
Definition: drwnImagePyramidCache.h:44
size_t _imagesLoaded
number of images loaded
Definition: drwnImagePyramidCache.h:45
static size_t MAX_IMAGES
maximum number of images in memory at any one time
Definition: drwnImagePyramidCache.h:63
int _maxLevels
maximum pyramid height
Definition: drwnImagePyramidCache.h:50
static size_t MAX_MEMORY
maximum number of bytes used at any one time
Definition: drwnImagePyramidCache.h:64
size_t levels(unsigned indx) const
returns the number of levels in an image pyramid (which must first be locked)
Definition: drwnImagePyramidCache.h:115
static bool BIG_MEMORY
default setting for big memory mode
Definition: drwnImagePyramidCache.h:66
static bool GREY_IMAGES
default setting for caching images in greyscale
Definition: drwnImagePyramidCache.h:65
vector< unsigned > _lock_counter
allows for multiple locks
Definition: drwnImagePyramidCache.h:38
double _downSampleRate
downsampling rate
Definition: drwnImagePyramidCache.h:48
size_t levels(const string &filename) const
returns the number of levels in an image pyramid (which must first be locked)
Definition: drwnImagePyramidCache.h:117
size_t memory() const
returns memory used by in-memory image pyramids
Definition: drwnImagePyramidCache.h:97
cv::Mat copy(const string &filename, unsigned level=0)
copies an image without locking it (caller must free the image)
Definition: drwnImagePyramidCache.h:138
size_t size() const
returns number of image pyramids stored in the cache
Definition: drwnImagePyramidCache.h:93
vector< string > _filenames
image filenames
Definition: drwnImagePyramidCache.h:34
Caches image pyramids in main memory up to a maximum number of images or memory limit.
Definition: drwnImagePyramidCache.h:32
vector< vector< cv::Mat > > _images
image pyramids
Definition: drwnImagePyramidCache.h:36
void unlock(const string &filename)
marks an image as free
Definition: drwnImagePyramidCache.h:133
size_t _memoryUsed
bytes used by loaded images
Definition: drwnImagePyramidCache.h:46
bool _bGreyImages
store images in greyscale (instead of RGB)
Definition: drwnImagePyramidCache.h:43