In this notebook, we will create a box formed of four lines onto our image. The box is created by checking the pixel locations of each pixel on the screen. Each pixel has a location based upon an x-y coordination plane. Each pixel moving from left to right is one more in the x horizontal direction. Each pixel moving from top to bottom is one more in the y vertical direction. If a pixel location matches the location where we want to draw a line, then instead of drawing the actual pixel value, we replace it with a red, green, blue, or yellow color.
For example, let's draw a horizontal blue line that is 6 pixels wide starting at pixel y location 256. So our logic would say that for any pixel with its y value equal to 256, 257, 258, 259, 260, or 261, we are going to make the pixel blue. If we were to do this on the RGB color mixing image from the RGB_Filter, it would look like :
We could also draw a horizontal red line that is 6 pixels wide sarting at pixel x location 128. Our logic would say that for any pixel with its x value equal to 128, 129, 130, 131, 132, or 133, we are going to make the pixel red. If we were to do this on the RGB color mixing image from the RGB_Filter, it would look like :
This notebook will use a video filter that will draw four lines on the screen using the same general idea described above. These four lines will form a box ontop of the image.
In [ ]:
from pynq.drivers.video import HDMI
from pynq import Bitstream_Part
from pynq.board import Register
from pynq import Overlay
Overlay("demo.bit").download()
In [ ]:
hdmi_in = HDMI('in')
hdmi_out = HDMI('out', frame_list=hdmi_in.frame_list)
hdmi_out.mode(2)
hdmi_out.start()
hdmi_in.start()
In [ ]:
Bitstream_Part("lines_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()
R0=Register(0)
R1=Register(1)
R2=Register(2)
R3=Register(3)
R4=Register(4)
R0.write(200)
R1.write(1020)
R2.write(175)
R3.write(620)
R4.write(3)
R0_s = widgets.IntSlider(
value=200,
min=0,
max=1919,
step=1,
description='X1:',
disabled=False,
continuous_update=True,
orientation='vertical',
readout=True,
readout_format='i',
slider_color='red'
)
R1_s = widgets.IntSlider(
value=1020,
min=0,
max=1919,
step=1,
description='X2:',
disabled=False,
continuous_update=True,
orientation='vertical',
readout=True,
readout_format='i',
slider_color='green'
)
R2_s = widgets.IntSlider(
value=175,
min=0,
max=1079,
step=1,
description='Y1:',
disabled=False,
continuous_update=True,
orientation='vertical',
readout=True,
readout_format='i',
slider_color='blue'
)
R3_s = widgets.IntSlider(
value=620,
min=0,
max=1079,
step=1,
description='Y2:',
disabled=False,
continuous_update=True,
orientation='vertical',
readout=True,
readout_format='i',
slider_color='yellow'
)
R4_s = widgets.IntSlider(
value=3,
min=0,
max=500,
step=1,
description='Width:',
disabled=False,
continuous_update=True,
orientation='vertical',
readout=True,
readout_format='i',
slider_color='purple'
)
def update_r0(*args):
R0.write(R0_s.value)
R0_s.observe(update_r0, 'value')
def update_r1(*args):
R1.write(R1_s.value)
R1_s.observe(update_r1, 'value')
def update_r2(*args):
R2.write(R2_s.value)
R2_s.observe(update_r2, 'value')
def update_r3(*args):
R3.write(R3_s.value)
R3_s.observe(update_r3, 'value')
def update_r4(*args):
R4.write(R4_s.value)
R4_s.observe(update_r4, 'value')
items[0].on_click(on_hdmi_clicked)
widgets.HBox([VBox([items[0]]),R0_s,R1_s,R2_s,R3_s,R4_s])
In [ ]:
hdmi_out.stop()
hdmi_in.stop()
del hdmi_out
del hdmi_in