Skip to content

Commit 9793801

Browse files
committed
1) Fixed documentation requirements and OCR example order
2) Added RapidOCR test stub for default OCRAlgorithm tests 3) Fixed IdsAlgorithm and NamesAlgorithm argument forwarding without debugger 4) Renamed UnDetected event to Undetected and updated CV tests 5) Fixed YOLO box coordinate rounding and size calculation 6) Fixed OCR plot text offset check and cleaned up docstrings
1 parent e512b40 commit 9793801

20 files changed

Lines changed: 72 additions & 50 deletions

File tree

apparser/core/ui/coordinates.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ def __init__(
2222
:type from_ui: BaseUi
2323
:param point_one: First point of the nested region.
2424
:type point_one: Point | RelativelyPoint
25-
:param point_two: Second point of the nested region or region size.
26-
:type point_two: Point | RelativelyPoint | Size
25+
:param point_two: Second point of the nested region.
26+
:type point_two: Point | RelativelyPoint
2727
:raises TypeError: If any argument has an invalid type.
2828
"""
2929
if not isinstance(from_ui, BaseUi):

apparser/cv/events/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from apparser.cv.events.moved import Moved
33
from apparser.cv.events.detected import Detected
44
from apparser.cv.events.resized import Resized
5-
from apparser.cv.events.undetected import UnDetected
5+
from apparser.cv.events.undetected import Undetected
66

77
__all__ = ["CvEvent", "Moved",
8-
"Detected", "Resized", "UnDetected"]
8+
"Detected", "Resized", "Undetected"]

apparser/cv/events/undetected.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from apparser.cv.events.base import CvEvent
22

33

4-
class UnDetected(CvEvent):
4+
class Undetected(CvEvent):
55
"""Represent a previously tracked object that disappeared."""
66

77
def __str__(self) -> str:

apparser/cv/readers/yolo.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ def read(self, ui: BaseUi) -> CvAllData:
5050
track_id = int(track_id.item())
5151
cls_name = names[class_index]
5252
x1, y1, x2, y2 = box.xyxy[0].tolist()
53-
x = int(x1)
54-
y = int(y1)
55-
x2 = int(x2)
56-
y2 = int(y2)
57-
width = x2 - x1
58-
height = y2 - y1
53+
x = round(x1)
54+
y = round(y1)
55+
x2 = round(x2)
56+
y2 = round(y2)
57+
width = x2 - x
58+
height = y2 - y
5959
box_ui = CoordinatesUi(ui, Point(x, y), Point(x2, y2))
6060
boxes.append(
6161
CvBox(

apparser/cv/utils/changes_checker.py

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
from apparser.cv.models import CvAllData, CvChangeData, CvBox
2-
from apparser.cv.events import Detected, UnDetected, Moved, Resized
2+
from apparser.cv.events import Detected, Undetected, Moved, Resized
33

44

55
def _is_moved(box: CvBox, old_box: CvBox) -> bool:
6-
"""Check whether a box position changed.
7-
8-
:param box: Current box state.
9-
:type box: CvBox
10-
:param old_box: Previous box state.
11-
:type old_box: CvBox
12-
:return: True if the box coordinates changed.
13-
:rtype: bool
14-
"""
156
return abs(box.x - old_box.x) > 0 or abs(box.y - old_box.y) > 0
167

178

189
def _is_resized(box: CvBox, old_box: CvBox) -> bool:
19-
"""Check whether both box dimensions changed.
20-
21-
:param box: Current box state.
22-
:type box: CvBox
23-
:param old_box: Previous box state.
24-
:type old_box: CvBox
25-
:return: True if width and height both changed.
26-
:rtype: bool
27-
"""
2810
return abs(box.width - old_box.width) > 0 or abs(box.height - old_box.height) > 0
2911

3012

@@ -59,7 +41,7 @@ def __get_undetected(self, current_data: CvAllData) -> list[CvChangeData]:
5941
:rtype: list[CvChangeData]
6042
"""
6143
new_ids = [i.track_id for i in current_data.boxes if i.track_id is not None]
62-
return [CvChangeData(UnDetected, i, i) for i in self.__old_data.boxes if
44+
return [CvChangeData(Undetected, i, i) for i in self.__old_data.boxes if
6345
i.track_id not in new_ids and i.track_id is not None]
6446

6547
def check(self, data: CvAllData) -> list[CvChangeData]:

apparser/instructions/default/click.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, click_type: BaseKeyCode = LeftClick()):
1212
1313
:param click_type: Mouse button to click.
1414
:type click_type: BaseKeyCode
15-
:raises TypeError: If ``click_type`` is neither :class:`BaseKeyCode`.
15+
:raises TypeError: If ``click_type`` is not a :class:`BaseKeyCode`.
1616
"""
1717
if not isinstance(click_type, BaseKeyCode):
1818
raise TypeError('click_type must be BaseKeyCode')

apparser/instructions/default/press.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,17 @@ def perform(self, *args, **kwargs):
3030
class PressKeysCombination(BaseInstruction):
3131
"""Send a keyboard shortcut as a pressed combination."""
3232

33-
def __init__(self, keys: list[BaseKeyCode | str]):
33+
def __init__(self, keys: list[BaseKeyCode | str] | str):
3434
"""Initialize a key combination instruction.
3535
3636
:param keys: Keys to press together.
37-
:type keys: list[BaseKeyCode | str]
37+
:type keys: list[BaseKeyCode | str] | str
3838
"""
3939
self.__keys = keys
4040
self.__validate()
4141

4242
def __validate(self):
43+
4344
for key in self.__keys:
4445
if not (isinstance(key, BaseKeyCode) or isinstance(key, str)):
4546
raise TypeError('key_code must be BaseKeyCode or str')

apparser/instructions/default/sleep.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, sleep_time: float):
1212
:param sleep_time: Delay duration in seconds.
1313
:type sleep_time: float
1414
:raises ValueError: If ``sleep_time`` is not greater than zero.
15-
:raises TypeError: If ``sleep_time`` is not number.
15+
:raises TypeError: If ``sleep_time`` is not a number.
1616
"""
1717
if not isinstance(sleep_time, float) and not isinstance(sleep_time, int):
1818
raise TypeError("sleep_time must be a number.")

apparser/instructions/ocr/plot_text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __paint_cords(self, data: TextData):
4141
if y < 0:
4242
y = data.coordinates.right_bottom.y - self.__text_move.y
4343
x = data.coordinates.left_top.x + self.__text_move.x
44-
if y < 0:
44+
if x < 0:
4545
x = data.coordinates.right_bottom.x - self.__text_move.x
4646
self.__draw.text((x, y), data.text, fill=self.__color)
4747

apparser/instructions/ui/algorithms/ids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def perform(self, ui: BaseUi, *args, **kwargs):
113113
if self.__debugger is not None:
114114
self.__debugger.try_perform(instruction, **perform_kwargs)
115115
else:
116-
instruction.perform(ui, **perform_kwargs)
116+
instruction.perform(**perform_kwargs)
117117

118118
def add_instruction(self, instruction: tuple[int, list[Any]]):
119119
_check_instruction(instruction)

0 commit comments

Comments
 (0)