0

Good afternoon. I found this article, but it shows how to take pixels from the image that is in the folder. Is it possible to take pixels straight from the desktop?

How to get image pixel value and image height and width in CUDA C?

Robert Crovella
  • 143,785
  • 11
  • 213
  • 257

1 Answers1

3

It's not possible to use CUDA to get pixels from the screen/desktop/application window. You would have to use some sort of graphics API, like some X extension or DirectX (or OpenGL if the window you are working on is under control of OpenGL).

Once you have acquired the pixels via your graphics API, you can pass that to CUDA using CUDA/Graphics interop.

There are many resources for screen capture. Here is one example. There are many others.

One possible suggestion is to use NVIDIA capture SDK. However this is not formally part of CUDA. It is one possible method to get the screen pixels into a resource accessible to CUDA. (And, the functionality is deprecated on Windows.)

Robert Crovella
  • 143,785
  • 11
  • 213
  • 257
  • How can I transfer an image straight to CUDA without saving it to the system. – asfasf asdgasg Oct 16 '20 at 18:16
  • 1
    If the image is in host memory, use `cudaMemcpy`. Study any CUDA sample code such as [vectorAdd](https://docs.nvidia.com/cuda/cuda-samples/index.html#vector-addition). If the image is in GPU memory already, but on the graphics side, use CUDA graphics interop. Study any CUDA graphics interop sample code such as [simpleTexture3D](https://docs.nvidia.com/cuda/cuda-samples/index.html#simple-texture-3d) – Robert Crovella Oct 16 '20 at 18:26
  • 2
    The first step in the capture process would be to get your displayed pixels into a resource like a texture. How to do that has nothing to do with CUDA, and if you have questions about that, please ask them on an appropriate SO tag. Once the image you want to send "straight to CUDA without saving it to the system" is in a graphics resource like a texture, then the CUDA graphics interop sample codes will show how to get it into a resource usable by CUDA kernels. – Robert Crovella Oct 16 '20 at 18:28