Nvinfer maintain-aspect-ratio padding color

Hello all,

I am testing nvinfer with a custom model, for this model I need to change the padding color used in nvinfer. By default nvinfer uses a black padding but I would like to use a gray scale padding instead.

I found this code inside gstnvinfer.cpp:

     /* Pad the scaled image with black color. */
    cudaReturn =
        cudaMemset2DAsync ((uint8_t *) destCudaPtr + pixel_size * dest_width,
        dest_frame->planeParams.pitch[0], 0,
        pixel_size * (dest_frame->width - dest_width), dest_frame->height,
        nvinfer->convertStream);
    if (cudaReturn != cudaSuccess) {
      GST_ERROR_OBJECT (nvinfer,
          "cudaMemset2DAsync failed with error %s while converting buffer",
          cudaGetErrorName (cudaReturn));
      return GST_FLOW_ERROR;
    }
    cudaReturn =
        cudaMemset2DAsync ((uint8_t *) destCudaPtr +
        dest_frame->planeParams.pitch[0] * dest_height,
        dest_frame->planeParams.pitch[0], 0, pixel_size * dest_width,
        dest_frame->height - dest_height, nvinfer->convertStream);
    if (cudaReturn != cudaSuccess) {
      GST_ERROR_OBJECT (nvinfer,
          "cudaMemset2DAsync failed with error %s while converting buffer",
          cudaGetErrorName (cudaReturn));
      return GST_FLOW_ERROR;
    }

First, the color choice for the padding will be an option in a future release of Deepstream?

Second, if I want to use a gray scale padding should I change the 0 by another value, recompile and installed it right? In this case what is the scale of pixels (0 to 255) ?

Finally there is a way to visualize/save this padded image ?

We will take a look at this request.

Thank you for your answer. Could please you confirm if to apply a grayscale to the padding the scale is between 0 and 255 ?

No. This request can be satisfied with a little change to the code. The code is open source.

Yes. The way is correct.

There is no way to dump the padded image directly, but there is a way to dump the image input to model. DeepStream SDK FAQ - Intelligent Video Analytics / DeepStream SDK - NVIDIA Developer Forums

1 Like