valetudo-map-parser 0.1.9b8__tar.gz → 0.1.9b9__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/PKG-INFO +1 -1
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/types.py +0 -1
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/utils.py +35 -12
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/hypfer_draw.py +4 -5
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/hypfer_handler.py +3 -18
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/map_data.py +14 -14
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/rand25_handler.py +11 -26
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/pyproject.toml +1 -1
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/LICENSE +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/NOTICE.txt +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/README.md +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/__init__.py +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/__init__.py +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/auto_crop.py +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/colors.py +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/drawable.py +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/rand25_parser.py +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/shared.py +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/py.typed +0 -0
- {valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/reimg_draw.py +0 -0
{valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/utils.py
RENAMED
@@ -32,6 +32,7 @@ class BaseHandler:
|
|
32
32
|
self.offset_y = 0
|
33
33
|
self.shared = None
|
34
34
|
self.crop_area = [0, 0, 0, 0]
|
35
|
+
self.zooming = False
|
35
36
|
|
36
37
|
def get_frame_number(self) -> int:
|
37
38
|
"""Return the frame number of the image."""
|
@@ -53,10 +54,22 @@ class BaseHandler:
|
|
53
54
|
"""Return the JSON ID from the image."""
|
54
55
|
return self.json_id
|
55
56
|
|
57
|
+
def check_zoom_and_aspect_ratio(self) -> bool:
|
58
|
+
"""Check if the image is zoomed and has an aspect ratio."""
|
59
|
+
return (
|
60
|
+
self.shared.image_auto_zoom
|
61
|
+
and self.shared.vacuum_state == "cleaning"
|
62
|
+
and self.zooming
|
63
|
+
and self.shared.image_zoom_lock_ratio
|
64
|
+
or self.shared.image_aspect_ratio != "None"
|
65
|
+
)
|
66
|
+
|
56
67
|
async def async_resize_image(
|
57
|
-
self, pil_img,
|
68
|
+
self, pil_img, aspect_ratio=None, is_rand=False
|
58
69
|
):
|
59
70
|
"""Resize the image to the given dimensions and aspect ratio."""
|
71
|
+
width = self.shared.image_ref_width
|
72
|
+
height = self.shared.image_ref_height
|
60
73
|
if aspect_ratio:
|
61
74
|
wsf, hsf = [int(x) for x in aspect_ratio.split(",")]
|
62
75
|
if wsf == 0 or hsf == 0:
|
@@ -105,7 +118,7 @@ class BaseHandler:
|
|
105
118
|
return width, height
|
106
119
|
|
107
120
|
@staticmethod
|
108
|
-
async def calculate_array_hash(layers: dict, active: list[int] = None) -> str:
|
121
|
+
async def calculate_array_hash(layers: dict, active: list[int] = None) -> str or None:
|
109
122
|
"""Calculate the hash of the image based on layers and active zones."""
|
110
123
|
if layers and active:
|
111
124
|
data_to_hash = {
|
@@ -121,17 +134,17 @@ class BaseHandler:
|
|
121
134
|
"""Copy the array."""
|
122
135
|
return NumpyArray.copy(original_array)
|
123
136
|
|
124
|
-
def get_map_points(self) -> dict:
|
137
|
+
def get_map_points(self) -> list[dict[str, int] | dict[str, int] | dict[str, int] | dict[str, int]]:
|
125
138
|
"""Return the map points."""
|
126
139
|
return [
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
140
|
+
{"x": 0, "y": 0}, # Top-left corner 0
|
141
|
+
{"x": self.crop_img_size[0], "y": 0}, # Top-right corner 1
|
142
|
+
{
|
143
|
+
"x": self.crop_img_size[0],
|
144
|
+
"y": self.crop_img_size[1],
|
145
|
+
}, # Bottom-right corner 2
|
146
|
+
{"x": 0, "y": self.crop_img_size[1]}, # Bottom-left corner (optional) 3
|
147
|
+
]
|
135
148
|
|
136
149
|
def set_image_offset_ratio_1_1(
|
137
150
|
self, width: int, height: int, rand256: bool = False
|
@@ -446,4 +459,14 @@ class BaseHandler:
|
|
446
459
|
id_count += 1
|
447
460
|
if id_count > 1:
|
448
461
|
_LOGGER.debug("%s: Point Properties updated.", self.file_name)
|
449
|
-
return point_properties
|
462
|
+
return point_properties
|
463
|
+
|
464
|
+
@staticmethod
|
465
|
+
def get_corners(x_max:int, x_min:int, y_max:int, y_min:int) -> list[tuple[int, int]]:
|
466
|
+
"""Return the corners of the image."""
|
467
|
+
return [
|
468
|
+
(x_min, y_min),
|
469
|
+
(x_max, y_min),
|
470
|
+
(x_max, y_max),
|
471
|
+
(x_min, y_max),
|
472
|
+
]
|
{valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/hypfer_draw.py
RENAMED
@@ -262,9 +262,9 @@ class ImageDraw:
|
|
262
262
|
for path in path_pixels:
|
263
263
|
# Get the points from the current path and extend multiple paths.
|
264
264
|
points = path.get("points", [])
|
265
|
-
|
265
|
+
sublist = self.img_h.data.sublist(points, 2)
|
266
266
|
self.img_h.shared.map_new_path = self.img_h.data.sublist_join(
|
267
|
-
|
267
|
+
sublist, 2
|
268
268
|
)
|
269
269
|
np_array = await self.img_h.draw.lines(
|
270
270
|
np_array, self.img_h.shared.map_new_path, 5, color_move
|
@@ -276,9 +276,8 @@ class ImageDraw:
|
|
276
276
|
try:
|
277
277
|
entity_dict = self.img_h.data.find_points_entities(m_json)
|
278
278
|
except (ValueError, KeyError):
|
279
|
-
|
280
|
-
|
281
|
-
_LOGGER.info("%s: Got the points in the json.", self.file_name)
|
279
|
+
return None
|
280
|
+
_LOGGER.info("%s: Got the points in the json.", self.file_name)
|
282
281
|
return entity_dict
|
283
282
|
|
284
283
|
async def async_get_robot_in_room(
|
@@ -40,8 +40,6 @@ class HypferMapImageHandler(BaseHandler):
|
|
40
40
|
self.img_hash = None # hash of the image calculated to check differences.
|
41
41
|
self.img_base_layer = None # numpy array store the map base layer.
|
42
42
|
self.active_zones = None # vacuum active zones.
|
43
|
-
self.frame_number = 0 # frame number of the image.
|
44
|
-
self.zooming = False # zooming the image.
|
45
43
|
self.svg_wait = False # SVG image creation wait.
|
46
44
|
self.trim_down = 0 # memory stored trims calculated once.
|
47
45
|
self.trim_left = 0 # memory stored trims calculated once.
|
@@ -78,12 +76,7 @@ class HypferMapImageHandler(BaseHandler):
|
|
78
76
|
x_max,
|
79
77
|
y_max,
|
80
78
|
) = await self.data.async_get_rooms_coordinates(pixels, pixel_size)
|
81
|
-
corners =
|
82
|
-
(x_min, y_min),
|
83
|
-
(x_max, y_min),
|
84
|
-
(x_max, y_max),
|
85
|
-
(x_min, y_max),
|
86
|
-
]
|
79
|
+
corners = self.get_corners(x_max, x_min, y_max, y_min)
|
87
80
|
room_id = str(segment_id)
|
88
81
|
self.rooms_pos.append(
|
89
82
|
{
|
@@ -253,17 +246,9 @@ class HypferMapImageHandler(BaseHandler):
|
|
253
246
|
pil_img = Image.fromarray(img_np_array, mode="RGBA")
|
254
247
|
del img_np_array
|
255
248
|
# reduce the image size if the zoomed image is bigger then the original.
|
256
|
-
if (
|
257
|
-
self.shared.image_auto_zoom
|
258
|
-
and self.shared.vacuum_state == "cleaning"
|
259
|
-
and self.zooming
|
260
|
-
and self.shared.image_zoom_lock_ratio
|
261
|
-
or self.shared.image_aspect_ratio != "None"
|
262
|
-
):
|
263
|
-
width = self.shared.image_ref_width
|
264
|
-
height = self.shared.image_ref_height
|
249
|
+
if self.check_zoom_and_aspect_ratio():
|
265
250
|
resized_image = await self.async_resize_image(
|
266
|
-
pil_img,
|
251
|
+
pil_img, self.shared.image_aspect_ratio
|
267
252
|
)
|
268
253
|
return resized_image
|
269
254
|
_LOGGER.debug("%s: Frame Completed.", self.file_name)
|
{valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/map_data.py
RENAMED
@@ -239,7 +239,7 @@ class RandImageData:
|
|
239
239
|
return compressed_pixels
|
240
240
|
|
241
241
|
@staticmethod
|
242
|
-
def
|
242
|
+
def _calculate_max_x_y(coord_array):
|
243
243
|
"""Calculate the max and min x and y coordinates."""
|
244
244
|
max_x = -float("inf")
|
245
245
|
max_y = -float("inf")
|
@@ -334,18 +334,18 @@ class RandImageData:
|
|
334
334
|
def get_rrm_currently_cleaned_zones(json_data: JsonType) -> dict:
|
335
335
|
"""Get the currently cleaned zones from the json."""
|
336
336
|
re_zones = json_data.get("currently_cleaned_zones", [])
|
337
|
-
formatted_zones = RandImageData.
|
337
|
+
formatted_zones = RandImageData._rrm_valetudo_format_zone(re_zones)
|
338
338
|
return formatted_zones
|
339
339
|
|
340
340
|
@staticmethod
|
341
341
|
def get_rrm_forbidden_zones(json_data: JsonType) -> dict:
|
342
342
|
"""Get the forbidden zones from the json."""
|
343
343
|
re_zones = json_data.get("forbidden_zones", [])
|
344
|
-
formatted_zones = RandImageData.
|
344
|
+
formatted_zones = RandImageData._rrm_valetudo_format_zone(re_zones)
|
345
345
|
return formatted_zones
|
346
346
|
|
347
347
|
@staticmethod
|
348
|
-
def
|
348
|
+
def _rrm_valetudo_format_zone(coordinates: list) -> any:
|
349
349
|
"""Format the zones from RRM to Valetudo."""
|
350
350
|
formatted_zones = []
|
351
351
|
for zone_data in coordinates:
|
@@ -387,7 +387,7 @@ class RandImageData:
|
|
387
387
|
return formatted_zones
|
388
388
|
|
389
389
|
@staticmethod
|
390
|
-
def
|
390
|
+
def _rrm_valetudo_lines(coordinates: list) -> list:
|
391
391
|
"""Format the lines from RRM to Valetudo."""
|
392
392
|
formatted_lines = []
|
393
393
|
for lines in coordinates:
|
@@ -402,7 +402,7 @@ class RandImageData:
|
|
402
402
|
tmp_data = json_data.get("virtual_walls", [])
|
403
403
|
except KeyError:
|
404
404
|
return None
|
405
|
-
virtual_walls = RandImageData.
|
405
|
+
virtual_walls = RandImageData._rrm_valetudo_lines(tmp_data)
|
406
406
|
return virtual_walls
|
407
407
|
|
408
408
|
@staticmethod
|
@@ -495,11 +495,11 @@ class RandImageData:
|
|
495
495
|
return None
|
496
496
|
return seg_ids
|
497
497
|
|
498
|
-
@staticmethod
|
499
|
-
def convert_negative_angle(angle: int) -> int:
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
498
|
+
# @staticmethod
|
499
|
+
# def convert_negative_angle(angle: int) -> int:
|
500
|
+
# """Convert negative angle to positive."""
|
501
|
+
# angle_c = angle % 360 # Ensure angle is within 0-359
|
502
|
+
# if angle_c < 0:
|
503
|
+
# angle_c += 360 # Convert negative angle to positive
|
504
|
+
# angle = angle_c + 180 # add offset
|
505
|
+
# return angle
|
@@ -55,14 +55,13 @@ class ReImageHandler(BaseHandler):
|
|
55
55
|
self.trim_left = None # Trim left
|
56
56
|
self.trim_right = None # Trim right
|
57
57
|
self.trim_up = None # Trim up
|
58
|
-
self.zooming = False # Zooming flag
|
59
58
|
self.file_name = self.shared.file_name # File name
|
60
59
|
self.offset_top = self.shared.offset_top # offset top
|
61
60
|
self.offset_bottom = self.shared.offset_down # offset bottom
|
62
61
|
self.offset_left = self.shared.offset_left # offset left
|
63
62
|
self.offset_right = self.shared.offset_right # offset right
|
64
63
|
self.imd = ImageDraw(self) # Image Draw
|
65
|
-
self.
|
64
|
+
self.crop = AutoCrop(self)
|
66
65
|
|
67
66
|
async def extract_room_properties(
|
68
67
|
self, json_data: JsonType, destinations: JsonType
|
@@ -96,12 +95,7 @@ class ReImageHandler(BaseHandler):
|
|
96
95
|
x_max = self.outlines[id_x][1][0]
|
97
96
|
y_min = self.outlines[id_x][0][1]
|
98
97
|
y_max = self.outlines[id_x][1][1]
|
99
|
-
corners =
|
100
|
-
(x_min, y_min),
|
101
|
-
(x_max, y_min),
|
102
|
-
(x_max, y_max),
|
103
|
-
(x_min, y_max),
|
104
|
-
]
|
98
|
+
corners = self.get_corners(x_max, x_min, y_max, y_min)
|
105
99
|
# rand256 vacuums accept int(room_id) or str(name)
|
106
100
|
# the card will soon support int(room_id) but the camera will send name
|
107
101
|
# this avoids the manual change of the values in the card.
|
@@ -251,30 +245,21 @@ class ReImageHandler(BaseHandler):
|
|
251
245
|
img_np_array = await self.imd.async_draw_robot_on_map(
|
252
246
|
img_np_array, robot_position, robot_position_angle, colors["robot"]
|
253
247
|
)
|
254
|
-
img_np_array = await self.
|
248
|
+
img_np_array = await self.crop.async_auto_trim_and_zoom_image(
|
255
249
|
img_np_array,
|
256
|
-
colors["background"],
|
257
|
-
int(self.shared.margins),
|
258
|
-
int(self.shared.image_rotate),
|
259
|
-
self.zooming,
|
250
|
+
detect_colour=colors["background"],
|
251
|
+
margin_size=int(self.shared.margins),
|
252
|
+
rotate=int(self.shared.image_rotate),
|
253
|
+
zoom=self.zooming,
|
260
254
|
rand256=True,
|
261
255
|
)
|
262
256
|
return img_np_array
|
263
257
|
|
264
258
|
async def _finalize_image(self, pil_img):
|
265
|
-
if (
|
266
|
-
self.
|
267
|
-
|
268
|
-
|
269
|
-
and self.shared.image_zoom_lock_ratio
|
270
|
-
or self.shared.image_aspect_ratio != "None"
|
271
|
-
):
|
272
|
-
width = self.shared.image_ref_width
|
273
|
-
height = self.shared.image_ref_height
|
274
|
-
if self.shared.image_aspect_ratio != "None":
|
275
|
-
pil_img = await self.async_resize_image(
|
276
|
-
pil_img, width, height, self.shared.image_aspect_ratio, True
|
277
|
-
)
|
259
|
+
if self.check_zoom_and_aspect_ratio() :
|
260
|
+
pil_img = await self.async_resize_image(
|
261
|
+
pil_img, self.shared.image_aspect_ratio, True
|
262
|
+
)
|
278
263
|
_LOGGER.debug("%s: Frame Completed.", self.file_name)
|
279
264
|
return pil_img
|
280
265
|
|
File without changes
|
File without changes
|
File without changes
|
{valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/__init__.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/colors.py
RENAMED
File without changes
|
File without changes
|
File without changes
|
{valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/config/shared.py
RENAMED
File without changes
|
{valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/py.typed
RENAMED
File without changes
|
{valetudo_map_parser-0.1.9b8 → valetudo_map_parser-0.1.9b9}/SCR/valetudo_map_parser/reimg_draw.py
RENAMED
File without changes
|