Compute Library
 21.08
ImageAccessor Class Referencefinal

Image accessor class. More...

#include <GraphUtils.h>

Collaboration diagram for ImageAccessor:
[legend]

Public Member Functions

 ImageAccessor (std::string filename, bool bgr=true, std::unique_ptr< IPreprocessor > preprocessor=nullptr)
 Constructor. More...
 
 ImageAccessor (ImageAccessor &&)=default
 Allow instances of this class to be move constructed. More...
 
bool access_tensor (ITensor &tensor) override
 Interface to be implemented to access a given tensor. More...
 
- Public Member Functions inherited from ITensorAccessor
virtual ~ITensorAccessor ()=default
 Default virtual destructor. More...
 

Detailed Description

Image accessor class.

Definition at line 230 of file GraphUtils.h.

Constructor & Destructor Documentation

◆ ImageAccessor() [1/2]

ImageAccessor ( std::string  filename,
bool  bgr = true,
std::unique_ptr< IPreprocessor preprocessor = nullptr 
)

Constructor.

Parameters
[in]filenameImage file
[in]bgr(Optional) Fill the first plane with blue channel (default = false - RGB format)
[in]preprocessor(Optional) Image pre-processing object

Definition at line 253 of file GraphUtils.cpp.

254  : _already_loaded(false), _filename(std::move(filename)), _bgr(bgr), _preprocessor(std::move(preprocessor))
255 {
256 }

◆ ImageAccessor() [2/2]

ImageAccessor ( ImageAccessor &&  )
default

Allow instances of this class to be move constructed.

Member Function Documentation

◆ access_tensor()

bool access_tensor ( ITensor tensor)
overridevirtual

Interface to be implemented to access a given tensor.

Parameters
[in]tensorTensor to be accessed
Returns
True if access is successful else false

Implements ITensorAccessor.

Definition at line 258 of file GraphUtils.cpp.

References ARM_COMPUTE_EXIT_ON_MSG, ARM_COMPUTE_EXIT_ON_MSG_VAR, ImageLoaderFactory::create(), ITensorInfo::data_layout(), ITensor::info(), arm_compute::NCHW, ITensorInfo::tensor_shape(), Dimensions< T >::x(), and Dimensions< T >::y().

259 {
260  if(!_already_loaded)
261  {
262  auto image_loader = utils::ImageLoaderFactory::create(_filename);
263  ARM_COMPUTE_EXIT_ON_MSG(image_loader == nullptr, "Unsupported image type");
264 
265  // Open image file
266  image_loader->open(_filename);
267 
268  // Get permutated shape and permutation parameters
269  TensorShape permuted_shape = tensor.info()->tensor_shape();
271  if(tensor.info()->data_layout() != DataLayout::NCHW)
272  {
273  std::tie(permuted_shape, perm) = compute_permutation_parameters(tensor.info()->tensor_shape(), tensor.info()->data_layout());
274  }
275 
276 #ifdef __arm__
277  ARM_COMPUTE_EXIT_ON_MSG_VAR(image_loader->width() != permuted_shape.x() || image_loader->height() != permuted_shape.y(),
278  "Failed to load image file: dimensions [%d,%d] not correct, expected [%" PRIu32 ",%" PRIu32 "].",
279  image_loader->width(), image_loader->height(), permuted_shape.x(), permuted_shape.y());
280 #else // __arm__
281  ARM_COMPUTE_EXIT_ON_MSG_VAR(image_loader->width() != permuted_shape.x() || image_loader->height() != permuted_shape.y(),
282  "Failed to load image file: dimensions [%d,%d] not correct, expected [%" PRIu64 ",%" PRIu64 "].",
283  image_loader->width(), image_loader->height(),
284  static_cast<uint64_t>(permuted_shape.x()), static_cast<uint64_t>(permuted_shape.y()));
285 #endif // __arm__
286 
287  // Fill the tensor with the PPM content (BGR)
288  image_loader->fill_planar_tensor(tensor, _bgr);
289 
290  // Preprocess tensor
291  if(_preprocessor)
292  {
293  _preprocessor->preprocess(tensor);
294  }
295  }
296 
297  _already_loaded = !_already_loaded;
298  return _already_loaded;
299 }
#define ARM_COMPUTE_EXIT_ON_MSG_VAR(cond, msg,...)
If the condition is true, the given message is printed and program exits.
Definition: Error.h:395
static std::unique_ptr< IImageLoader > create(const std::string &filename)
Create an image loader depending on the image type.
Definition: ImageLoader.h:509
#define ARM_COMPUTE_EXIT_ON_MSG(cond, msg)
If the condition is true, the given message is printed and program exits.
Definition: Error.h:379
Num samples, channels, height, width.
Strides of an item in bytes.
Definition: Strides.h:37

The documentation for this class was generated from the following files: