Display pipeline resolution

Hey, everybody!
When I use detection.py from hailo-rpi5-examples with a usb camera input I get a small window. I want to make the video to be full screen. I managed to modify DISPLAY_PIPELINE a little bit, but there are still unfilled spaces on the sides. How can I do this?
Here is just the modified code in hailo_rpi_common.py :

from screeninfo import get_monitors
...
def get_screen_resolution():
    monitor = get_monitors()[0]
    width = monitor.width
    height = monitor.height
    return width, height
....
def DISPLAY_PIPELINE(video_sink='xvimagesink', sync='true', show_fps='false', name='hailo_display'):
    """
    Creates a GStreamer pipeline string for displaying the video.
    It includes the hailooverlay plugin to draw bounding boxes and labels on the video.

    Args:
        video_sink (str, optional): The video sink element to use. Defaults to 'xvimagesink'.
        sync (str, optional): The sync property for the video sink. Defaults to 'true'.
        show_fps (str, optional): Whether to show the FPS on the video sink. Should be 'true' or 'false'. Defaults to 'false'.
        name (str, optional): The prefix name for the pipeline elements. Defaults to 'hailo_display'.

    Returns:
        str: A string representing the GStreamer pipeline for displaying the video.
    """
    screen_width, screen_height = get_screen_resolution()
    # Construct the display pipeline string
    display_pipeline = (
        f'{QUEUE(name=f"{name}_hailooverlay_q")} ! '
        f'hailooverlay name={name}_hailooverlay ! '
        f'{QUEUE(name=f"{name}_videoscale_q")} ! '
        f'videoscale ! '
        f'video/x-raw, width={screen_width}, height={screen_height} ! '
        f'{QUEUE(name=f"{name}_videoconvert_q")} ! '
        f'videoconvert name={name}_videoconvert n-threads=2 qos=false ! '
        f'{QUEUE(name=f"{name}_q")} ! '
        f'fpsdisplaysink name={name} video-sink={video_sink} sync={sync} text-overlay={show_fps} signal-fps-measurements=true '
    )

    return display_pipeline

And this is what the screen looks like after changes in the code

Hey @PVLGRPKN

Welcome to the Hailo Community!

Achieving Full-Screen Display with xvimagesink in GStreamer

To display video without unfilled spaces using xvimagesink in GStreamer, you need to match the video’s aspect ratio to your screen’s. Here are three approaches to handle aspect ratio mismatches:

1. Force Full Screen (Allow Distortion)

This approach scales the video to fit the screen exactly, potentially distorting the image:

def DISPLAY_PIPELINE(video_sink='xvimagesink', sync='true', show_fps='false', name='hailo_display'):
    screen_width, screen_height = get_screen_resolution()
    
    display_pipeline = (
        f'{QUEUE(name=f"{name}_hailooverlay_q")} ! '
        f'hailooverlay name={name}_hailooverlay ! '
        f'{QUEUE(name=f"{name}_videoscale_q")} ! '
        f'videoscale ! '
        f'video/x-raw, width={screen_width}, height={screen_height}, pixel-aspect-ratio=1/1 ! '
        f'{QUEUE(name=f"{name}_videoconvert_q")} ! '
        f'videoconvert name={name}_videoconvert n-threads=2 qos=false ! '
        f'{QUEUE(name=f"{name}_q")} ! '
        f'fpsdisplaysink name={name} video-sink={video_sink} sync={sync} text-overlay={show_fps} signal-fps-measurements=true '
    )
    
    return display_pipeline

2. Preserve Aspect Ratio and Crop

This method maintains the original aspect ratio but crops the video to fill the screen:

def DISPLAY_PIPELINE(video_sink='xvimagesink', sync='true', show_fps='false', name='hailo_display'):
    screen_width, screen_height = get_screen_resolution()
    
    display_pipeline = (
        f'{QUEUE(name=f"{name}_hailooverlay_q")} ! '
        f'hailooverlay name={name}_hailooverlay ! '
        f'{QUEUE(name=f"{name}_videoscale_q")} ! '
        f'videoscale ! '
        f'videocrop top=0 bottom=0 left=0 right=0 ! '
        f'video/x-raw, width={screen_width}, height={screen_height}, pixel-aspect-ratio=1/1 ! '
        f'{QUEUE(name=f"{name}_videoconvert_q")} ! '
        f'videoconvert name={name}_videoconvert n-threads=2 qos=false ! '
        f'{QUEUE(name=f"{name}_q")} ! '
        f'fpsdisplaysink name={name} video-sink={video_sink} sync={sync} text-overlay={show_fps} signal-fps-measurements=true '
    )
    
    return display_pipeline

3. Add Letterboxing

This approach maintains aspect ratio by adding black bars if necessary:

def DISPLAY_PIPELINE(video_sink='xvimagesink', sync='true', show_fps='false', name='hailo_display'):
    screen_width, screen_height = get_screen_resolution()
    
    display_pipeline = (
        f'{QUEUE(name=f"{name}_hailooverlay_q")} ! '
        f'hailooverlay name={name}_hailooverlay ! '
        f'{QUEUE(name=f"{name}_videoscale_q")} ! '
        f'videoscale ! '
        f'video/x-raw, width={screen_width}, height={screen_height}, maintain-aspect-ratio=true ! '
        f'{QUEUE(name=f"{name}_videoconvert_q")} ! '
        f'videoconvert name={name}_videoconvert n-threads=2 qos=false ! '
        f'{QUEUE(name=f"{name}_q")} ! '
        f'fpsdisplaysink name={name} video-sink={video_sink} sync={sync} text-overlay={show_fps} signal-fps-measurements=true '
    )
    
    return display_pipeline

Choose the approach that best suits your needs:

  1. Full screen with potential distortion
  2. Full screen with cropping
  3. Letterboxing to maintain aspect ratio without cropping

Implement the chosen method in your GStreamer pipeline to achieve the desired full-screen display.

Best Regards,
Omri

1 Like

Hi, Omria! This is what I got using your solutions
1.Using the code from the first solution I still have black blocks not filled from the edges


2. Using the code from the second one, the situation is exactly the same as on the first one

3. In the third case, the unfilled black blocks went away and just left the desktop

I tried playing around with xvimagesink but so far unfortunately no results =(

Hey @PVLGRPKN

Thanks for the detailed feedback! It looks like the solutions provided earlier didn’t fully solve the issue. Let’s try a few refined approaches to ensure the video properly fills the screen.

  1. First, let’s try modifying your xvimagesink settings. Add the fullscreen parameter to your pipeline:
fpsdisplaysink name=hailo_display video-sink=xvimagesink fullscreen=true sync=true

If you’re still seeing black bars, we can try a few more approaches:

  1. We can use wmctrl to force fullscreen mode:
sudo apt-get install wmctrl

Then use this Python code to automate fullscreen:

import subprocess
def set_fullscreen():
    window_id = subprocess.check_output(
        "xwininfo | grep 'Window id' | awk '{print $4}'", shell=True).decode().strip()
    subprocess.run(f"wmctrl -i -r {window_id} -b add,fullscreen", shell=True)
  1. Another option is switching to glimagesink, which often handles scaling better:
fpsdisplaysink name=hailo_display video-sink=glimagesink sync=true
  1. To ensure your Pi’s screen resolution matches the video output:
sudo fbset -xres 1920 -yres 1080
  1. If none of the above fully resolves the issue, we can try using videomixer to force scaling:
videomixer name=mixer sink_0::xpos=0 sink_0::ypos=0 sink_0::width=1920 sink_0::height=1080 ! xvimagesink

Please try these solutions in order and let me know if you’re still experiencing any issues. I’m here to help fine-tune the approach if needed!"