Update ui.py
Some checks for first run when models are missing, so it doesn't error out with inv_scale_x > 0 in cv2pull/911/head
parent
e862ff1456
commit
2506c5a261
|
@ -696,7 +696,7 @@ def check_and_ignore_nsfw(target, destroy: Callable = None) -> bool:
|
||||||
|
|
||||||
|
|
||||||
def fit_image_to_size(image, width: int, height: int):
|
def fit_image_to_size(image, width: int, height: int):
|
||||||
if width is None and height is None:
|
if width is None or height is None or width <= 0 or height <= 0:
|
||||||
return image
|
return image
|
||||||
h, w, _ = image.shape
|
h, w, _ = image.shape
|
||||||
ratio_h = 0.0
|
ratio_h = 0.0
|
||||||
|
@ -707,6 +707,16 @@ def fit_image_to_size(image, width: int, height: int):
|
||||||
ratio_w = width / w
|
ratio_w = width / w
|
||||||
ratio = max(ratio_w, ratio_h)
|
ratio = max(ratio_w, ratio_h)
|
||||||
new_size = (int(ratio * w), int(ratio * h))
|
new_size = (int(ratio * w), int(ratio * h))
|
||||||
|
ratio_w = width / w
|
||||||
|
ratio_h = height / h
|
||||||
|
# Use the smaller ratio to ensure the image fits within the given dimensions
|
||||||
|
ratio = min(ratio_w, ratio_h)
|
||||||
|
|
||||||
|
# Compute new dimensions, ensuring they're at least 1 pixel
|
||||||
|
new_width = max(1, int(ratio * w))
|
||||||
|
new_height = max(1, int(ratio * h))
|
||||||
|
new_size = (new_width, new_height)
|
||||||
|
|
||||||
return cv2.resize(image, dsize=new_size)
|
return cv2.resize(image, dsize=new_size)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1199,4 +1209,4 @@ def update_webcam_target(
|
||||||
target_label_dict_live[button_num] = target_image
|
target_label_dict_live[button_num] = target_image
|
||||||
else:
|
else:
|
||||||
update_pop_live_status("Face could not be detected in last upload!")
|
update_pop_live_status("Face could not be detected in last upload!")
|
||||||
return map
|
return map
|
||||||
|
|
Loading…
Reference in New Issue