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

Overlay("full.bit").download()

In [2]:
hdmi_in = HDMI('in')
hdmi_out = HDMI('out', frame_list=hdmi_in.frame_list)
hdmi_out.mode(4)#2 is for camera
hdmi_out.start()
hdmi_in.start()

#Valid resolutions are:
#
# 0 : '640x480@60Hz' 
# 1 : '800x600@60Hz' 
# 2 : '1280x720@60Hz' 
# 3 : '1280x1024@60Hz' 
# 4 : '1920x1080@60Hz'

In [3]:
R0 =Register(0)
R1 =Register(1)
R2 =Register(2)
R3 =Register(3)
R4 =Register(4)
import ipywidgets as widgets


R0_s = widgets.IntSlider(
    value=255,
    min=0,
    max=255,
    step=1,
    description='R0:',
    disabled=False,
    continuous_update=True,
    orientation='vertical',
    readout=True,
    readout_format='i',
    slider_color='red'
)
R1_s = widgets.IntSlider(
    value=255,
    min=0,
    max=255,
    step=1,
    description='R1:',
    disabled=False,
    continuous_update=True,
    orientation='vertical',
    readout=True,
    readout_format='i',
    slider_color='green'
)
R2_s = widgets.IntSlider(
    value=255,
    min=0,
    max=255,
    step=1,
    description='R2:',
    disabled=False,
    continuous_update=True,
    orientation='vertical',
    readout=True,
    readout_format='i',
    slider_color='blue'
)
R3_s = widgets.IntSlider(
    value=255,
    min=0,
    max=255,
    step=1,
    description='R3:',
    disabled=False,
    continuous_update=True,
    orientation='vertical',
    readout=True,
    readout_format='i',
    slider_color='yellow'
)
R4_s = widgets.IntSlider(
    value=255,
    min=0,
    max=1920,
    step=1,
    description='R4:',
    disabled=False,
    continuous_update=True,
    orientation='vertical',
    readout=True,
    readout_format='i',
    slider_color='purple'
)
R0_s.width = '80px'
R1_s.width = '80px'
R2_s.width = '80px'
R3_s.width = '80px'
R4_s.width = '80px'
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')

In [4]:
from IPython.display import clear_output
from ipywidgets import Button, HBox, VBox, Label

words = ['HDMI Reset','Pass', 'RGB','Box', 'Invert', 'Gscale','Mirror','Sobel','Blur']
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()
def on_pass_clicked(b):
    Bitstream_Part("pass_k.bit").download()
    R0_s.disabled = True
    R0_s.description='N/A'
    R1_s.disabled = True
    R1_s.description='N/A'
    R2_s.disabled = True
    R2_s.description='N/A'
    R3_s.disabled = True
    R3_s.description='N/A'
    R4_s.disabled = True
    R4_s.description='N/A'
def on_rgb_clicked(b):
    Bitstream_Part("rgb_k.bit").download()
    R0.write(255)
    R1.write(255)
    R2.write(255)
    R0_s.disabled = False
    R0_s.value = 255
    R0_s.max = 255
    R0_s.description='Red:'
    R1_s.disabled = False
    R1_s.value = 255
    R1_s.max = 255
    R1_s.description='Green:'
    R2_s.disabled = False
    R2_s.value = 255
    R2_s.max = 255
    R2_s.description='Blue:'
    R3_s.disabled = True
    R3_s.description='N/A'
    R4_s.disabled = True
    R4_s.description='N/A'
def on_box_clicked(b):
    Bitstream_Part("box_k.bit").download()
    R0.write(200)
    R1.write(1020)
    R2.write(175)
    R3.write(620)
    R4.write(3)
    R0_s.disabled = False
    R0_s.max = 1919
    R0_s.value = 200
    R0_s.description='X1:'
    R1_s.disabled = False
    R1_s.max = 1919
    R1_s.value = 1020
    R1_s.description='X2:'
    R2_s.disabled = False
    R2_s.max = 1079
    R2_s.value = 175
    R2_s.description='Y1:'
    R3_s.disabled = False
    R3_s.max = 1079
    R3_s.value = 620
    R3_s.description='Y2:'
    R4_s.disabled = False
    R4_s.max = 500
    R4_s.value = 3
    R4_s.description='Width:'
def on_Invert_clicked(b):
    Bitstream_Part("invert_k.bit").download()
    R0_s.disabled = True
    R0_s.description='N/A'
    R1_s.disabled = True
    R1_s.description='N/A'
    R2_s.disabled = True
    R2_s.description='N/A'
    R3_s.disabled = True
    R3_s.description='N/A'
    R4_s.disabled = True
    R4_s.description='N/A'
def on_Gscale_clicked(b):
    Bitstream_Part("gscale_k.bit").download()
    R0_s.disabled = True
    R0_s.description='N/A'
    R1_s.disabled = True
    R1_s.description='N/A'
    R2_s.disabled = True
    R2_s.description='N/A'
    R3_s.disabled = True
    R3_s.description='N/A'
    R4_s.disabled = True
    R4_s.description='N/A'
def on_Mirror_clicked(b):
    Bitstream_Part("mirror_k.bit").download()
    R0_s.disabled = True
    R0_s.description='N/A'
    R1_s.disabled = True
    R1_s.description='N/A'
    R2_s.disabled = True
    R2_s.description='N/A'
    R3_s.disabled = True
    R3_s.description='N/A'
    R4_s.disabled = True
    R4_s.description='N/A'
def on_Sobel_clicked(b):
    Bitstream_Part("sobel_k.bit").download()
    R0.write(128)
    R1.write(1)
    R2.write(1)
    R0_s.disabled = False
    R0_s.max = 255
    R0_s.value = 128
    R0_s.description='Threshold:'
    R1_s.disabled = False
    R1_s.max = 15
    R1_s.value = 1
    R1_s.description='Sensitivity:'
    R2_s.disabled = False
    R2_s.max = 1
    R2_s.value = 1
    R2_s.description='inverted:'
    R3_s.disabled = True
    R3_s.description='N/A'
    R4_s.disabled = True
    R4_s.description='N/A'
def on_Blur_clicked(b):
    Bitstream_Part("blur_k.bit").download()
    R0_s.disabled = True
    R0_s.description='N/A'
    R1_s.disabled = True
    R1_s.description='N/A'
    R2_s.disabled = True
    R2_s.description='N/A'
    R3_s.disabled = True
    R3_s.description='N/A'
    R4_s.disabled = True
    R4_s.description='N/A'

    
items[0].on_click(on_hdmi_clicked)
items[1].on_click(on_pass_clicked)
items[2].on_click(on_rgb_clicked)
items[3].on_click(on_box_clicked)
items[4].on_click(on_Invert_clicked)
items[5].on_click(on_Gscale_clicked)
items[6].on_click(on_Mirror_clicked)
items[7].on_click(on_Sobel_clicked)
items[8].on_click(on_Blur_clicked)

In [5]:
GUI =HBox([VBox([items[0], items[1],items[2], items[3],items[4],items[5],items[6],items[7],items[8]]),R0_s,R1_s,R2_s,R3_s,R4_s])
GUI.layout.justify_content = 'center'
GUI


Widget Javascript not detected.  It may not be installed properly. Did you enable the widgetsnbextension? If not, then run "jupyter nbextension enable --py --sys-prefix widgetsnbextension"

In [6]:
from IPython.display import HTML
HTML('''<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 } else {
 $('div.input').show();
 }
 code_show = !code_show
} 
$( document ).ready(code_toggle);
</script>
The raw code for this IPython notebook is by default hidden for easier reading.
To toggle on/off the raw code, click <a href="javascript:code_toggle()">here</a>.''')


Out[6]:
The raw code for this IPython notebook is by default hidden for easier reading. To toggle on/off the raw code, click here.

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