How to Resize the OpenGL window from jetson.inference tutorials

How do I resize an openGL window using jetson.utils?

To be more specific, whenever I run any kind of a python program based off the inference tutorials, using:

display = jetson.utils.glDisplay()

while display.IsOpen():
    img, width, height = camera.CaptureRGBA()
    detections = net.Detect(img, width, height)
    display.RenderOnce(img, width, height)
    display.SetTitle("Object Detection | Network {:.0f} FPS".format(net.GetNetworkFPS()))

The window is the size of the display (fullscreen which is usually much bigger than the image size). The video is in the top left and the rest of the window fills with black. I would like to make the window the size of the video frame being shown. I’ll be doggone if I can find how to do that with jetson.utils.

I don’t need to scale anything or worry about fustrum, I just want to crop the window to the video size.

Do I need to do this with an openGL command like glViewport() ? If so, can you give me a hint where I should look to get started with that (I’m a Python guy, but very new to the whole working with images in VRAM thing).

The code is in

It is based on X Window and OpenGL. You may check and customize it into your usecase. Thanks.

Sorry, I have not implemented the function for that yet. Although I have recently made some updates to glDisplay in the jetson-utils master branch, I will add this to list of features to add. In the meantime, if you edit the code in glDisplay.cpp (around line 155), you can set your desired resolution:

// change screenWidth and screenHeight to your desired resolution
// const int screenWidth = DisplayWidth(mDisplayX, screenIdx);
// const int screenHeight = DisplayHeight(mDisplayX, screenIdx);
const int screenWidth = 1300;
const int screenHeight = 750;

You should probably make it a little bigger than your camera to allow for window border (above is example for 1280x720 camera)

Then, compile and install again before re-running the application:

$ cd jetson-inference/build
$ make
$ sudo make install

Thanks Dane and Dusty! Both answers are super helpful! Have a good one!

Hey @dusty_nv just wanted to ask you if it’s now possible to change the size of the screen opened directly through Python code or we still have to go to the C++ code and rebuild? Thanks!

Hi @paranyushkin, I believe the window should automatically resize to the size of the image, which you can change using the --input-width and --input-height arguments (see here for command-line details). Baring that, yes you can edit/recompile the C++ source.

EDIT: see this post for additional details.