-
Notifications
You must be signed in to change notification settings - Fork 0
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
0 parents
commit 6704cc8
Showing
5 changed files
with
682 additions
and
0 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,160 @@ | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
cover/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
# For a library or package, you might want to ignore these files since the code is | ||
# intended to run in multiple environments; otherwise, check them in: | ||
# .python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# poetry | ||
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control. | ||
# This is especially recommended for binary packages to ensure reproducibility, and is more | ||
# commonly ignored for libraries. | ||
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control | ||
#poetry.lock | ||
|
||
# pdm | ||
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control. | ||
#pdm.lock | ||
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it | ||
# in version control. | ||
# https://pdm.fming.dev/#use-with-ide | ||
.pdm.toml | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# pytype static type analyzer | ||
.pytype/ | ||
|
||
# Cython debug symbols | ||
cython_debug/ | ||
|
||
# PyCharm | ||
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can | ||
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore | ||
# and can be added to the global gitignore or merged into this file. For a more nuclear | ||
# option (not recommended) you can uncomment the following to ignore the entire idea folder. | ||
#.idea/ |
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,155 @@ | ||
import cv2 | ||
import numpy as np | ||
import gradio as gr | ||
from infer import Model | ||
|
||
|
||
def hex_to_rgb(hex_color, div=255): | ||
hex_color = hex_color.lstrip('#') | ||
r = int(hex_color[0:2], 16) / div | ||
g = int(hex_color[2:4], 16) / div | ||
b = int(hex_color[4:6], 16) / div | ||
|
||
return r, g, b | ||
|
||
|
||
def draw_circle(image, color, x, y, radius, thickness): | ||
|
||
circle_color = hex_to_rgb(color, 1) | ||
|
||
overlay = image.copy() | ||
overlay = cv2.circle(overlay, (x, y), radius, circle_color, -1) | ||
image = cv2.addWeighted(overlay, 0.5, image, 0.5, 0) | ||
image = cv2.circle(image, (x, y), radius, circle_color, thickness) | ||
|
||
return image | ||
|
||
|
||
model = Model() | ||
|
||
with gr.Blocks() as app: | ||
|
||
with gr.Row(): | ||
|
||
original_image = gr.Image(visible=False, type="numpy") | ||
input_image = gr.Image(label="Input Image", | ||
sources="upload", | ||
type="numpy", | ||
interactive=True) | ||
with gr.Tab("Output Image"): | ||
output_image = gr.Image(type="numpy", interactive=False) | ||
with gr.Tab("Output Depth Image"): | ||
depth_image = gr.Image(type="numpy", interactive=False) | ||
with gr.Column(): | ||
pos_x = gr.Slider(0.0, | ||
1.0, | ||
value=0.5, | ||
step=0.1, | ||
label="X", | ||
interactive=True) | ||
pos_y = gr.Slider(0.0, | ||
1.0, | ||
value=0.5, | ||
step=0.1, | ||
label="Y", | ||
interactive=True) | ||
pos_z = gr.Slider(-1.0, | ||
1.0, | ||
value=-0.7, | ||
step=0.05, | ||
label="Z", | ||
interactive=True) | ||
light = gr.Slider(0.0, | ||
2.0, | ||
value=0.7, | ||
step=0.1, | ||
label="Light Intensity", | ||
interactive=True) | ||
color = gr.ColorPicker(value="#FFFFFF", | ||
label="Light Color", | ||
interactive=True) | ||
|
||
def on_upload_image(image, x, y, z, power, color): | ||
r, g, b = hex_to_rgb(color) | ||
x_ = (x - 0.5) * 2 | ||
y_ = (-y + 0.5) * 2 | ||
|
||
d_img, o_img = model.inference_image(image, x_, y_, z, r, g, b, power) | ||
return d_img, o_img, image | ||
|
||
input_image.upload(on_upload_image, | ||
[input_image, pos_x, pos_y, pos_z, light, color], | ||
[depth_image, output_image, original_image]) | ||
|
||
def on_change_image(image, x, y, color): | ||
x_ = int(x * image.shape[1]) | ||
y_ = int(y * image.shape[0]) | ||
|
||
r = int(max(min(image.shape[0], image.shape[1]) / 10, 10)) | ||
|
||
return draw_circle(image, color, x_, y_, r, r // 10) | ||
|
||
original_image.change(on_change_image, | ||
[original_image, pos_x, pos_y, color], [input_image]) | ||
|
||
def get_point(image, color, z, power, evt: gr.SelectData): | ||
x_ = evt.index[0] | ||
y_ = evt.index[1] | ||
x = (x_ / image.shape[1]) | ||
y = (y_ / image.shape[0]) | ||
|
||
r = int(max(min(image.shape[0], image.shape[1]) / 10, 10)) | ||
|
||
input_image = draw_circle(image, color, x_, y_, r, r // 10) | ||
output_image = on_change_parameter(x, y, z, power, color) | ||
return output_image, input_image, x, y | ||
|
||
input_image.select( | ||
get_point, | ||
[original_image, color, pos_z, light], | ||
[output_image, input_image, pos_x, pos_y], | ||
show_progress="hidden", | ||
) | ||
|
||
def on_change_parameter_and_update_image(image, x, y, z, power, color): | ||
|
||
x_ = int(image.shape[1] * x) | ||
y_ = int(image.shape[0] * y) | ||
r = int(max(min(image.shape[0], image.shape[1]) / 10, 10)) | ||
|
||
input_image = draw_circle(image, color, x_, y_, r, r // 10) | ||
output_image = on_change_parameter(x, y, z, power, color) | ||
|
||
return input_image, output_image | ||
|
||
def on_change_parameter(x, y, z, power, color): | ||
r, g, b = hex_to_rgb(color) | ||
xx = (x - 0.5) * 2 | ||
yy = (-y + 0.5) * 2 | ||
|
||
return model.add_light(xx, yy, z, r, g, b, power) | ||
|
||
pos_x.input(on_change_parameter_and_update_image, | ||
[original_image, pos_x, pos_y, pos_z, light, color], | ||
[input_image, output_image], | ||
show_progress="hidden", | ||
trigger_mode="always_last") | ||
pos_y.input(on_change_parameter_and_update_image, | ||
[original_image, pos_x, pos_y, pos_z, light, color], | ||
[input_image, output_image], | ||
show_progress="hidden", | ||
trigger_mode="always_last") | ||
pos_z.input(on_change_parameter, [pos_x, pos_y, pos_z, light, color], | ||
[output_image], | ||
show_progress="hidden", | ||
trigger_mode="always_last") | ||
light.input(on_change_parameter, [pos_x, pos_y, pos_z, light, color], | ||
[output_image], | ||
show_progress="hidden", | ||
trigger_mode="always_last") | ||
color.input(on_change_parameter, [pos_x, pos_y, pos_z, light, color], | ||
[output_image], | ||
show_progress="hidden", | ||
trigger_mode="always_last") | ||
|
||
app.queue().launch() |
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.