andfanilo / streamlit-drawable-canvas

Do you like Quick, Draw? Well what if you could train/predict doodles drawn inside Streamlit? Also draws lines, circles and boxes over background images for annotation.
https://drawable-canvas.streamlit.app/
MIT License
563 stars 85 forks source link

"initial_drawing" over "background_image" only appears when clicking "Undo" or "Reset Canvas & History" #44

Closed mroyce1 closed 3 years ago

mroyce1 commented 3 years ago

Hi,

first of all, thank you for this awesome extension to streamlit. I'd really like to make use of the "initial_drawing" capability in order to superimpose bounding boxes on images. However, there seems to be a bug that the background image overlays the drawing (while it should be the other way around). The drawing only appears in the following cases:

My super simple app is as follows:


import json
from pathlib import Path

import streamlit as st
from PIL import Image
from streamlit_drawable_canvas import st_canvas

with open("star_state.json", "r") as f:
    star_state = json.load(f)

canvas_result = st_canvas(
    fill_color="rgba(255, 165, 0, 0.3)",
    background_image=Image.open("img/tennis-balls.jpg"),
    update_streamlit=False,
    height=150,
    initial_drawing=star_state,
    key="full_app",
)

star_state.json and tennis-balls.jpg are from the demo repo.

Thank you for your help.

andfanilo commented 3 years ago

Hello @mroyce1

Thanks for reporting! After pulling my hair on this for some hours I think I fixed this, it'll be in the next release. Hope it solves everything :)

Cheers, Fanilo

andfanilo commented 3 years ago

EDIT: @mroyce1 I've released version 0.7.0, could you update and try on your side and tell me if all goes well? I've edited the demo app to test loading a state on the Get center coords of circles demo.