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

From CUVI Wiki
(Created page with "CUVI sdlksljfdks;dlks kdsldks ==Using CUVI with C++== ===CuviImage=== CuviImage is a C++ class to hold image data on the device. It has all the essential members to hold ima...")
 
(27 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. 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.
 


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
|-
| 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.
|-
|-
| width
| bool isSigned();
| Cuvi32u
| Returns true in case of unsigned or floating point image type, else returns false.
| Image width in pixels
|-
|-
| height
| bool isInitialized();
| Cuvi32u
| Returns whether the image has been initialized.
| Image height in pixels
|-
|-
| pitch
| void* ptr();
| size_t
| Returns the GPU data pointer of the image.
| Image pitch/widthstep in bytes
|-
|-
| depth
| T* ptr<T>();
| Cuvi32u
| Returns the GPU data pointer as the specified type.
| Defines the data container for the image. A depth of '8' creates CuviImage of type Cuvi8u
|-
|-
| nChannels
| void setDataBits(const Cuvi32s dataBits);
| Cuvi32u
| Set the dataBits of the image.
| Number of channels in image
|-
|-
| isSigned
| void setChannelSequence(const CuviChannelSeq sequence);
| bool
| Set the channel sequence of the image.
| Specifies if the image also contains negative values. (float is an exception)
|}
 
====I/O using CuviImage====
{|
|style="font-size:125%;"|
<syntaxhighlight lang="cpp">
 
#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;
| isInitialized
| bool
| Specifies if the image has successfully been created on the device


|-
          cuvi::arithmeticLogical::NOT(input,output);
| channelSequence
 
| CuviChannelSeq
          output.show("Negative Image");
| Specifies the arrangement of image channels like RGB and BGR


|}
          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