Image I/O & Framework

From CUVI Wiki

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