Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions hints/backends/opencv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from typing import TYPE_CHECKING

import pyscreenshot as ImageGrab
from cv2 import (CHAIN_APPROX_SIMPLE, COLOR_BGR2GRAY, RETR_LIST, Canny,
boundingRect, cvtColor, dilate, findContours)
from cv2 import (CHAIN_APPROX_SIMPLE, COLOR_BGR2GRAY, RETR_LIST, INTER_AREA,
Canny, boundingRect, cvtColor, dilate, findContours, resize)
from numpy import array, ones, uint8

from hints.backends.backend import HintsBackend
Expand Down Expand Up @@ -62,13 +62,23 @@ def get_children(self) -> list[Child]:
# in sway, we need to exclude the top bar from the screenshot region
window_extents_offsets = (0, self.window_system.bar_height, 0, 0)

gray_image = cvtColor(
array(
image = array(
self.screenshot(
self.window_system.focused_window_extents,
window_extents_offsets=window_extents_offsets,
)
),
)

# Resize the image to the size of the focused window,
# so hints are right-positioned
resized_image = resize(
image,
self.window_system.focused_window_extents[2:4],
interpolation=INTER_AREA,
)

gray_image = cvtColor(
resized_image,
COLOR_BGR2GRAY,
)

Expand Down