Skip to content

Commit

Permalink
Merge pull request #23 from sqoshi/mask-switch-ab
Browse files Browse the repository at this point in the history
Functionality to dynamically switch mask
  • Loading branch information
sqoshi authored Nov 7, 2021
2 parents 76e6fe7 + c73d146 commit 36c9c71
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 7 deletions.
6 changes: 6 additions & 0 deletions mask_imposer/bundled/set_00/mask_coords.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"2": [10, 300],
"9": [400, 590],
"16": [790, 300],
"29": [400, 10]
}
Binary file added mask_imposer/bundled/set_00/mask_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions mask_imposer/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def __init__(self, bundled_mask_set_idx: int = 1) -> None:
logger=self._logger
)

def switch_mask(self, bundled_mask_set_idx: int) -> None:
"""Switches mask set in mask imposer."""
self._imposer.switch_mask_set(_get_bundled_mask_set(bundled_mask_set_idx))

def impose_mask(
self, image: Union[str, List[str]], show: bool = False
) -> Union[NDArray[Any], List[NDArray[Any]]]:
Expand Down
4 changes: 4 additions & 0 deletions mask_imposer/imposer/mask_imposer.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ def __init__(
self._show_samples = improvements.show_samples
self._mask = MaskImage(mask_set)

def switch_mask_set(self, mask_set: MaskSet) -> None:
"""Switches mask image."""
self._mask = MaskImage(mask_set)

@staticmethod
def _fit_left_top_coords(
landmarks_dict: Dict[int, Tuple[int, int]], mask_pointers_map: PointerMap
Expand Down
10 changes: 4 additions & 6 deletions run.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,12 @@ def _parse_args() -> Namespace:
parser.add_argument("--off-face-detection", action="store_true",
help="Before landmark prediction detect face box.")
parser.add_argument("--mask-coords", type=str, default=None,
# "mask_imposer/bundled/set_01/mask_coords.json",
help="Custom mask image path.")
parser.add_argument("--mask-img", type=str, default=None,
help="Custom mask characteristic [2,9,16,29]"
" landmarks coordinates json filepath.")
parser.add_argument("--use-bundled-mask", type=int, default=1, choices=[1, 2],
help="Custom mask characteristic [2,9,16,29] "
"landmarks coordinates json filepath.")
parser.add_argument("--mask-img", type=str, default=None,
help="Custom mask image path.")
parser.add_argument("--use-bundled-mask", type=int, default=1, choices=[0, 1, 2],
help="Index to bundled mask set [0, 1, 2]")
return parser.parse_args()


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name="Mask Imposer",
version="2.2.0",
version="2.3.1",
description="Tool to overlay fake face masks.",
url="https://github.com/sqoshi/mask-imposer",
author="Piotr Popis",
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/test_package/test_python_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,15 @@ def test_should_impose_mask_on_image_from_path(self) -> None:
def test_should_impose_mask_on_image_from_numpy_array(self) -> None:
self.imp.impose_mask((cv2.imread(self.test_img_path), "fake_mask"), show=True)

def test_should_switch_mask(self) -> None:
self.imp.impose_mask((cv2.imread(self.test_img_path), "fake_mask"), show=True)
self.imp.switch_mask(2)
self.imp.impose_mask((cv2.imread(self.test_img_path), "fake_mask"), show=True)

def test_should_set_black_rect_instead_of_mask(self) -> None:
self.imp.switch_mask(0)
self.imp.impose_mask((cv2.imread(self.test_img_path), "fake_mask"), show=True)

def test_should_imposing_results_be_same_for_path_and_numpy_array_way(self):
m1 = self.imp.impose_mask((cv2.imread(self.test_img_path), "fake_mask"), show=False)
m2 = self.imp.impose_mask(self.test_img_path, show=False)
Expand Down

0 comments on commit 36c9c71

Please sign in to comment.