The View structure provides storage and manipulation of images. More...
Public Types | |
enum | Format { None = 0, Gray8, Uv16, Bgr24, Bgra32, Int16, Int32, Int64, Float, Double, BayerGrbg, BayerGbrg, BayerRggb, BayerBggr, Hsv24, Hsl24 } |
enum | Position { TopLeft, TopCenter, TopRight, MiddleLeft, MiddleCenter, MiddleRight, BottomLeft, BottomCenter, BottomRight } |
typedef A< uint8_t > | Allocator |
Public Member Functions | |
View () | |
View (const View &view) | |
View (const cv::Mat &mat) | |
View (size_t w, size_t h, ptrdiff_t s, Format f, void *d) | |
View (size_t w, size_t h, Format f, void *d=NULL, size_t align=Allocator::Alignment()) | |
View (const Point< ptrdiff_t > &size, Format f) | |
~View () | |
operator cv::Mat () const | |
void | ToTFTensor (tensorflow::Tensor &tensor, float shift=0, float scale=1) const |
void | ToTFTensor (tensorflow::Tensor &tensor, int batchIndex, float shift=0, float scale=0) const |
View * | Clone () const |
View & | operator= (const View &view) |
View & | operator= (const cv::Mat &mat) |
View & | Ref () |
void | Recreate (size_t w, size_t h, Format f, void *d=NULL, size_t align=Allocator::Alignment()) |
void | Recreate (const Point< ptrdiff_t > &size, Format f) |
View | Region (ptrdiff_t left, ptrdiff_t top, ptrdiff_t right, ptrdiff_t bottom) const |
View | Region (const Point< ptrdiff_t > &topLeft, const Point< ptrdiff_t > &bottomRight) const |
View | Region (const Rectangle< ptrdiff_t > &rect) const |
View | Region (const Point< ptrdiff_t > &size, Position position) const |
View | Flipped () const |
Point< ptrdiff_t > | Size () const |
size_t | DataSize () const |
size_t | Area () const |
template<class T > | |
const T & | At (size_t x, size_t y) const |
template<class T > | |
T & | At (size_t x, size_t y) |
template<class T > | |
const T & | At (const Point< ptrdiff_t > &p) const |
template<class T > | |
T & | At (const Point< ptrdiff_t > &p) |
template<class T > | |
const T * | Row (size_t row) const |
template<class T > | |
T * | Row (size_t row) |
size_t | PixelSize () const |
size_t | ChannelSize () const |
size_t | ChannelCount () const |
void | Swap (View &other) |
bool | Load (const std::string &path) |
bool | Save (const std::string &path) const |
Static Public Member Functions | |
static size_t | PixelSize (Format format) |
static size_t | ChannelSize (Format format) |
static size_t | ChannelCount (Format format) |
static int | ToOcv (Format format) |
static Format | OcvTo (int type) |
Data Fields | |
const size_t | width |
A width of the image. | |
const size_t | height |
A height of the image. | |
const ptrdiff_t | stride |
A row size of the image in bytes. | |
const Format | format |
A pixel format types of the image. | |
uint8_t *const | data |
A pointer to the pixel data (first row) of the image. | |
Detailed Description
template<template< class > class A>
struct Simd::View< A >
The View structure provides storage and manipulation of images.
In order to have mutual conversion with OpenCV image type (cv::Mat) you have to define macro SIMD_OPENCV_ENABLE:
#include "opencv2/core/core.hpp" #define SIMD_OPENCV_ENABLE #include "Simd/SimdView.hpp" int main() { typedef Simd::View<Simd::Allocator> View; View view1(40, 30, View::Bgr24); cv::Mat mat1(80, 60, CV_8UC3) View view2 = mat1; // view2 will be refer to mat1, it is not a copy! cv::Mat mat2 = view1; // mat2 will be refer to view1, it is not a copy! return 0; }
Member Typedef Documentation
◆ Allocator
Member Enumeration Documentation
◆ Format
enum Format |
Describes pixel format types of an image view.
- Note
- This type is corresponds to C type SimdPixelFormatType.
◆ Position
enum Position |
Describes the position of the child image view to the parent image view. This enum is used for creation of sub image view in method Simd::View::Region.
Constructor & Destructor Documentation
◆ View() [1/6]
◆ View() [2/6]
Creates a new View structure on the base of the image view.
- Note
- This constructor is not create new image view! It only creates a reference to the same image. If you want to create a copy then must use method Simd::View::Clone.
- Parameters
-
[in] view - an original image view.
◆ View() [3/6]
SIMD_INLINE View | ( | const cv::Mat & | mat | ) |
Creates a new View structure on the base of OpenCV Mat type.
- Note
- You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
- Parameters
-
[in] mat - an OpenCV Mat.
◆ View() [4/6]
Creates a new View structure with specified width, height, row size, pixel format and pointer to pixel data.
- Parameters
-
[in] w - a width of created image view. [in] h - a height of created image view. [in] s - a stride (row size) of created image view. [in] f - a pixel format of created image view. [in] d - a pointer to the external buffer with pixel data. If this pointer is NULL then will be created own buffer.
◆ View() [5/6]
SIMD_INLINE View | ( | size_t | w, |
size_t | h, | ||
Format | f, | ||
void * | d = NULL , |
||
size_t | align = Allocator::Alignment() |
||
) |
Creates a new View structure with specified width, height, pixel format, pointer to pixel data and memory alignment.
- Parameters
-
[in] w - a width of created image view. [in] h - a height of created image view. [in] f - a pixel format of created image view. [in] d - a pointer to the external buffer with pixel data. If this pointer is NULL then will be created own buffer. [in] align - a required memory alignment. Its default value is determined by function Allocator::Alignment.
◆ View() [6/6]
Creates a new View structure with specified width, height and pixel format.
- Parameters
-
[in] size - a size (width and height) of created image view. [in] f - a pixel format of created image view.
◆ ~View()
Member Function Documentation
◆ operator cv::Mat()
SIMD_INLINE operator cv::Mat | ( | ) | const |
Creates an OpenCV Mat which references this image.
- Note
- You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
- Returns
- an OpenCV Mat which references to this image.
◆ ToTFTensor() [1/2]
SIMD_INLINE void ToTFTensor | ( | tensorflow::Tensor & | tensor, |
float | shift = 0 , |
||
float | scale = 1 |
||
) | const |
Creates an Tensorflow Tensor which references this image.
- Note
- You have to define SIMD_TENSORFLOW_ENABLE in order to use this functionality.
- Returns
- an Tensorflow Tensor which references to this image.
◆ ToTFTensor() [2/2]
SIMD_INLINE void ToTFTensor | ( | tensorflow::Tensor & | tensor, |
int | batchIndex, | ||
float | shift = 0 , |
||
float | scale = 0 |
||
) | const |
Creates an Tensorflow Tensor which references this image.
- Note
- You have to define SIMD_TENSORFLOW_ENABLE in order to use this functionality.
- Returns
- an Tensorflow Tensor which references to this image.
◆ Clone()
SIMD_INLINE View< A > * Clone | ( | ) | const |
Gets a copy of current image view.
- Returns
- a pointer to the new View structure. The user must free this pointer after usage.
◆ operator=() [1/2]
Creates view which references to other View structure.
- Note
- This function is not create copy of image view! It only create a reference to the same image.
- Parameters
-
[in] view - an original image view.
- Returns
- a reference to itself.
◆ operator=() [2/2]
SIMD_INLINE View< A > & operator= | ( | const cv::Mat & | mat | ) |
Creates view which references to an OpenCV Mat.
- Note
- You have to define SIMD_OPENCV_ENABLE in order to use this functionality.
- Parameters
-
[in] mat - an OpenCV Mat.
- Returns
- a reference to itself.
◆ Ref()
SIMD_INLINE View< A > & Ref | ( | ) |
Creates reference to itself.
- Returns
- a reference to itself.
◆ Recreate() [1/2]
SIMD_INLINE void Recreate | ( | size_t | w, |
size_t | h, | ||
Format | f, | ||
void * | d = NULL , |
||
size_t | align = Allocator::Alignment() |
||
) |
Re-creates a View structure with specified width, height, pixel format, pointer to pixel data and memory alignment.
- Parameters
-
[in] w - a width of re-created image view. [in] h - a height of re-created image view. [in] f - a pixel format of re-created image view. [in] d - a pointer to the external buffer with pixel data. If this pointer is NULL then will be created own buffer. [in] align - a required memory alignment. Its default value is determined by function Allocator::Alignment.
◆ Recreate() [2/2]
Re-creates a View structure with specified width, height and pixel format.
- Parameters
-
[in] size - a size (width and height) of re-created image view. [in] f - a pixel format of re-created image view.
◆ Region() [1/4]
SIMD_INLINE View< A > Region | ( | ptrdiff_t | left, |
ptrdiff_t | top, | ||
ptrdiff_t | right, | ||
ptrdiff_t | bottom | ||
) | const |
Creates a new View structure which points to the region of current image bounded by the rectangle with specified coordinates.
- Parameters
-
[in] left - a left side of the region. [in] top - a top side of the region. [in] right - a right side of the region. [in] bottom - a bottom side of the region.
- Returns
- - a new View structure which points to the region of current image.
◆ Region() [2/4]
SIMD_INLINE View< A > Region | ( | const Point< ptrdiff_t > & | topLeft, |
const Point< ptrdiff_t > & | bottomRight | ||
) | const |
Creates a new View structure which points to the region of current image bounded by the rectangle with specified coordinates.
- Parameters
-
[in] topLeft - a top-left corner of the region. [in] bottomRight - a bottom-right corner of the region.
- Returns
- - a new View structure which points to the region of current image.
◆ Region() [3/4]
◆ Region() [4/4]
Creates a new View structure which points to the region of current image bounded by the rectangle with specified coordinates.
- Parameters
-
[in] size - a size (width and height) of the region. [in] position - a value represents the position of the region (see Simd::View::Position).
- Returns
- - a new View structure which points to the region of current image.
◆ Flipped()
SIMD_INLINE View< A > Flipped | ( | ) | const |
◆ Size()
SIMD_INLINE Point< ptrdiff_t > Size | ( | ) | const |
Gets size (width and height) of the image.
- Returns
- - a new Point structure with image width and height.
◆ DataSize()
SIMD_INLINE size_t DataSize | ( | ) | const |
Gets size in bytes required to store pixel data of current View structure.
- Returns
- - a size of data pixels in bytes.
◆ Area()
SIMD_INLINE size_t Area | ( | ) | const |
◆ At() [1/4]
const T& At | ( | size_t | x, |
size_t | y | ||
) | const |
Gets constant reference to the pixel of arbitrary type into current view with specified coordinates.
- Parameters
-
[in] x - a x-coordinate of the pixel. [in] y - a y-coordinate of the pixel.
- Returns
- - a constant reference to pixel of arbitrary type.
◆ At() [2/4]
T& At | ( | size_t | x, |
size_t | y | ||
) |
Gets reference to the pixel of arbitrary type into current view with specified coordinates.
- Parameters
-
[in] x - a x-coordinate of the pixel. [in] y - a y-coordinate of the pixel.
- Returns
- - a reference to pixel of arbitrary type.
◆ At() [3/4]
const T& At | ( | const Point< ptrdiff_t > & | p | ) | const |
Gets constant reference to the pixel of arbitrary type into current view with specified coordinates.
- Parameters
-
[in] p - a point with coordinates of the pixel.
- Returns
- - a constant reference to pixel of arbitrary type.
◆ At() [4/4]
T& At | ( | const Point< ptrdiff_t > & | p | ) |
Gets reference to the pixel of arbitrary type into current view with specified coordinates.
- Parameters
-
[in] p - a point with coordinates of the pixel.
- Returns
- - a reference to pixel of arbitrary type.
◆ Row() [1/2]
const T* Row | ( | size_t | row | ) | const |
Gets constant pointer to the first pixel of specified row.
- Parameters
-
[in] row - a row of the image.
- Returns
- - a constant pointer to the first pixel.
◆ Row() [2/2]
T* Row | ( | size_t | row | ) |
Gets pointer to the first pixel of specified row.
- Parameters
-
[in] row - a row of the image.
- Returns
- - a pointer to the first pixel.
◆ PixelSize() [1/2]
|
static |
Gets pixel size in bytes for current pixel format.
- Parameters
-
[in] format - a pixel format.
- Returns
- - a pixel size in bytes.
◆ PixelSize() [2/2]
SIMD_INLINE size_t PixelSize | ( | ) | const |
Gets pixel size in bytes for current image.
- Returns
- - a pixel size in bytes.
◆ ChannelSize() [1/2]
|
static |
Gets pixel channel size in bytes for current pixel format.
- Parameters
-
[in] format - a pixel format.
- Returns
- - a pixel channel size in bytes.
◆ ChannelSize() [2/2]
SIMD_INLINE size_t ChannelSize | ( | ) | const |
Gets pixel channel size in bytes for current image.
- Returns
- - a pixel channel size in bytes.
◆ ChannelCount() [1/2]
|
static |
Gets number of channels in the pixel for current pixel format.
- Parameters
-
[in] format - a pixel format.
- Returns
- - a number of channels.
◆ ChannelCount() [2/2]
SIMD_INLINE size_t ChannelCount | ( | ) | const |
Gets number of channels in the pixel for current image.
- Returns
- - a number of channels.
◆ ToOcv()
|
static |
◆ OcvTo()
◆ Swap()
SIMD_INLINE void Swap | ( | View< A > & | other | ) |
Swaps content of two (this and other) View structures.
- Parameters
-
[in] other - an other image view.
◆ Load()
SIMD_INLINE bool Load | ( | const std::string & | path | ) |
Loads image from file.
Supported formats:
- PGM(Portable Gray Map) binary(P5) (the file is loaded as 8-bit gray image).
- PPM(Portable Pixel Map) binary(P6) (the file is loaded as 32-bit BGRA image).
- Note
- PGM and PPM files with comments are not supported.
- Parameters
-
[in] path - a path to file with PGM or PPM image.
- Returns
- - a result of loading.
◆ Save()
SIMD_INLINE bool Save | ( | const std::string & | path | ) | const |
Saves image to file.
Supported formats:
- PGM(Portable Gray Map) binary(P5) (this format is used in order to save 8-bit gray images).
- PPM(Portable Pixel Map) binary(P6) (this format is used in order to save 24-bit BGR and 32-bit BGRA images).
- Parameters
-
[in] path - a path to file.
- Returns
- - a result of saving.