From 901b4a727fb705ed9ac1056fdec2dc8990d86413 Mon Sep 17 00:00:00 2001 From: leeping-ng Date: Wed, 1 Dec 2021 16:21:54 +0800 Subject: [PATCH 1/5] feat: add configs to output screen --- peekingduck/configs/output/screen.yml | 8 +++++++- peekingduck/pipeline/nodes/output/screen.py | 20 ++++++++++++++++++-- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/peekingduck/configs/output/screen.yml b/peekingduck/configs/output/screen.yml index c60012f95..06e42c353 100644 --- a/peekingduck/configs/output/screen.yml +++ b/peekingduck/configs/output/screen.yml @@ -1,2 +1,8 @@ input: ["img"] -output: ["pipeline_end"] \ No newline at end of file +output: ["pipeline_end"] + +window_name: PeekingDuck +window_width: 1280 +window_height: 720 +window_x_coord: 0 +window_y_coord: 0 \ No newline at end of file diff --git a/peekingduck/pipeline/nodes/output/screen.py b/peekingduck/pipeline/nodes/output/screen.py index a5a8d16a4..067a547ed 100644 --- a/peekingduck/pipeline/nodes/output/screen.py +++ b/peekingduck/pipeline/nodes/output/screen.py @@ -33,17 +33,33 @@ class Node(AbstractNode): |pipeline_end| Configs: - None. + window_name (:obj:`str`): **default = "PeekingDuck"** |br| + Name of the displayed window. + window_width (:obj:`int`): **default = 1280** |br| + Width of the displayed window, in pixels. + window_height (:obj:`int`): **default = 720** |br| + Height of the displayed window, in pixels. + window_x_coord (:obj:`int`): **default = 0** |br| + X-coordinate of the top left corner of the displayed window, with reference + from the top left corner of the screen, in pixels. + window_y_coord (:obj:`int`): **default = 0** |br| + Y-coordinate of the top left corner of the displayed window, with reference + from the top left corner of the screen, in pixels. """ def __init__(self, config: Dict[str, Any] = None, **kwargs: Any) -> None: super().__init__(config, node_path=__name__, **kwargs) + cv2.namedWindow(self.window_name, cv2.WINDOW_NORMAL) + cv2.moveWindow(self.window_name, self.window_x_coord, self.window_y_coord) + cv2.resizeWindow(self.window_name, self.window_width, self.window_height) def run(self, inputs: Dict[str, Any]) -> Dict[str, Any]: """Show the outputs on your display""" - cv2.imshow("PeekingDuck", inputs["img"]) + + cv2.imshow(self.window_name, inputs["img"]) if cv2.waitKey(1) & 0xFF == ord("q"): + cv2.destroyWindow(self.window_name) return {"pipeline_end": True} return {"pipeline_end": False} From 9fe2def7c8db09051506f2e121f8ab91d2fa4ab4 Mon Sep 17 00:00:00 2001 From: leeping-ng Date: Thu, 2 Dec 2021 16:33:56 +0800 Subject: [PATCH 2/5] feat: nested related configs for cleaner code --- peekingduck/configs/output/screen.yml | 14 +++++++++----- peekingduck/pipeline/nodes/output/screen.py | 21 +++++++++------------ 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/peekingduck/configs/output/screen.yml b/peekingduck/configs/output/screen.yml index 06e42c353..cb1f2dd07 100644 --- a/peekingduck/configs/output/screen.yml +++ b/peekingduck/configs/output/screen.yml @@ -1,8 +1,12 @@ input: ["img"] output: ["pipeline_end"] -window_name: PeekingDuck -window_width: 1280 -window_height: 720 -window_x_coord: 0 -window_y_coord: 0 \ No newline at end of file +window_name: "PeekingDuck" +window_size: { + width: 1280, + height: 720 +} +window_loc: { + x: 0, + y: 0 +} \ No newline at end of file diff --git a/peekingduck/pipeline/nodes/output/screen.py b/peekingduck/pipeline/nodes/output/screen.py index 067a547ed..bc296950c 100644 --- a/peekingduck/pipeline/nodes/output/screen.py +++ b/peekingduck/pipeline/nodes/output/screen.py @@ -35,23 +35,20 @@ class Node(AbstractNode): Configs: window_name (:obj:`str`): **default = "PeekingDuck"** |br| Name of the displayed window. - window_width (:obj:`int`): **default = 1280** |br| - Width of the displayed window, in pixels. - window_height (:obj:`int`): **default = 720** |br| - Height of the displayed window, in pixels. - window_x_coord (:obj:`int`): **default = 0** |br| - X-coordinate of the top left corner of the displayed window, with reference - from the top left corner of the screen, in pixels. - window_y_coord (:obj:`int`): **default = 0** |br| - Y-coordinate of the top left corner of the displayed window, with reference - from the top left corner of the screen, in pixels. + window_size (:obj:`Dict`): **default = { width: 1280, height: 720 }** |br| + Width and height of the displayed window, in pixels. + window_loc (:obj:`Dict`): **default = { x: 0, y: 0 }** |br| + X and Y coordinates of the top left corner of the displayed window, with + reference from the top left corner of the screen, in pixels. """ def __init__(self, config: Dict[str, Any] = None, **kwargs: Any) -> None: super().__init__(config, node_path=__name__, **kwargs) cv2.namedWindow(self.window_name, cv2.WINDOW_NORMAL) - cv2.moveWindow(self.window_name, self.window_x_coord, self.window_y_coord) - cv2.resizeWindow(self.window_name, self.window_width, self.window_height) + cv2.moveWindow(self.window_name, self.window_loc["x"], self.window_loc["y"]) + cv2.resizeWindow( + self.window_name, self.window_size["width"], self.window_size["height"] + ) def run(self, inputs: Dict[str, Any]) -> Dict[str, Any]: """Show the outputs on your display""" From aafeb286f2941679c802255744bb1c06e7617e99 Mon Sep 17 00:00:00 2001 From: leeping-ng Date: Thu, 16 Dec 2021 09:13:39 +0800 Subject: [PATCH 3/5] feat: update resizing on opencv version >= 4.5 --- peekingduck/configs/output/screen.yml | 1 + peekingduck/pipeline/nodes/output/screen.py | 17 +++++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/peekingduck/configs/output/screen.yml b/peekingduck/configs/output/screen.yml index cb1f2dd07..9f979ff07 100644 --- a/peekingduck/configs/output/screen.yml +++ b/peekingduck/configs/output/screen.yml @@ -3,6 +3,7 @@ output: ["pipeline_end"] window_name: "PeekingDuck" window_size: { + do_resizing: False, width: 1280, height: 720 } diff --git a/peekingduck/pipeline/nodes/output/screen.py b/peekingduck/pipeline/nodes/output/screen.py index bc296950c..c2fd840ca 100644 --- a/peekingduck/pipeline/nodes/output/screen.py +++ b/peekingduck/pipeline/nodes/output/screen.py @@ -35,8 +35,10 @@ class Node(AbstractNode): Configs: window_name (:obj:`str`): **default = "PeekingDuck"** |br| Name of the displayed window. - window_size (:obj:`Dict`): **default = { width: 1280, height: 720 }** |br| - Width and height of the displayed window, in pixels. + window_size (:obj:`Dict`): + **default = { do_resizing: False, width: 1280, height: 720 }** |br| + Resizes the displayed window to the chosen width and weight, if ``do_resizing`` + is set to ``true``. window_loc (:obj:`Dict`): **default = { x: 0, y: 0 }** |br| X and Y coordinates of the top left corner of the displayed window, with reference from the top left corner of the screen, in pixels. @@ -46,14 +48,17 @@ def __init__(self, config: Dict[str, Any] = None, **kwargs: Any) -> None: super().__init__(config, node_path=__name__, **kwargs) cv2.namedWindow(self.window_name, cv2.WINDOW_NORMAL) cv2.moveWindow(self.window_name, self.window_loc["x"], self.window_loc["y"]) - cv2.resizeWindow( - self.window_name, self.window_size["width"], self.window_size["height"] - ) def run(self, inputs: Dict[str, Any]) -> Dict[str, Any]: """Show the outputs on your display""" - cv2.imshow(self.window_name, inputs["img"]) + if not self.window_size["do_resizing"]: + cv2.imshow(self.window_name, inputs["img"]) + else: + resized_img = cv2.resize( + inputs["img"], (self.window_size["width"], self.window_size["height"]) + ) + cv2.imshow(self.window_name, resized_img) if cv2.waitKey(1) & 0xFF == ord("q"): cv2.destroyWindow(self.window_name) From 98d3f78bbe54adf2ba605c4846a4b72e64ede6c0 Mon Sep 17 00:00:00 2001 From: leeping-ng Date: Fri, 17 Dec 2021 09:10:38 +0800 Subject: [PATCH 4/5] feat: minor refactor to streamline code --- peekingduck/pipeline/nodes/output/screen.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/peekingduck/pipeline/nodes/output/screen.py b/peekingduck/pipeline/nodes/output/screen.py index c2fd840ca..a366e7822 100644 --- a/peekingduck/pipeline/nodes/output/screen.py +++ b/peekingduck/pipeline/nodes/output/screen.py @@ -52,13 +52,12 @@ def __init__(self, config: Dict[str, Any] = None, **kwargs: Any) -> None: def run(self, inputs: Dict[str, Any]) -> Dict[str, Any]: """Show the outputs on your display""" - if not self.window_size["do_resizing"]: - cv2.imshow(self.window_name, inputs["img"]) - else: - resized_img = cv2.resize( - inputs["img"], (self.window_size["width"], self.window_size["height"]) + img = inputs["img"] + if self.window_size["do_resizing"]: + img = cv2.resize( + img, (self.window_size["width"], self.window_size["height"]) ) - cv2.imshow(self.window_name, resized_img) + cv2.imshow(self.window_name, img) if cv2.waitKey(1) & 0xFF == ord("q"): cv2.destroyWindow(self.window_name) From 9762dc86981709743efa1c913f56c6f578f1396f Mon Sep 17 00:00:00 2001 From: leeping-ng Date: Fri, 17 Dec 2021 09:14:21 +0800 Subject: [PATCH 5/5] feat: added note in config that window size can be changed by clicking and dragging --- peekingduck/pipeline/nodes/output/screen.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/peekingduck/pipeline/nodes/output/screen.py b/peekingduck/pipeline/nodes/output/screen.py index a366e7822..503ad5fb2 100644 --- a/peekingduck/pipeline/nodes/output/screen.py +++ b/peekingduck/pipeline/nodes/output/screen.py @@ -38,7 +38,8 @@ class Node(AbstractNode): window_size (:obj:`Dict`): **default = { do_resizing: False, width: 1280, height: 720 }** |br| Resizes the displayed window to the chosen width and weight, if ``do_resizing`` - is set to ``true``. + is set to ``true``. The size of the displayed window can also be adjusted by + clicking and dragging. window_loc (:obj:`Dict`): **default = { x: 0, y: 0 }** |br| X and Y coordinates of the top left corner of the displayed window, with reference from the top left corner of the screen, in pixels.