Don't forget to delete the hdmi_out and hdmi_in when finished

Box Blur Filter Example

In this notebook, we will demonstrate how to use the box blur filter. We take advantage of the Pynq’s ability to buffer HDMI signals in order to perform a filter. The box blur filter is relatively simple. As shown in the image below, the value of each pixel outputted is the average of the pixel in the center and the surrounding pixels.

This diagram shows how the blur algorithm functions.

In order to perform this function, we need access to three rows worth of pixel data. We achieve this by stalling the HDMI signal for two rows while buffering the RGB values of the pixels. Once all the need RGB values are buffered the algorithm is performed and the HDMI output signals are sent.

1. Download base overlay to the board

Ensure that the camera is not connected to the board. Run the following script to provide the PYNQ with its base overlay.


In [1]:
from pynq.drivers.video import HDMI
from pynq import Bitstream_Part
from pynq.board import Register
from pynq import Overlay

Overlay("demo.bit").download()

2. Connect camera

Physically connect the camera to the HDMI-in port of the PYNQ. Run the following code to instruct the PYNQ to capture the video from the camera and to begin streaming video to your monitor (connected to the HDMI-out port).


In [2]:
hdmi_in = HDMI('in')
hdmi_out = HDMI('out', frame_list=hdmi_in.frame_list)
hdmi_out.mode(3)
hdmi_out.start()
hdmi_in.start()

3. Program board

Run the following script to download the Box Blur Filter to the PYNQ. This applies the bluring filter to the video stream.


In [3]:
Bitstream_Part("box_blur_p.bit").download()

In [ ]:
import ipywidgets as widgets
from ipywidgets import Button, HBox, VBox, Label

words = ['HDMI Reset']
items = [Button(description=w) for w in words]


def on_hdmi_clicked(b):
    hdmi_out.stop()
    hdmi_in.stop()
    hdmi_out.start()
    hdmi_in.start()

items[0].on_click(on_hdmi_clicked)

widgets.VBox([items[0]])

4. User interface

Do to the simplicity of this filter there is no need for a user interface.

5. Exploration

Due to the small size of the blur matrix and the high resolution of the image, the filter does not have a large effect on the image. It acts as a proof of concept that filtering can be done on the pynq.

6. Clean up

When you are done playing with the box blur filter, run the following code to stop the video stream


In [5]:
hdmi_out.stop()
hdmi_in.stop()
del hdmi_out
del hdmi_in