【问题标题】:NPP CUDA without freeImage没有 freeImage 的 NPP CUDA
【发布时间】:2013-02-12 05:28:23
【问题描述】:

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

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

我已经彻底查看了 NVIDIA 性能基元 (NPP),但这里只提到了一个图像,并没有具体说明使用的是哪种图像格式。

如果您有一个示例说明如何在没有 freeImage 或不从磁盘加载图像的情况下使用 NPP,那么我会非常高兴。

【问题讨论】:

    标签: image-processing cuda npp


    【解决方案1】:

    NPP 既不依赖于 FreeImage,也不遵循任何图像处理库特定的约定。它只是遵循图像处理领域中使用的一般约定。它期望图像以行优先顺序存储。图像通常存储为跨步线性内存。因此,NPP 函数将指向存储在设备上的原始图像数据的指针、图像的大小以及图像的step 作为参数。

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

    【讨论】:

      猜你喜欢
      • 2012-09-28
      • 1970-01-01
      • 2012-02-28
      • 1970-01-01
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 2016-12-09
      相关资源
      最近更新 更多