gpt4 book ai didi

image-processing - 没有 freeImage 的 NPP CUDA

转载 作者:行者123 更新时间:2023-12-04 08:34:40 24 4
gpt4 key购买 nike

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

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

我已经彻底浏览了 NVIDIA Performance Primitives ( NPP ),但只提到了一个图像,并没有特别说明使用的是哪种图像格式。

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

最佳答案

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

关于image-processing - 没有 freeImage 的 NPP CUDA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14814088/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com