Crop and resize frame before inference

• Hardware Platform (Jetson / GPU) : NVIDIA Jetson AGX Orin
• DeepStream Version : 6.3
• JetPack Version (valid for Jetson only) : 5
• TensorRT Version : 8.5.2
• Issue Type( questions, new requirements, bugs) : questions

I want to create such a pipeline:

  • read h264 file
  • crop frame from 1920x1080 to 256:976 in x-axis and 600:1320 in y-axis
  • resize it to 224x224 frame
  • perform inference
  • draw result on display
  • save result to file

My question is: How can I crop frame before inference and then resize it to the desired scale? This is a fragment from my pipeline and I dont know where this preprcoessing step should be placed. Should I link nvvideoconvert before pgie and set crop values or should I create nvdspreprocess element? If so what are the parameters that I should set? I can see a deepstream-preprocess-test example with nvdspreprocess element but I am not sure where it sets the crop if it does at all.

...

# Create gstreamer elements
    # Create Pipeline element that will form a connection of other elements
    print("Creating Pipeline\n")
    pipeline = Gst.Pipeline()
    if not pipeline:
        sys.stderr.write("Unable to create Pipeline\n")

    # Source element for reading from the file
    print("Creating Source\n")
    source = Gst.ElementFactory.make("filesrc", "file-source")
    if not source:
        sys.stderr.write("Unable to create Source\n")

    # Data format in the input file is elementary h264 stream, we need a parser
    print("Creating parser\n")
    parser = Gst.ElementFactory.make("h264parse", "h264-parser")
    if not parser:
        sys.stderr.write("Unable to create parser\n")

    # Use nvdec_h264 for hardware accelerated decode on GPU
    print("Creating Decoder\n")
    decoder = Gst.ElementFactory.make("nvv4l2decoder", "nvv4l2-decoder")
    if not decoder:
        sys.stderr.write("Unable to create Nvv4l2 Decoder\n")

    # Create nvstreammux instance to form batches from one or more sources
    print("Creating Streammux\n")
    streammux = Gst.ElementFactory.make("nvstreammux", "Stream-muxer")
    if not streammux:
        sys.stderr.write("Unable to create NvStreamMux\n")

    # Use nvinfer to run inferencing on decoder's output, behaviour of inferencing is set through config file
    print("Creating Primary Inference\n")
    pgie = Gst.ElementFactory.make("nvinfer", "primary-inference")
    if not pgie:
        sys.stderr.write("Unable to create pgie\n")

    # Use converter to convert from NV12 to RGBA as required by nvosd
    print("Creatting nvvideoconvert\n")
    nvvidconv = Gst.ElementFactory.make("nvvideoconvert", "converter")
    if not nvvidconv:
        sys.stderr.write("Unable to create nvvidconv\n")

    # Create OSD to draw on the converted RGBA buffer
    print("Creating OSD\n")
    nvosd = Gst.ElementFactory.make("nvdsosd", "onscreendisplay")
    if not nvosd:
        sys.stderr.write("Unable to create nvosd\n")

...

You can try to use the nvvideoconvert plugin to crop the image, please refer to the src-crop parameter of nvvideoconvert. Then just set the infer-dims parameter in the config file of pgie to 3;244;244.

Could I achieve this also with nvdspreprocess? I am not sure what is the difference between those 2 plugins.

So to perfrom crop of the frame i just have to set src-crop to the desired values.

To resize the frame before inference to 3;224;224 I just have to set this in pgie config file? The proces of resizing a frame will done automatically and I do not have to add any plugin in my pipeline to resize the frame from 720x720 to 224x224? Or should I include some plugin after the crop and before the nvinfer to perform frame resize?

Yes, you can. You can get whatever data you want in preprocess, but you need to write code to implement that yourself.

Yes. Before the inference, nvinfer will scale the image according to your configuration.

Thank You. This answers my question

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.