Skip to content

Commit

Permalink
hyperfocal: Now with filters
Browse files Browse the repository at this point in the history
Added new and fun filters :)

filters.py: New sub-module with filters represented as Callables
__main__.py: Added filter button UI
  • Loading branch information
okawo80085 committed Aug 25, 2021
1 parent d063965 commit 31c39a6
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 3 deletions.
89 changes: 86 additions & 3 deletions hyperfocal/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,17 +493,100 @@ def theme_change_dir_setting_cb(app: Dict[str, setting]):
layer=1
)

################################################
# layer 0 - normal app overlay
# layer 1 - settings
# layer 2 - resolution overlays WIP
# layer 3 - gallery buttons
################################################

def set_filter(filt: Union[Callable[[np.ndarray], np.ndarray], None]):
img_proc.CV_PHOTO_FILTER = filt
print(f'filter set to: {filt}')

# filters
clear_filter = ui.CanvasAlphaObject(
np.array(
(0.07, 0.75)
) * app_settings['preview_resolution'] - (40, 15),
cv2.putText(
np.zeros((30, 80, 3), dtype=np.uint8),
"clear",
(0, 30),
cv2.FONT_HERSHEY_PLAIN,
1,
(255, 255, 255)
),
np.ones((30, 80)) * 0.4,
lambda: set_filter(None)
)

t1000_filter = ui.CanvasAlphaObject(
np.array(
(0.14, 0.75)
) * app_settings['preview_resolution'] - (0, 15),
cv2.putText(
np.zeros((30, 80, 3), dtype=np.uint8),
"times1000",
(0, 30),
cv2.FONT_HERSHEY_PLAIN,
1,
(255, 255, 255)
),
np.ones((30, 80)) * 0.4,
lambda: set_filter(filters.times1000)
)

t2000_filter = ui.CanvasAlphaObject(
np.array(
(0.26, 0.75)
) * app_settings['preview_resolution'] - (0, 15),
cv2.putText(
np.zeros((30, 80, 3), dtype=np.uint8),
"times2000",
(0, 30),
cv2.FONT_HERSHEY_PLAIN,
1,
(255, 255, 255)
),
np.ones((30, 80)) * 0.4,
lambda: set_filter(filters.times2000)
)

gray_filter = ui.CanvasAlphaObject(
np.array(
(0.38, 0.75)
) * app_settings['preview_resolution'] - (0, 15),
cv2.putText(
np.zeros((30, 80, 3), dtype=np.uint8),
"gray",
(0, 30),
cv2.FONT_HERSHEY_PLAIN,
1,
(255, 255, 255)
),
np.ones((30, 80)) * 0.4,
lambda: set_filter(filters.grayscale)
)

################################################
# button lists for rendering
################################################

buttons_opaque = [
# layer 0
# layer 0 - main overlay
gallery_button,
]

buttons_transparent = [
# layer 0
# layer 0 - main overlay
take_photo_button,
settings_button,
# layer 1
clear_filter,
t1000_filter,
t2000_filter,
gray_filter,
# layer 1 - settings
gallery_toggle_setting,
gallery_change_dir_setting,
theme_change_dir_setting,
Expand Down
25 changes: 25 additions & 0 deletions hyperfocal/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import cv2
import numpy as np
# from typing import Tuple, Dict, TypeVar, List, Callable, Union

# setting = TypeVar('setting', str, int, float, bool, List[int])

###############################################################################
# IMAGE FILTERS
###############################################################################


def times1000(img: np.ndarray) -> np.ndarray:
return (img * 1000).astype(np.uint8)


def times2000(img: np.ndarray) -> np.ndarray:
return (img * 10000).astype(np.uint8)


def grayscale(img: np.ndarray) -> np.ndarray:
return np.stack((cv2.cvtColor(img, cv2.COLOR_BGR2GRAY), ) * 3, axis=-1)

###############################################################################
# VIDEO FILTERS (WIP... since there is no video processing yet...)
###############################################################################

0 comments on commit 31c39a6

Please sign in to comment.