没有freeImage的NPP CUDA

Ste*_*rup 4 cuda image-processing npp

用于CUDA构建的NPP库是仅使用freeImage还是我可以使用其他结构或仅使用unsigned char*image作为NPP函数中的输入.

我提出这个问题的原因是NPP的所有样本都有freeImage的大包装器.

我已经仔细研究了NVIDIA Performance Primitives(NPP),但是只提到了一个图像,而不是特别使用哪种图像格式.

如果你有一个如何在没有freeImage的情况下使用NPP的例子,或者只是没有从磁盘加载图像,那么我会谨慎开心.

sga*_*zvi 6

NPP既不依赖于FreeImage,也不遵循任何图像处理库特定的约定.它遵循图像处理域中使用的一般惯例.它希望图像以行主要顺序存储.图像通常存储为跨步线性存储器.因此,NPP函数将指针指向存储在设备上的原始图像数据,图像的大小以及图像的步骤作为参数.

在NPP示例中,FreeImage仅用作​​图像I/O库,并且易于在主机端进行图像处理.

我利用NPP开发图像处理功能.为了测试这些功能,我使用OpenCV从磁盘读取图像,将数据复制IplImage到原始设备指针并将指针传递给NPP函数.

以下是使用NPP和OpenCV作为主机的示例.

#include <iostream>
#include <cuda_runtime.h>
#include <npp.h>
#include <opencv2/opencv.hpp>

using namespace std;

int main()
{    
    const int width = 640, height = 480;

    //Create an 8 bit single channel image
    IplImage* img = cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
    //Set All Image Pixels To 0
    cvZero(img);

    cvShowImage("Input",img);
    cvWaitKey();


    const int step = img->widthStep;
    const int bytes = img->widthStep * img->height;

    unsigned char *dSrc, *dDst;
    cudaMalloc<unsigned char>(&dSrc,bytes);
    cudaMalloc<unsigned char>(&dDst,bytes);

    //Copy Data From IplImage to Device Pointer
    cudaMemcpy(dSrc,img->imageData,bytes,cudaMemcpyHostToDevice);

    NppiSize size;
    size.width = width;
    size.height = height;

    const Npp8u value = 150;

    //Call NPP function to add a constant value to each pixel of the image
    nppiAddC_8u_C1RSfs(dSrc,step,value,dDst,step,size,1);

    //Copy back the result from device to IplImage
    cudaMemcpy(img->imageData,dDst,bytes,cudaMemcpyDeviceToHost);

    cudaFree(dSrc);
    cudaFree(dDst);

    cvShowImage("Output",img);
    cvWaitKey();

    cvReleaseImage(&img);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)