Jetson Inference
DNN Vision Library
|
Loading and saving image files from disk. More...
Classes | |
class | imageLoader |
Load an image or set of images from disk into GPU memory. More... | |
class | imageWriter |
Save an image or set of images to disk. More... | |
Functions | |
template<typename T > | |
bool | loadImage (const char *filename, T **ptr, int *width, int *height) |
Load a color image from disk into CUDA memory, in uchar3/uchar4/float3/float4 formats with pixel values 0-255. More... | |
bool | loadImage (const char *filename, void **output, int *width, int *height, imageFormat format) |
Load a color image from disk into CUDA memory, in uchar3/uchar4/float3/float4 formats with pixel values 0-255. More... | |
bool | loadImageRGBA (const char *filename, float4 **ptr, int *width, int *height) |
Load a color image from disk into CUDA memory with alpha, in float4 RGBA format with pixel values 0-255. More... | |
bool | loadImageRGBA (const char *filename, float4 **cpu, float4 **gpu, int *width, int *height) |
Load a color image from disk into CUDA memory with alpha, in float4 RGBA format with pixel values 0-255. More... | |
template<typename T > | |
bool | saveImage (const char *filename, T *ptr, int width, int height, int quality=95, const float2 &pixel_range=make_float2(0, 255), bool sync=true) |
Save an image in CPU/GPU shared memory to disk. More... | |
bool | saveImage (const char *filename, void *ptr, int width, int height, imageFormat format, int quality=95, const float2 &pixel_range=make_float2(0, 255), bool sync=true) |
Save an image in CPU/GPU shared memory to disk. More... | |
bool | saveImageRGBA (const char *filename, float4 *ptr, int width, int height, float max_pixel=255.0f, int quality=100) |
Save a float4 image in CPU/GPU shared memory to disk. More... | |
Loading and saving image files from disk.
class imageLoader |
Load an image or set of images from disk into GPU memory.
Supported image formats for loading are JPG, PNG, TGA, BMP, GIF, PSD, HDR, PIC, and PNM (PPM/PGM binary). Internally, imageLoader uses the loadImage() function to load the images, so the supported formats are the same.
imageLoader has the ability to load an sequence of images from a directory, including wildcard characters (e.g. images/*.jpg
), or just a single image. When given just the path to a directory, it will load all valid images from that directory.
Public Member Functions | |
virtual | ~imageLoader () |
Destructor. More... | |
virtual bool | Capture (void **image, imageFormat format, uint64_t timeout=DEFAULT_TIMEOUT, int *status=NULL) |
Load the next frame. More... | |
virtual bool | Open () |
Open the stream. More... | |
virtual void | Close () |
Close the stream. More... | |
bool | IsEOS () const |
Return true if End Of Stream (EOS) has been reached. More... | |
virtual uint32_t | GetType () const |
Return the interface type (imageLoader::Type) More... | |
Public Member Functions inherited from videoSource | |
virtual | ~videoSource () |
Destroy interface and release all resources. More... | |
template<typename T > | |
bool | Capture (T **image, int *status) |
Capture the next image from the video stream, using the default timeout of 1000ms. More... | |
template<typename T > | |
bool | Capture (T **image, uint64_t timeout=DEFAULT_TIMEOUT, int *status=NULL) |
Capture the next image from the video stream. More... | |
bool | IsStreaming () const |
Check if the device is actively streaming or not. More... | |
uint32_t | GetWidth () const |
Return the width of the stream, in pixels. More... | |
uint32_t | GetHeight () const |
Return the height of the stream, in pixels. More... | |
uint32_t | GetFrameRate () const |
Return the framerate, in Hz or FPS. More... | |
uint64_t | GetFrameCount () const |
Return the number of frames captured. More... | |
uint64_t | GetLastTimestamp () const |
Get timestamp of the last captured frame, in nanoseconds. More... | |
imageFormat | GetRawFormat () const |
Get raw image format. More... | |
const URI & | GetResource () const |
Return the resource URI of the stream. More... | |
const videoOptions & | GetOptions () const |
Return the videoOptions of the stream. More... | |
bool | IsType (uint32_t type) const |
Check if this stream is of a particular type. More... | |
template<typename T > | |
bool | IsType () const |
Check if a this stream is of a particular type. More... | |
const char * | TypeToStr () const |
Convert this stream's class type to string. More... | |
Static Public Member Functions | |
static imageLoader * | Create (const char *path, const videoOptions &options=videoOptions()) |
Create an imageLoader instance from a path and optional videoOptions. More... | |
static imageLoader * | Create (const videoOptions &options) |
Create an imageLoader instance from the provided video options. More... | |
static bool | IsSupportedExtension (const char *ext) |
Return true if the extension is in the list of SupportedExtensions. More... | |
Static Public Member Functions inherited from videoSource | |
static videoSource * | Create (const videoOptions &options) |
Create videoSource interface from a videoOptions struct that's already been filled out. More... | |
static videoSource * | Create (const char *URI, const videoOptions &options=videoOptions()) |
Create videoSource interface from a resource URI string and optional videoOptions. More... | |
static videoSource * | Create (const char *URI, const commandLine &cmdLine) |
Create videoSource interface from a resource URI string and parsing command line arguments. More... | |
static videoSource * | Create (const char *URI, const int argc, char **argv) |
Create videoSource interface from a resource URI string and parsing command line arguments. More... | |
static videoSource * | Create (const int argc, char **argv, int positionArg=-1) |
Create videoSource interface by parsing command line arguments, including the resource URI. More... | |
static videoSource * | Create (const commandLine &cmdLine, int positionArg=-1) |
Create videoSource interface by parsing command line arguments, including the resource URI. More... | |
static const char * | Usage () |
Usage string for command line arguments to Create() More... | |
static const char * | TypeToStr (uint32_t type) |
Convert a class type to a string. More... | |
Static Public Attributes | |
static const uint32_t | Type = (1 << 4) |
Unique type identifier of imageLoader class. More... | |
static const char * | SupportedExtensions [] |
String array of supported image file extensions, terminated with a NULL sentinel value. More... | |
Static Public Attributes inherited from videoSource | |
static const uint64_t | DEFAULT_TIMEOUT =1000 |
The default Capture timeout (1000ms) More... | |
Protected Member Functions | |
imageLoader (const videoOptions &options) | |
bool | isLooping () const |
Protected Member Functions inherited from videoSource | |
videoSource (const videoOptions &options) | |
Protected Attributes | |
bool | mEOS |
size_t | mLoopCount |
size_t | mNextFile |
std::vector< std::string > | mFiles |
std::vector< void * > | mBuffers |
Protected Attributes inherited from videoSource | |
bool | mStreaming |
videoOptions | mOptions |
uint64_t | mLastTimestamp |
imageFormat | mRawFormat |
Additional Inherited Members | |
Public Types inherited from videoSource | |
enum | Status { ERROR = -2, EOS = -1, TIMEOUT = 0, OK = 1 } |
Stream status codes that are optionally returned from Capture() More... | |
|
virtual |
Destructor.
|
protected |
|
virtual |
|
virtual |
|
static |
Create an imageLoader instance from a path and optional videoOptions.
|
static |
Create an imageLoader instance from the provided video options.
|
inlinevirtual |
Return the interface type (imageLoader::Type)
Reimplemented from videoSource.
|
inline |
Return true if End Of Stream (EOS) has been reached.
In the context of imageLoader, EOS means that all images in the sequence have been loaded, and looping is either disabled or all loops have already been run.
|
inlineprotected |
|
static |
Return true if the extension is in the list of SupportedExtensions.
ext | string containing the extension to be checked (should not contain leading dot) |
|
virtual |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
static |
String array of supported image file extensions, terminated with a NULL sentinel value.
The supported extension are:
|
static |
Unique type identifier of imageLoader class.
class imageWriter |
Save an image or set of images to disk.
Supported image formats for saving are JPG, PNG, TGA, and BMP. Internally, imageLoader uses the saveImage() function to save the images, so the supported formats are the same.
imageWriter has the ability to write a sequence of images to a directory, for example images/i.jpg
(where i
becomes the image number), or just a single image with a static filename (e.g. images/my_image.jpg
). When given just the path of a directory as output, it will default to incremental i.jpg
sequencing and save in JPG format.
Public Member Functions | |
virtual | ~imageWriter () |
Destructor. More... | |
template<typename T > | |
bool | Render (T *image, uint32_t width, uint32_t height) |
Save the next frame. More... | |
virtual bool | Render (void *image, uint32_t width, uint32_t height, imageFormat format) |
Save the next frame. More... | |
virtual uint32_t | GetType () const |
Return the interface type (imageWriter::Type) More... | |
Public Member Functions inherited from videoOutput | |
virtual | ~videoOutput () |
Destroy interface and release all resources. More... | |
template<typename T > | |
bool | Render (T *image, uint32_t width, uint32_t height) |
Render and output the next frame to the stream. More... | |
virtual bool | Open () |
Begin streaming the device. More... | |
virtual void | Close () |
Stop streaming the device. More... | |
bool | IsStreaming () const |
Check if the device is actively streaming or not. More... | |
uint32_t | GetWidth () const |
Return the width of the stream, in pixels. More... | |
uint32_t | GetHeight () const |
Return the height of the stream, in pixels. More... | |
float | GetFrameRate () const |
Return the framerate, in Hz or FPS. More... | |
uint64_t | GetFrameCount () const |
Return the number of frames output. More... | |
const URI & | GetResource () const |
Return the resource URI of the stream. More... | |
const videoOptions & | GetOptions () const |
Return the videoOptions of the stream. More... | |
void | AddOutput (videoOutput *output) |
Add an output sub-stream. More... | |
uint32_t | GetNumOutputs () const |
Return the number of sub-streams. More... | |
videoOutput * | GetOutput (uint32_t index) const |
Return a sub-stream. More... | |
virtual void | SetStatus (const char *str) |
Set a status string (i.e. More... | |
bool | IsType (uint32_t type) const |
Check if this stream is of a particular type. More... | |
template<typename T > | |
bool | IsType () const |
Check if a this stream is of a particular type. More... | |
const char * | TypeToStr () const |
Convert this stream's class type to string. More... | |
Static Public Member Functions | |
static imageWriter * | Create (const char *path, const videoOptions &options=videoOptions()) |
Create an imageWriter instance from a path and optional videoOptions. More... | |
static imageWriter * | Create (const videoOptions &options) |
Create an imageWriter instance from the provided video options. More... | |
static bool | IsSupportedExtension (const char *ext) |
Return true if the extension is in the list of SupportedExtensions. More... | |
Static Public Member Functions inherited from videoOutput | |
static videoOutput * | Create (const videoOptions &options) |
Create videoOutput interface from a videoOptions struct that's already been filled out. More... | |
static videoOutput * | Create (const char *URI, const videoOptions &options=videoOptions()) |
Create videoOutput interface from a resource URI string and optional videoOptions. More... | |
static videoOutput * | Create (const char *URI, const commandLine &cmdLine) |
Create videoOutput interface from a resource URI string and parsing command line arguments. More... | |
static videoOutput * | Create (const char *URI, const int argc, char **argv) |
Create videoOutput interface from a resource URI string and parsing command line arguments. More... | |
static videoOutput * | Create (const int argc, char **argv, int positionArg=-1) |
Create videoOutput interface by parsing command line arguments, including the resource URI. More... | |
static videoOutput * | Create (const commandLine &cmdLine, int positionArg=-1) |
Create videoOutput interface by parsing command line arguments, including the resource URI. More... | |
static videoOutput * | CreateNullOutput () |
Create videoOutput interface that acts as a NULL output and does nothing with incoming frames. More... | |
static const char * | Usage () |
Usage string for command line arguments to Create() More... | |
static const char * | TypeToStr (uint32_t type) |
Convert a class type to a string. More... | |
Static Public Attributes | |
static const uint32_t | Type = (1 << 5) |
Unique type identifier of imageWriter class. More... | |
static const char * | SupportedExtensions [] |
String array of supported image file extensions, terminated with a NULL sentinel value. More... | |
Protected Member Functions | |
imageWriter (const videoOptions &options) | |
Protected Member Functions inherited from videoOutput | |
videoOutput (const videoOptions &options) | |
Protected Attributes | |
uint32_t | mFileCount |
char | mFileOut [1024] |
Protected Attributes inherited from videoOutput | |
bool | mStreaming |
videoOptions | mOptions |
std::vector< videoOutput * > | mOutputs |
|
virtual |
Destructor.
|
protected |
|
static |
Create an imageWriter instance from a path and optional videoOptions.
|
static |
Create an imageWriter instance from the provided video options.
|
inlinevirtual |
Return the interface type (imageWriter::Type)
Reimplemented from videoOutput.
|
static |
Return true if the extension is in the list of SupportedExtensions.
ext | string containing the extension to be checked (should not contain leading dot) |
|
inline |
Save the next frame.
|
virtual |
|
protected |
|
protected |
|
static |
String array of supported image file extensions, terminated with a NULL sentinel value.
The supported extension are:
|
static |
Unique type identifier of imageWriter class.
bool loadImage | ( | const char * | filename, |
T ** | ptr, | ||
int * | width, | ||
int * | height | ||
) |
Load a color image from disk into CUDA memory, in uchar3/uchar4/float3/float4 formats with pixel values 0-255.
Supported image file formats by loadImage() include:
This function loads the image into shared CPU/GPU memory, using the functions from cudaMappedMemory.h
[in] | filename | Path to the image file to load from disk. |
[out] | ptr | Reference to pointer that will be set to the shared CPU/GPU buffer containing the image that will be allocated. This buffer will be allocated by loadImage() in CUDA mapped memory, so it is shared between CPU/GPU. gpu will be the pointer to this shared buffer in the GPU's address space. There is physically one buffer in memory. |
[in,out] | width | Pointer to int variable that gets set to the width of the image in pixels. If the width variable contains a non-zero value when it's passed in, the image is resized to this desired width. Otherwise if the value of width is 0, the image will be loaded with it's dimensions from the file on disk. |
[in,out] | height | Pointer to int variable that gets set to the height of the image in pixels. If the height variable contains a non-zero value when it's passed in, the image is resized to this desired height. Otherwise if the value of height is 0, the image will be loaded with it's dimensions from the file on disk. |
bool loadImage | ( | const char * | filename, |
void ** | output, | ||
int * | width, | ||
int * | height, | ||
imageFormat | format | ||
) |
Load a color image from disk into CUDA memory, in uchar3/uchar4/float3/float4 formats with pixel values 0-255.
Supported image file formats by loadImage() include:
This function loads the image into shared CPU/GPU memory, using the functions from cudaMappedMemory.h
[in] | filename | Path to the image file to load from disk. |
[out] | ptr | Reference to pointer that will be set to the shared CPU/GPU buffer containing the image that will be allocated. This buffer will be allocated by loadImage() in CUDA mapped memory, so it is shared between CPU/GPU. gpu will be the pointer to this shared buffer in the GPU's address space. There is physically one buffer in memory. |
[in,out] | width | Pointer to int variable that gets set to the width of the image in pixels. If the width variable contains a non-zero value when it's passed in, the image is resized to this desired width. Otherwise if the value of width is 0, the image will be loaded with it's dimensions from the file on disk. |
[in,out] | height | Pointer to int variable that gets set to the height of the image in pixels. If the height variable contains a non-zero value when it's passed in, the image is resized to this desired height. Otherwise if the value of height is 0, the image will be loaded with it's dimensions from the file on disk. |
bool loadImageRGBA | ( | const char * | filename, |
float4 ** | cpu, | ||
float4 ** | gpu, | ||
int * | width, | ||
int * | height | ||
) |
Load a color image from disk into CUDA memory with alpha, in float4 RGBA format with pixel values 0-255.
bool loadImageRGBA | ( | const char * | filename, |
float4 ** | ptr, | ||
int * | width, | ||
int * | height | ||
) |
Load a color image from disk into CUDA memory with alpha, in float4 RGBA format with pixel values 0-255.
bool saveImage | ( | const char * | filename, |
T * | ptr, | ||
int | width, | ||
int | height, | ||
int | quality = 95 , |
||
const float2 & | pixel_range = make_float2(0,255) , |
||
bool | sync = true |
||
) |
Save an image in CPU/GPU shared memory to disk.
Supported image file formats by saveImage() include:
filename | Desired path of the image file to save to disk. |
ptr | Pointer to the buffer containing the image in shared CPU/GPU zero-copy memory. |
width | Width of the image in pixels. |
height | Height of the image in pixels. |
max_pixel | The maximum pixel value of this image, by default it's 255 for images in the range of 0-255. If your image is in the range of 0-1, pass 1.0 as this value. Then the pixel values of the image will be rescaled appropriately to be stored on disk (which expects a range of 0-255). |
quality | Indicates the compression quality level (between 1 and 100) to be applied for JPEG and PNG images. A level of 1 correponds to reduced quality and maximum compression. A level of 100 corresponds to maximum quality and reduced compression. By default a level of 95 is used for high quality and moderate compression. Note that this quality parameter only applies to JPEG and PNG, other formats will ignore it. |
sync | If true (default), the GPU will be sychronized with cudaDeviceSynchronize() to assure that any processing on the image has been completed before saving it to disk. |
bool saveImage | ( | const char * | filename, |
void * | ptr, | ||
int | width, | ||
int | height, | ||
imageFormat | format, | ||
int | quality = 95 , |
||
const float2 & | pixel_range = make_float2(0, 255) , |
||
bool | sync = true |
||
) |
Save an image in CPU/GPU shared memory to disk.
Supported image file formats by saveImage() include:
filename | Desired path of the image file to save to disk. |
ptr | Pointer to the buffer containing the image in shared CPU/GPU zero-copy memory. |
width | Width of the image in pixels. |
height | Height of the image in pixels. |
max_pixel | The maximum pixel value of this image, by default it's 255 for images in the range of 0-255. If your image is in the range of 0-1, pass 1.0 as this value. Then the pixel values of the image will be rescaled appropriately to be stored on disk (which expects a range of 0-255). |
quality | Indicates the compression quality level (between 1 and 100) to be applied for JPEG and PNG images. A level of 1 correponds to reduced quality and maximum compression. A level of 100 corresponds to maximum quality and reduced compression. By default a level of 95 is used for high quality and moderate compression. Note that this quality parameter only applies to JPEG and PNG, other formats will ignore it. |
sync | If true (default), the GPU will be sychronized with cudaDeviceSynchronize() to assure that any processing on the image has been completed before saving it to disk. |
bool saveImageRGBA | ( | const char * | filename, |
float4 * | ptr, | ||
int | width, | ||
int | height, | ||
float | max_pixel = 255.0f , |
||
int | quality = 100 |
||
) |
Save a float4 image in CPU/GPU shared memory to disk.