#print(run_prediction(jpg_path2array("jpg_path"))) import cv2 import ipywidgets from IPython.display import display as ipydisplay image_widget = ipywidgets.Image( format='jpg', width=300, height=400, ) prediction_text_widget = ipywidgets.Text(description='Prediction') ipydisplay(image_widget) ipydisplay(prediction_text_widget) prediction_text_widget.value = "3" # cap = cv2.VideoCapture('http://172.16.11.10:8080/stream.mjpeg') # cap = cv2.VideoCapture('http://172.16.11.10:8080/video') cap = cv2.VideoCapture('http://172.16.11.10:4747/video') cap.set(cv2.CAP_PROP_FPS, 10) count_frame = 0 while True: ret, frame = cap.read() count_frame = count_frame + 1 cap.set(cv2.CAP_PROP_FPS, 30) fps = cap.get(cv2.CAP_PROP_FPS) # cv2.imshow('Video', frame) # JPEG
def display_image(img, scale=1.0): ipydisplay( cv2_to_display( cv2.resize(img, (0, 0), fx=scale, fy=scale, interpolation=cv2.INTER_NEAREST)))
def display(self, msg): cond = ("module" in msg and "attr" in msg and "args" in msg) if cond: try: # ModuleNotFoundError mod = importlib.import_module(msg["module"]) args = msg["args"] if "decode_bytes" in msg: for key in msg["decode_bytes"]: args[key] = base64.decodebytes( args[key].encode("ascii")) # AttributeError cb = getattr(mod, msg["attr"]) if isinstance(args, list): obj = cb(*args) elif isinstance(args, dict): obj = cb(**args) else: self.stderr("display warning: 'args' is not list or dict") return ipydisplay(obj) except Exception as e: self.stderr("display error: %s" % e) else: self.stderr( "display error: message must contain 'module', 'attr', and 'args'" )
def d3_output(response, visid, width, height): results = json.loads(response) d3js = results["js"] d3css = results["css"] controls = results["controls"] html = D3_TEMPLATE_HTML.render({ 'jsloc': brunel_util.JS_LOC, 'd3css': d3css, 'visId': visid, 'width': width, 'height': height }) # side effect pushes required D3 HTML to the client ipydisplay(HTML(html)) widgets = brunelWidgets.build_widgets(controls, visid) if (widgets is not None): # Push widgets & D3 JS js = D3_TEMPLATE.render({ 'jsloc': brunel_util.JS_LOC, 'd3loc': brunel_util.D3_LOC, 'd3js': d3js, 'controls': widgets['wire_code'] }) return ipydisplay(widgets['widget_box'], Javascript(js)) else: js = D3_TEMPLATE.render({ 'jsloc': brunel_util.JS_LOC, 'd3loc': brunel_util.D3_LOC, 'd3js': d3js, 'controls': "" }) return Javascript(js)
def download(self, *_): with contextlib.suppress(Exception): with self._download_output: data = getattr(self, self._download_data_name) js_download = nu.create_js_download(data, index=True) if js_download is not None: ipydisplay(js_download)
def d3_output(response, visid, width, height): results = json.loads(response) d3js = results["js"] d3css = results["css"] controls = results["controls"] html = D3_TEMPLATE_HTML.render( {"jsloc": brunel_util.JS_LOC, "d3css": d3css, "visId": visid, "width": width, "height": height} ) # side effect pushes required D3 HTML to the client ipydisplay(HTML(html)) widgets = brunelWidgets.build_widgets(controls, visid) if widgets is not None: # Push widgets & D3 JS js = D3_TEMPLATE.render( { "jsloc": brunel_util.JS_LOC, "d3loc": brunel_util.D3_LOC, "topojsonloc": brunel_util.TOPO_JSON_LOC, "d3js": d3js, } ) return ipydisplay(widgets["widget_box"], Javascript(js)) else: js = D3_TEMPLATE.render( { "jsloc": brunel_util.JS_LOC, "d3loc": brunel_util.D3_LOC, "topojsonloc": brunel_util.TOPO_JSON_LOC, "d3js": d3js, } ) return Javascript(js)
def d3_output(response, visid, controlsid, width, height, online_js): results = json.loads(response) d3js = results["js"] d3css = results["css"] jsloc = brunel_util.JS_LOC #Forces online loading of JS from brunelvis. if online_js: jsloc = "https://brunelvis.org/js" html = D3_TEMPLATE_HTML.render({ 'jsloc': jsloc, 'd3css': d3css, 'visId': visid, 'width': width, 'height': height, 'controlsid': controlsid, 'version': brunel_version }) # side effect pushes required D3 HTML to the client ipydisplay(HTML(html)) js = D3_TEMPLATE.render({ 'jsloc': jsloc, 'd3loc': brunel_util.D3_LOC, 'topojsonloc': brunel_util.TOPO_JSON_LOC, 'd3js': d3js, 'version': brunel_version }) return Javascript(js)
def make_clear_all_objects_button(): if not HAS_WIDGETS: return def on_clear_click(b): remove_all_objects(sim) clear_objs_button = set_button_launcher("Clear all objects") clear_objs_button.on_click(on_clear_click) ipydisplay(clear_objs_button)
def d3_output(response, visid, controlsid, width, height): results = json.loads(response) d3js = results["js"] d3css = results["css"] controls = results["controls"] html = D3_TEMPLATE_HTML.render({'jsloc': brunel_util.JS_LOC, 'd3css': d3css, 'visId': visid, 'width': width, 'height': height, 'controlsid': controlsid}) # side effect pushes required D3 HTML to the client ipydisplay(HTML(html)) js = D3_TEMPLATE.render({'jsloc': brunel_util.JS_LOC, 'd3loc': brunel_util.D3_LOC, 'topojsonloc':brunel_util.TOPO_JSON_LOC, 'd3js': d3js}) return Javascript(js)
def connect_magic(self, args): if self.client is not None: print("already connected to backend") return w = self.pick_backend() if w is None: self.stdout("no backends available") else: ipydisplay(w)
def display_html(df): """ Display method capable of displaying the dataframe in a formatted HTML structured output """ ipydisplay(HTML("<style>pre { white-space: pre !important; }</style>")) if isinstance(df, DataFrame): df.show(truncate=False, vertical=False) elif isinstance(df, pandasDataFrame): df.head() else: logger.error("'display' method not available for this object")
def make_sim_and_vid_button(prefix, dt=1.0): if not HAS_WIDGETS: return def on_sim_click(b): observations = simulate(sim, dt=dt) vut.make_video(observations, "color_sensor_1st_person", "color", output_path + prefix) sim_and_vid_btn = set_button_launcher("Simulate and Make Video") sim_and_vid_btn.on_click(on_sim_click) ipydisplay(sim_and_vid_btn)
def connect_magic(self, args): if self.client is not None: self.client.check_connection() if self.client is not None: print("already connected to backend") return else: print("disconnected, select a new connection") w = self.pick_backend() if w is None: self.stdout("no backends available") else: ipydisplay(w)
def d3_output(response, visid, width, height): results = json.loads(response) d3js = results["js"] d3css = results["css"] controls = results["controls"] html = D3_TEMPLATE_HTML.render({'jsloc': brunel_util.JS_LOC, 'd3css': d3css, 'visId': visid, 'width': width, 'height': height}) # side effect pushes required D3 HTML to the client ipydisplay(HTML(html)) widgets = brunelWidgets.build_widgets(controls, visid) if (widgets is not None): # Push widgets & D3 JS js = D3_TEMPLATE.render({'jsloc': brunel_util.JS_LOC, 'd3loc': brunel_util.D3_LOC, 'd3js': d3js, 'controls': widgets['wire_code']}) return ipydisplay(widgets['widget_box'], Javascript(js)) else: js = D3_TEMPLATE.render({'jsloc': brunel_util.JS_LOC, 'd3loc': brunel_util.D3_LOC, 'd3js': d3js, 'controls': ""}) return Javascript(js)
def d3_output(response, visid, width, height): results = json.loads(response.read().decode("utf-8")) d3js = results["js"] d3css = results["css"] controls = results["controls"] html = D3_TEMPLATE_HTML.render({"d3css": d3css, "visId": visid, "width": width, "height": height}) # side effect pushes required D3 HTML to the client ipydisplay(HTML(html)) widgets = brunelWidgets.build_widgets(controls, visid) if widgets is not None: # Push widgets & D3 JS js = D3_TEMPLATE.render({"d3js": d3js, "controls": widgets["wire_code"]}) return ipydisplay(widgets["widget_box"], Javascript(js)) else: js = D3_TEMPLATE.render({"d3js": d3js, "controls": ""}) return Javascript(js)
def __init__(self, drawable_mesh): self.drawable = drawable_mesh self.mesh = drawable_mesh.geometry self.mesh.attach(self) self.widgets = [] self.click_picker = self.__initialize_picker() self.old_picked_face = None self.old_picked_face_internal = False self.__clipping_in_queue = False self.__dont_update_clipping = False self.__create_UI() #self.wireframe_thickness_slider.observe(self.__update_wireframe_thickness, names='value') for widget in self.widgets: ipydisplay(widget)
def d3_output(response, visid, controlsid, width, height, online_js): results = json.loads(response) d3js = results["js"] d3css = results["css"] jsloc = brunel_util.JS_LOC #Forces online loading of JS from brunelvis. if online_js: jsloc = "https://brunelvis.org/js" html = D3_TEMPLATE_HTML.render({'jsloc': jsloc, 'd3css': d3css, 'visId': visid, 'width': width, 'height': height, 'controlsid': controlsid, 'version': brunel_version}) # side effect pushes required D3 HTML to the client ipydisplay(HTML(html)) js = D3_TEMPLATE.render({'jsloc': jsloc, 'd3loc': brunel_util.D3_LOC, 'topojsonloc':brunel_util.TOPO_JSON_LOC, 'd3js': d3js, 'version': brunel_version}) return Javascript(js)
def build_widget_ui(metadata_mediator): # Holds the user's desired scene global selected_scene selected_scene = "NONE" # Construct DDLs and assign event handlers # All file-based object template handles scene_handles = metadata_mediator.get_scene_handles() # If not using widgets, set as first available handle if not HAS_WIDGETS: selected_scene = scene_handles[0] return # Build widgets scene_obj_ddl, selected_scene = set_handle_ddl_widget( scene_handles, selected_scene, on_scene_ddl_change, ) # Display DDLs ipydisplay(scene_obj_ddl)
def __init__(self, drawable_objects): self.__prev_geom = 0 self.__drawables = drawable_objects self.drawable = drawable_objects[0] self.mesh = self.drawable.geometry self.mesh.attach(self) self.widgets = [] self.click_picker = self.__initialize_picker(self.drawable.mesh) self.old_picked_face = None self.old_picked_face_internal = False self.__clipping_in_queue = False self.__dont_update_clipping = False self.thread_list = [] self.__create_UI() #self.wireframe_thickness_slider.observe(self.__update_wireframe_thickness, names='value') self.__values = {} for idx in range(len(self.__drawables)): if not ("Skeleton" in str(type(self.__drawables[idx])) or "PointCloud" in str(type(self.__drawables[idx]))): self.__set_values(idx, True) for widget in self.widgets: ipydisplay(widget)
def build_widget_ui(obj_attr_mgr, prim_attr_mgr): # Holds the user's desired file-based object template handle global sel_file_obj_handle sel_file_obj_handle = "" # Holds the user's desired primitive-based object template handle global sel_prim_obj_handle sel_prim_obj_handle = "" # Holds the user's desired primitive asset template handle global sel_asset_handle sel_asset_handle = "" # Construct DDLs and assign event handlers # All file-based object template handles file_obj_handles = obj_attr_mgr.get_file_template_handles() # All primitive asset-based object template handles prim_obj_handles = obj_attr_mgr.get_synth_template_handles() # All primitive asset handles template handles prim_asset_handles = prim_attr_mgr.get_template_handles() # If not using widgets, set as first available handle if not HAS_WIDGETS: sel_file_obj_handle = file_obj_handles[0] sel_prim_obj_handle = prim_obj_handles[0] sel_prim_obj_handle = prim_asset_handles[0] return # Build widgets file_obj_ddl, sel_file_obj_handle = set_handle_ddl_widget( file_obj_handles, "File-based Object", sel_file_obj_handle, on_file_obj_ddl_change, ) prim_obj_ddl, sel_prim_obj_handle = set_handle_ddl_widget( prim_obj_handles, "Primitive-based Object", sel_prim_obj_handle, on_prim_obj_ddl_change, ) prim_asset_ddl, sel_asset_handle = set_handle_ddl_widget( prim_asset_handles, "Primitive Asset", sel_asset_handle, on_prim_ddl_change) # Display DDLs ipydisplay(file_obj_ddl) ipydisplay(prim_obj_ddl) ipydisplay(prim_asset_ddl)
def __init__(self, drawable_mesh): self.drawable = drawable_mesh self.mesh = drawable_mesh.geometry self.mesh.attach(self) self.widgets = [] self.click_picker = self.__initialize_picker() self.old_picked_face = None self.old_picked_face_internal = False self.__clipping_in_queue = False self.__dont_update_clipping = False self.invisible_layout = {'display': 'none'} self.visible_layout = {'display': ''} self.flip_button_layout = { 'width': 'auto', 'margin': '0px 0px 0px 10px' } self.slider_layout = {} self.flip_x_button = widgets.ToggleButton( value=False, description='Flip x', disabled=False, button_style='info', tooltip='Flip the visualization range on x axis', layout=self.flip_button_layout) self.flip_y_button = widgets.ToggleButton( value=False, description='Flip y', disabled=False, button_style='info', # 'success', 'info', 'warning', 'danger' or '' tooltip='IFlip the visualization range on y axis', layout=self.flip_button_layout) self.flip_z_button = widgets.ToggleButton( value=False, description='Flip z', disabled=False, button_style='info', # 'success', 'info', 'warning', 'danger' or '' tooltip='Flip the visualization range on z axis', layout=self.flip_button_layout) x_range = self.mesh.bbox[0][0], self.mesh.bbox[1][0] x_step = abs(x_range[0] - x_range[1]) / 100 self.clipping_slider_x = widgets.FloatRangeSlider( value=x_range, min=x_range[0] - x_step, max=x_range[1] + x_step, step=x_step, description='X Clipping:', disabled=False, continuous_update=True, orientation='horizontal', readout=True, readout_format=".1f", layout=self.slider_layout) y_range = self.mesh.bbox[0][1], self.mesh.bbox[1][1] y_step = abs(y_range[0] - y_range[1]) / 100 self.clipping_slider_y = widgets.FloatRangeSlider( value=y_range, min=y_range[0] - y_step, max=y_range[1] + y_step, step=y_step, description='Y Clipping:', disabled=False, continuous_update=True, orientation='horizontal', readout=True, readout_format=".1f", layout=self.slider_layout) z_range = self.mesh.bbox[0][2], self.mesh.bbox[1][2] z_step = abs(z_range[0] - z_range[1]) / 100 self.clipping_slider_z = widgets.FloatRangeSlider( value=z_range, min=z_range[0] - z_step, max=z_range[1] + z_step, step=z_step, description='Z Clipping:', disabled=False, continuous_update=True, orientation='horizontal', readout=True, readout_format=".1f", layout=self.slider_layout) self.wireframe_opacity_slider = widgets.FloatSlider( value=0.4, min=0., max=1., step=0.1, continuous_update=True, readout_format=".1f", description='Wireframe', disable=False, ) self.color_wireframe = widgets.ColorPicker( concise=True, value=self.drawable.wireframe.material.color, disabled=False, layout={'margin': '0 0 0 10px'}) self.widgets += [ widgets.HBox([self.clipping_slider_x, self.flip_x_button]), widgets.HBox([self.clipping_slider_y, self.flip_y_button]), widgets.HBox([self.clipping_slider_z, self.flip_z_button]), widgets.HBox([self.wireframe_opacity_slider, self.color_wireframe]), ] self.picking_title = widgets.Label(value="Click informations:", layout={'margin': '0 0 0 20px'}, disabled=False, continuous_update=True) self.picking_label = widgets.Label(layout={'margin': '0 0 0 20px'}, disabled=False, continuous_update=True) tab_titles = ['Face', 'Vertex'] children = [ widgets.HTML(value="", layout={'margin': '0 0 0 10px'}, disabled=False, continuous_update=True) for title in tab_titles ] self.picking_tab = widgets.Tab(layout={'margin': '0 0 0 20px'}, disabled=True, width=300, height=400) self.picking_tab.children = children for i in range(len(children)): self.picking_tab.set_title(i, tab_titles[i]) self.color_picking_label = widgets.Label( value="Click Color ", layout={'margin': '0 0 0 20px'}, disabled=False, continuous_update=True) self.widgets += [ widgets.HBox([self.picking_title]), widgets.HBox([self.picking_label]), widgets.HBox([self.picking_tab]) ] self.color_map = widgets.Dropdown( options=[(i, idx) for idx, i in enumerate(ColorMap.color_maps.keys())], value=0, description='Color-Map:', layout=self.invisible_layout, ) self.widgets += [self.color_map] self.metric_menu = widgets.Dropdown( options=[(i, idx) for idx, i in enumerate(self.mesh.simplex_metrics.keys()) ], value=0, description='Metric:', layout=self.invisible_layout, ) self.widgets += [self.metric_menu] self.coloring_type_menu = widgets.Dropdown( options=[('Default', 0), ('Simplex Quality', 1), ('Label', 2)], value=0, description='Color Type:', ) self.widgets += [self.coloring_type_menu] mesh_colors = [] if hasattr(self.mesh, "internals"): self.color_internal = widgets.ColorPicker( concise=True, description='Internal', value=colors.rgb2hex(self.drawable._internal_color), disabled=False, ) mesh_colors += [self.color_internal] self.color_picking = widgets.ColorPicker( concise=True, description="Click Color", value=colors.rgb2hex(colors.purple), disabled=False, ) self.color_external = widgets.ColorPicker( concise=True, description='External', value=colors.rgb2hex(self.drawable._external_color), disabled=False, ) mesh_colors += [self.color_external] mesh_colors += [self.color_picking] self.widgets += [widgets.HBox(mesh_colors)] self.color_label_pickers = [ widgets.ColorPicker( concise=True, description='Label ' + str(i), value=colors.random_color(return_hex=True), disabled=False, layout=self.visible_layout, ) for i in np.unique(self.mesh.labels) ] self.color_label_pickers = widgets.HBox(self.color_label_pickers, layout=self.invisible_layout) self.widgets += [self.color_label_pickers] self.flip_x_button.observe(self.__update_clipping, names='value') self.flip_y_button.observe(self.__update_clipping, names='value') self.flip_z_button.observe(self.__update_clipping, names='value') self.clipping_slider_x.observe(self.__update_clipping, names='value') self.clipping_slider_y.observe(self.__update_clipping, names='value') self.clipping_slider_z.observe(self.__update_clipping, names='value') if hasattr(self.mesh, "internals"): self.color_internal.observe(self.__update_internal_color, names='value') self.color_external.observe(self.__update_external_color, names='value') self.color_wireframe.observe(self.__update_wireframe_color, names='value') self.wireframe_opacity_slider.observe(self.__update_wireframe_opacity, names='value') self.coloring_type_menu.observe(self.__change_color_type, names='value') self.color_map.observe(self.__change_color_map, names='value') self.metric_menu.observe(self.__change_metric, names='value') self.click_picker.observe(self.on_click, names=['point']) [ i.observe(self.__change_color_label, names='value') for i in self.color_label_pickers.children ] #self.wireframe_thickness_slider.observe(self.__update_wireframe_thickness, names='value') for widget in self.widgets: ipydisplay(widget)
def show(self): ipydisplay(self.renderer)
def display(self): """Display the Box widget in the current IPython cell.""" from IPython.display import display as ipydisplay ipydisplay(self.box)
def show(self): ipydisplay(self)