-
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
7 changed files
with
160 additions
and
63 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
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 |
---|---|---|
@@ -1,31 +1,42 @@ | ||
from drawing_to_fsd_layout.image_processing import Image | ||
from streamlit_drawable_canvas import st_canvas | ||
import streamlit as st | ||
import numpy as np | ||
import streamlit as st | ||
from streamlit_drawable_canvas import st_canvas | ||
|
||
from drawing_to_fsd_layout.image_processing import Image | ||
|
||
|
||
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, 10) | ||
|
||
should_erase = st.radio("Eraser", ["Off", "On"], horizontal=True) | ||
|
||
stroke_color = "white" if should_erase == "On" else "black" | ||
|
||
canvas_result = st_canvas( | ||
stroke_width=stroke_width, | ||
drawing_mode='freedraw', | ||
stroke_color=stroke_color, | ||
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 | ||
raw_image_data = canvas_result.image_data | ||
image_data = canvas_result.image_data[:, :, [-1]] | ||
image_lightness = np.max(raw_image_data[:, :, :-1], axis=2) > 0 | ||
|
||
image_data[image_lightness] = 0 | ||
|
||
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 |
---|---|---|
@@ -1,5 +1,36 @@ | ||
from pathlib import Path | ||
|
||
import numpy as np | ||
|
||
FloatArrayNx2 = np.typing.NDArray[np.float64] | ||
IntArrayN = np.typing.NDArray[np.int64] | ||
FloatArray2 = np.typing.NDArray[np.float64] | ||
|
||
|
||
def find_github_link_of_repo() -> str: | ||
""" | ||
Find the github link of a repository by looking at the .git/config file | ||
Args: | ||
git_directory: The directory of the git repository | ||
Returns: | ||
The github link of the repository | ||
""" | ||
|
||
git_directory = Path(__file__).parent.parent | ||
|
||
# The entire function was generated by github copilot | ||
git_config = git_directory / ".git" / "config" | ||
with open(git_config, "r") as f: | ||
lines = f.readlines() | ||
|
||
for i, line in enumerate(lines): | ||
if "url = " in line: | ||
url = line.split(" = ")[1].strip() | ||
url = url.replace("git@", "https://") | ||
url = url.replace(".git", "") | ||
url = url.replace(".com:", ".com/") | ||
return url | ||
|
||
raise ValueError("Could not find the github link in the .git/config file") |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.