Difference between revisions of "Image I/O & Framework"

From CUVI Wiki
(21 intermediate revisions by 2 users not shown)
Line 1: Line 1:
CUVI sdlksljfdks;dlks kdsldks
==Using CUVI with C++==
==Using CUVI with C++==
CUVI C++ interface uses various features of C++ including classes, namespaces, default arguments and overloading to provide ease of use.


===CuviImage===
===CuviImage===
CuviImage is a C++ class to hold image data on the device. It has all the essential members to hold image information as well as methods to create and move image to and from device. All the C++ functions in CUVI take CuviImage as input/output image argument. CuviImage creates an image on the GPU so you do not need to cater for manually copying the image to the GPU and then back to the CPU, this is catered by CuviImage. The CuviImage members include:
CuviImage is a C++ class to hold image data on the device. It has all the essential members to hold image information as well as methods to create and move image to and from device. All the C++ functions in CUVI take CuviImage as input/output image argument. CuviImage creates an image on the GPU so you do not need to cater for manually copying the image to the GPU and then back to the CPU, this is catered by CuviImage.
====Members====
 
CuviImage methods helps create, copy and show images.
====Methods====
{|class="wikitable"
{|class="wikitable"
|-
|-
! Member name
! Method
! Type
! Description
! Description
|-
|-
| data
| CuviImage()
| void*
| Default constructor. Initializes all members with 0
| Data pointer containing the image pixel values on device
|-
| CuviImage(const Cuvi32s width, const Cuvi32s height, const Cuvi32s depth, const Cuvi32s channels);
| Creates a CuviImage of specified width, height, depth and channels.
|-
| CuviImage(const CuviSize& size, const Cuvi32s depth, const Cuvi32s channels);
| Creates a CuviImage of specified size, depth and channels.
|-
| CuviImage(const CuviImage&);
| Creates a copy of existing CuviImage
|-
| CuviStatus upload(const void* pSrcHost, Cuvi32s srcPitch);
| Copy image data from host memory to CuviImage.
|-
| CuviStatus upload(const void* pSrcHost, Cuvi32s srcPitch, const CuviStream& stream);
| Copy image data asynchronously, from host memory to CuviImage using the specified CuviStream.
|-
| CuviStatus download(void* pDstHost, Cuvi32s dstPitch);
| Copy image data from CuviImage to host memory.
|-
| CuviStatus download(void* pDstHost, Cuvi32s dstPitch, const CuviStream& stream);
| Copy image data asynchronously,from CuviImage to host memory using the specified CuviStream.
|-
| CuviStatus show(const std::string& title = "CUVI Image",Cuvi32s milliseconds = 0);
| Render CuviImage on screen for a specified amount of time
|-
|-
| width
| CuviStatus create(const Cuvi32s width, const Cuvi32s height, const Cuvi32s depth, const Cuvi32s channels);
| Cuvi32u
| Creates a CuviImage of specified width, height, depth and channels. Used for lazy initialization of a previously declared CuviImage.
| Image width in pixels
|-
|-
| height
| CuviStatus create(const CuviSize& size, const Cuvi32s depth, const Cuvi32s channels);
| Cuvi32u
| Creates a CuviImage of specified size, depth and channels. Used for lazy initialization of a previously declared CuviImage.
| Image height in pixels
|-
| CuviStatus release();
| Deallocates a CuviImage object.
|-
| ~CuviImage();
| CuviImage destructor. Calls release().
|-
|-
| pitch
| Cuvi32s width();
| size_t
| Returns the width of CuviImage in pixels.
| Image pitch/widthstep in bytes
|-
|-
| depth
| Cuvi32s height();
| Cuvi32u
| Returns the height of CuviImage in pixels.
| Defines the data container for the image. A depth of '8' creates CuviImage of type Cuvi8u
|-
|-
| dataBits
| Cuvi32s depth();
| Cuvi32u
| Returns the depth of CuviImage.
| No. of bits containing image information. By default dataBits is equal to the depth of the image
|-
|-
| nChannels
| Cuvi32s pitch();
| Cuvi32u
| Returns the size of a row in bytes, including the padding of the row.
| Number of channels in image
|-
|-
| isSigned
| Cuvi32s channels();
| bool
| Returns the number of channels of the CuviImage.
| Specifies if the image also contains negative values. (float is an exception)
 
|-
|-
| isInitialized
| CuviSize size();
| bool
| Returns the size of CuviImage.
| Specifies if the image has successfully been created on the device
 
|-
|-
| channelSequence
| Cuvi32s dataBits();
| CuviChannelSeq
| Returns the number of actual data bits of the image.
| Specifies the arrangement of image channels like RGB and BGR
|}
CuviImage methods helps create, copy and show images. All methods return CuviStatus except constructors and destructor which throws an exception in case of failure.
{|class="wikitable"
|-
|-
! Method
| CuviType type();
! Description
| Returns the type of CuviImage, e.g. CUVI_8UC1, CUVI_8UC3.
|-
|-
| CuviImage()
| CuviChannelSeq channelSeq();
| Default constructor. Initializes all members with 0
| Returns the channel sequence of the image, e.g. RGB, BGR etc.
|-
|-
| CuviImage(CuviSize size, Cuvi32u depth, Cuvi32u channels);
| bool isSigned();  
| Creates a CuviImage of specified size, depth and channels. Throws exception if memory allocation on device fails.
| Returns true in case of unsigned or floating point image type, else returns false.
|-
|-
| CuviImage(const CuviImage&);
| bool isInitialized();  
| Creates a copy of existing CuviImage
| Returns whether the image has been initialized.
|-
|-
| CuviImage(const CuviMat&);
| void* ptr();  
| Creates a copy of existing CuviMat
| Returns the GPU data pointer of the image.
|-
|-
| CuviStatus upload(void* pSrcHost, size_t srcPitch, CuviStream* stream = NULL);  
| T* ptr<T>();  
| Copy image data from host memory to CuviImage. This function also supports async operation
| Returns the GPU data pointer as the specified type.
|-
|-
| CuviStatus download(void* pDstHost, size_t dstPitch, CuviStream* stream = NULL);
| void setDataBits(const Cuvi32s dataBits);  
| Copy image data from CuviImage to host memory.
| Set the dataBits of the image.
|-
|-
| CuviStatus show(char* title = "CUVI Image",int milliseconds = 0);
| void setChannelSequence(const CuviChannelSeq sequence);
| Render CuviImage on screen for a specified amount of time
| Set the channel sequence of the image.
|}
 
====I/O using CuviImage====
{|
|style="font-size:125%;"|
<syntaxhighlight lang="cpp">
 
#include<iostream>
#include<cuvi.h>
 
using namespace std;


|-
int main()
| ~CuviImage();  
{
| CuviImage destructor. Throws an exception in case of failure
    try
    {
          const char* imagePath = "image.jpg";
          CuviImage input = cuvi::io::loadImage(imagePath);
          if(!input.isInitialized())
          {
            cout<<"Image Not Loaded"<<endl;
            return -1;
          }


|}
          CuviImage output;


          cuvi::arithmeticLogical::NOT(input,output);
 
          output.show("Negative Image");


          const char* outputPath = "output.jpg";


          cuvi::io::saveImage(output,outputPath);


    }
    catch(const char* e)
    {
          cout<<"Error: "<<endl<<e<<endl;
    }
    return 0;
}
</syntaxhighlight>
|}


;
===Namespaces===
CUVI is divided in image processing modules based on functionality. These modules use separate namespace in CUVI C++ interface to increase readability and ease of use. The current CUVI version has following namespaces:
*cuvi
**arithmeticLogical
**colorOpertions
**computerVision
**dataExchange
**geometryTransforms
**imageFiltering
**imageStatistics
**imageTransforms
**io
**device

Revision as of 16:03, 27 March 2018

Using CUVI with C++

CUVI C++ interface uses various features of C++ including classes, namespaces, default arguments and overloading to provide ease of use.

CuviImage

CuviImage is a C++ class to hold image data on the device. It has all the essential members to hold image information as well as methods to create and move image to and from device. All the C++ functions in CUVI take CuviImage as input/output image argument. CuviImage creates an image on the GPU so you do not need to cater for manually copying the image to the GPU and then back to the CPU, this is catered by CuviImage.

CuviImage methods helps create, copy and show images.

Methods

Method Description
CuviImage() Default constructor. Initializes all members with 0
CuviImage(const Cuvi32s width, const Cuvi32s height, const Cuvi32s depth, const Cuvi32s channels); Creates a CuviImage of specified width, height, depth and channels.
CuviImage(const CuviSize& size, const Cuvi32s depth, const Cuvi32s channels); Creates a CuviImage of specified size, depth and channels.
CuviImage(const CuviImage&); Creates a copy of existing CuviImage
CuviStatus upload(const void* pSrcHost, Cuvi32s srcPitch); Copy image data from host memory to CuviImage.
CuviStatus upload(const void* pSrcHost, Cuvi32s srcPitch, const CuviStream& stream); Copy image data asynchronously, from host memory to CuviImage using the specified CuviStream.
CuviStatus download(void* pDstHost, Cuvi32s dstPitch); Copy image data from CuviImage to host memory.
CuviStatus download(void* pDstHost, Cuvi32s dstPitch, const CuviStream& stream); Copy image data asynchronously,from CuviImage to host memory using the specified CuviStream.
CuviStatus show(const std::string& title = "CUVI Image",Cuvi32s milliseconds = 0); Render CuviImage on screen for a specified amount of time
CuviStatus create(const Cuvi32s width, const Cuvi32s height, const Cuvi32s depth, const Cuvi32s channels); Creates a CuviImage of specified width, height, depth and channels. Used for lazy initialization of a previously declared CuviImage.
CuviStatus create(const CuviSize& size, const Cuvi32s depth, const Cuvi32s channels); Creates a CuviImage of specified size, depth and channels. Used for lazy initialization of a previously declared CuviImage.
CuviStatus release(); Deallocates a CuviImage object.
~CuviImage(); CuviImage destructor. Calls release().
Cuvi32s width(); Returns the width of CuviImage in pixels.
Cuvi32s height(); Returns the height of CuviImage in pixels.
Cuvi32s depth(); Returns the depth of CuviImage.
Cuvi32s pitch(); Returns the size of a row in bytes, including the padding of the row.
Cuvi32s channels(); Returns the number of channels of the CuviImage.
CuviSize size(); Returns the size of CuviImage.
Cuvi32s dataBits(); Returns the number of actual data bits of the image.
CuviType type(); Returns the type of CuviImage, e.g. CUVI_8UC1, CUVI_8UC3.
CuviChannelSeq channelSeq(); Returns the channel sequence of the image, e.g. RGB, BGR etc.
bool isSigned(); Returns true in case of unsigned or floating point image type, else returns false.
bool isInitialized(); Returns whether the image has been initialized.
void* ptr(); Returns the GPU data pointer of the image.
T* ptr<T>(); Returns the GPU data pointer as the specified type.
void setDataBits(const Cuvi32s dataBits); Set the dataBits of the image.
void setChannelSequence(const CuviChannelSeq sequence); Set the channel sequence of the image.

I/O using CuviImage

#include<iostream>
#include<cuvi.h>

using namespace std;

int main()
{
    try
    {
          const char* imagePath = "image.jpg";
          CuviImage input = cuvi::io::loadImage(imagePath);
 
          if(!input.isInitialized())
          {
             cout<<"Image Not Loaded"<<endl;
             return -1;
          }

          CuviImage output;

          cuvi::arithmeticLogical::NOT(input,output);
  
          output.show("Negative Image");

          const char* outputPath = "output.jpg";

          cuvi::io::saveImage(output,outputPath);

    }
    catch(const char* e)
    {
           cout<<"Error: "<<endl<<e<<endl;
    }
    return 0;
}

Namespaces

CUVI is divided in image processing modules based on functionality. These modules use separate namespace in CUVI C++ interface to increase readability and ease of use. The current CUVI version has following namespaces:

  • cuvi
    • arithmeticLogical
    • colorOpertions
    • computerVision
    • dataExchange
    • geometryTransforms
    • imageFiltering
    • imageStatistics
    • imageTransforms
    • io
    • device