<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Snap
Step1:  Video
http
Step2:  GUI and BUTTONS
http
Step3:  Arrows
<ASSISTANT_TASK:>
Python Code:
# test image stack
arr = []
for i in range(50):
    b = np.random.rand(500,500)
    b= (b*(2**16-1)).astype('uint16')
    arr.append(b)
# snap (MPL)
button = widgets.Button(description='Snap')
display.display(button)
    
def on_button_clicked(b):
    img=arr.pop()
    plt.imshow(img, cmap='gray')
    display.clear_output(wait=True)
    display.display(plt.gcf())
    
button.on_click(on_button_clicked)
# snap (CV2)
button = widgets.Button(description='Snap')
display.display(button)
    
def on_button_clicked(b):
    img=arr.pop()
    cv2.imshow('Video',img)
    cv2.waitKey(30)
        
button.on_click(on_button_clicked)
Explanation: Snap
End of explanation
import numpy as np
import cv2
from IPython import display
# test image stack
a = []
for i in range(50):
    b = np.zeros((500,500))
    b[i:i+100, i:i+100]=1.0
    b=b*255
    b=b.astype('uint8')
    a.append(b)
# video (MPL) (slow, doesn't work well)
# for img in a:
#     plt.imshow(img, cmap='gray')
#     display.clear_output(wait=True)
#     display.display(plt.gcf())
# video (CV2)
cv2.namedWindow('Video',cv2.WINDOW_NORMAL)
for img in a:
    b = cv2.imshow('Video',img)
    cv2.resizeWindow('Video', 500,500)
    cv2.moveWindow('Video',0,0)
    display.clear_output(wait=True)
    print np.random.randn(1)
    if cv2.waitKey(30) >= 0:
        break
cv2.destroyAllWindows()
# video with button (CV2)
button = widgets.Button(description='Live')
display.display(button)
    
def on_button_clicked(b):
    for img in a:  
        cv2.imshow('Video',img)
        cv2.waitKey(30)
        display.clear_output(wait=True)
        print np.random.randn(1)
        
button.on_click(on_button_clicked)
Explanation: Video
http://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_gui/py_video_display/py_video_display.html
End of explanation
button = widgets.ToggleButton(description='Live', value=False)
def on_click(change):
    display.clear_output(wait=True)
    print change['new']
button.observe(on_click, names='value')
display.display(button)
import time
b1 = widgets.Button(description='b1')
b2 = widgets.Button(description='b2')
def ctrlloop():
    
    
def b1_click(b):
    for i in range(10):
        print 'b1', i
        time.sleep(0.5)
def b2_click(b):
    for i in range(10):
        print 'b2', i
        
# dl = widgets.jsdlink((button, 'value'), (vid, 'value'))
b1.on_click(b1_click)
b2.on_click(b2_click)
widgets.HBox([b1,b2])
play = widgets.Play(
    interval=160,
    value=50,
    min=0,
    max=100,
    step=1,
    description="Press play",
    disabled=False
)
slider = widgets.IntSlider()
widgets.jslink((play, 'value'), (slider, 'value'))
widgets.HBox([play, slider])
f = open('temp.msg','wb')
f.write(str(1))
f.close()
Explanation: GUI and BUTTONS
http://docs.opencv.org/2.4/modules/highgui/doc/user_interface.html
End of explanation
# icons are from "font-awesome"
x_minus = widgets.Button(
    description='',
    disabled=False,
    button_style='',
    icon = 'arrow-left')
x_plus = widgets.Button(
    description='',
    disabled=False,
    button_style='',
    icon = 'arrow-right')
y_minus = widgets.Button(
    description='',
    disabled=False,
    button_style='', 
    icon='arrow-up')
y_plus = widgets.Button(
    description='',
    disabled=False,
    button_style='',
    icon = 'arrow-down')
xy_slider = widgets.VBox([widgets.FloatText(description='speed', width='30%',value=50),widgets.IntSlider(width=100, step=10)])
xy_cluster = widgets.VBox([ widgets.HBox([x_minus,x_plus]), widgets.HBox([y_minus, y_plus]) ])
z_minus = widgets.Button(
    description='',
    disabled=False,
    button_style='',
    icon = 'arrow-up')
z_plus = widgets.Button(
    description='',
    disabled=False,
    button_style='',
    icon = 'arrow-down')
z_slider = widgets.VBox([widgets.FloatText(description='speed', width='30%',value=50),widgets.IntSlider(width=100, step=10)])
z_cluster = widgets.VBox([ z_minus, z_plus])
widgets.HBox([xy_cluster, xy_slider, z_cluster, z_slider])
Explanation: Arrows
End of explanation
<END_TASK>