-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
48 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from drawing_to_fsd_layout.image_processing import Image | ||
from streamlit_drawable_canvas import st_canvas | ||
import streamlit as st | ||
import numpy as np | ||
|
||
def show_canvas_warning(): | ||
st.warning("You need to draw a track in order to continue.") | ||
st.stop() | ||
|
||
def get_canvas_image() -> Image: | ||
|
||
stroke_width = st.slider("Stroke width", 1, 25, 3) | ||
|
||
canvas_result = st_canvas( | ||
stroke_width=stroke_width, | ||
drawing_mode='freedraw', | ||
key="canvas", | ||
) | ||
|
||
if canvas_result.image_data is None: | ||
show_canvas_warning() | ||
|
||
# by default canvas changes the alpha channel, not the rgb channels | ||
image_data = canvas_result.image_data[:, :, [-1]] | ||
image_data = np.broadcast_to(image_data, image_data.shape[:-1] + (3,)) | ||
image_data = 255 - image_data | ||
|
||
if np.all(image_data == 255): | ||
show_canvas_warning() | ||
|
||
return image_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,3 +6,4 @@ scikit-image==0.19.3 | |
scipy==1.10.0 | ||
streamlit==1.15.2 | ||
altair<5 | ||
streamlit-drawable-canvas==0.9.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters