I need to read Base64 encoded image (uploaded by user on Dash app), do some operations using opencv (skip this operation for now) and transform it back to Base64, so that it could be displayed in the browser. The problem is that I never manage to see the output image in a browser, I don't get any errors though.
def parse_contents(contents):
img1 = data_uri_to_cv2_img(contents)
_, buffer = cv2.imencode('.jpg', img1)
jpg_as_text = base64.b64encode(buffer.tobytes())
second_part = str(jpg_as_text).split('/', 1)[-1]
to_save = contents.split(',')[0]
one_string = to_save + ',' + '/'+ second_part
return html.Div([
html.Img(src=one_string, style={'height':'10%',
'width':'10%'}),
html.Hr(),
html.Div('Raw Content'),
html.Pre(one_string + '...', style={
'whiteSpace': 'pre-wrap',
'wordBreak': 'break-all'
})
])
@app.callback(
Output('output-image-upload', 'children'),
Input('store-data', 'data')
)
The input data looks something like this: contents =
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/4QAiRXhpZgAATU0AKgAAAAgAAQESAAMA..
When I run the code in notebook, I see the output image, however in app, it looks like on picture