Hi!
I’m using bokeh in a jupyter notebook.
And i’m trying to use the boxedittool to select patches of a plotted image and to get back the selected boxes’ properties in the python code.
But the source.data[‘x’/‘y’…] doen’t contain the new values.
(iv’e alse tried to push them to the source.data in js_on_change(“data”, CustomJS manner)
is this possible? is there another more elegant way to implement my task rather than using boxedittool?
here the core code:
img = cv2.imread('img.png', cv2.IMREAD_GRAYSCALE).astype('float') / 255
width, height = img.shape
palette = ['#%02x%02x%02x' %(i,i,i) for i in range(256)]
fig = figure(tools="pan,wheel_zoom,box_edit,reset,box_zoom,box_select")
fig.y_range = Range1d(0, height, bounds=(0, height))
fig.x_range = Range1d(0, width, bounds=(0, width))
imfig = fig.image(image=[img[::-1,:,...]], x=[0], y=[0], dw=[width], dh=[height], palette=palette)
src = ColumnDataSource({
'x': [0], 'y': [0], 'width': [0],
'height': [0], 'alpha': [0]
})
renderer = fig.rect('x', 'y', 'width', 'height', source=src, alpha='alpha')
draw_tool = BoxEditTool(renderers=[renderer], empty_value=1)
fig.add_tools(draw_tool)
fig.toolbar.active_drag = draw_tool
show(fig, notebook_handle=True)
Hope you can help me,
Thank you very much