Skip to content

Commit

Permalink
Merge pull request #547 from leeping-ng/feat-output-screen-size
Browse files Browse the repository at this point in the history
Add configurable options to improve `output.screen` node
  • Loading branch information
ongtw committed Dec 17, 2021
2 parents 163ab90 + 9762dc8 commit 6527660
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
13 changes: 12 additions & 1 deletion peekingduck/configs/output/screen.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
input: ["img"]
output: ["pipeline_end"]
output: ["pipeline_end"]

window_name: "PeekingDuck"
window_size: {
do_resizing: False,
width: 1280,
height: 720
}
window_loc: {
x: 0,
y: 0
}
22 changes: 20 additions & 2 deletions peekingduck/pipeline/nodes/output/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,35 @@ class Node(AbstractNode):
|pipeline_end|
Configs:
None.
window_name (:obj:`str`): **default = "PeekingDuck"** |br|
Name of the displayed window.
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``. 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.
"""

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"])

def run(self, inputs: Dict[str, Any]) -> Dict[str, Any]:
"""Show the outputs on your display"""
cv2.imshow("PeekingDuck", inputs["img"])

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, img)

if cv2.waitKey(1) & 0xFF == ord("q"):
cv2.destroyWindow(self.window_name)
return {"pipeline_end": True}

return {"pipeline_end": False}

0 comments on commit 6527660

Please sign in to comment.