简体   繁体   中英

How to load a gray scale image in CUDA Visual Studio 10?

I just want to know the CUDA code of loading an image in visual studio 10. I am writing following code

 char * srcPath = "C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v5.0/src/lena.pgm";

 cutLoadPGMub(srcPath , &h_pixels , &width , &height);

but it is not working. I think i am giving the path of the image wrongly...

Please provide the solution for this. I am just new in CUDA.

The method you are showing would only be possible on a very old CUDA version, ie CUDA 4.2 or earlier and depends on SDK functions that have been removed in newer CUDA distributions.

Loading a PGM image (or any image from a disk file) is not CUDA-specific, and there are many resources for this available on the web and here on stackoverflow, such as this question/answer .

I would strongly encourage you to find and use a resource of your own choice. By doing so, your code/building environment would not be dependent on the CUDA samples distribution, which may change from one CUDA release to the next (as has already happened from your formulation.)

However the CUDA samples still do load PGM images in order to perform certain demonstrations. If you'd like to use one of these as an example, refer to the helper_image.h file for a summary of available functions, such as sdkLoadPGM and sdkSavePGM . On a standard linux install of recent CUDA versions, this file would be located at /usr/local/cuda/samples/common/inc . However, there is no guarantee that future CUDA versions will provide this functionality in this way.

For a fully worked example of the use of these PGM functions, take a look at any of the sample codes that use them (linux grep will help here) such as the SobelFilter cuda sample code (in particular, SobelFilter.cpp ):

    if (sdkLoadPGM<unsigned char>(file, &pixels, &w, &h) != true)
    {
        printf("Failed to load PGM image file: %s\n", file);
        exit(EXIT_FAILURE);
    }

This will of course depend on having the samples loaded correctly on your machine, including appropriate files from the samples include directory, and having samples library functions available as well and properly linked. You can use the cuda sample projects, including their Makefiles, as a roadmap to manage all of this.

The CUDA samples also load other image formats in some cases, such as PPM, and perhaps others. If you use linux grep on the CUDA samples code directory, you can fairly quickly find out what methods/formats are provided and how to use those.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM