What is the easiest way to crop an image on the GPU?

Is there any example code out there for cropping a float4 RGBA image that’s already on the GPU?

I want to feed forward a TensorRT neural network and the inputs require cropped parts of an image that has already been loaded into the GPU.

I might add I’m actually using the Jetson TX2 and a modified jetson-inference example in c++.

Hi stangogh, here’s a simple example CUDA kernel of cropping image: [url]https://github.com/dusty-nv/jetson-video/blob/master/cuda/cudaCrop.cu[/url]

NPP (NVIDIA Performance Primitives) library should also have a function for cropping available.

Thank you dusty_nv! Your jetson-inference github repo is amazing and has been super instrumental in getting my project off the ground and running :)

Hi dusty_nv!
I currently consider myself a beginner, so my question may be a bit off:
Does your kernel run entirely on GPU?
I am trying to do the cropping without having to load the entire frame into the CPU buffer. In other words, I would like to use the detection metas (from the previous nvinfer element) and crop the images right in the GPU. Later, I would like to extract only the cropped patches. Does your kernel satisfy this need? Can I use it in my custom plugin, to avoid loading the entire frame into the CPU?

Hi @Mohammad_Amin_Parchami, yes these CUDA functions are entirely on the GPU.

There is also a Python version now, see here: https://github.com/dusty-nv/jetson-inference/blob/master/docs/aux-image.md#cropping

1 Like

Great! I was exactly searching online on how to use your kernel in Python! You’re a lifesaver!

Thank you for your help.