mirror of
https://github.com/hacksider/Deep-Live-Cam.git
synced 2025-03-17 13:21:46 +01:00
Merge pull request #911 from nimishgautam/main
Fix cv2 size errors on first run in ui.py
This commit is contained in:
commit
28c4b34db1
@ -696,17 +696,21 @@ def check_and_ignore_nsfw(target, destroy: Callable = None) -> bool:
|
||||
|
||||
|
||||
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
|
||||
h, w, _ = image.shape
|
||||
ratio_h = 0.0
|
||||
ratio_w = 0.0
|
||||
if width > height:
|
||||
ratio_h = height / h
|
||||
else:
|
||||
ratio_w = width / w
|
||||
ratio = max(ratio_w, 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)
|
||||
|
||||
|
||||
@ -1199,4 +1203,4 @@ def update_webcam_target(
|
||||
target_label_dict_live[button_num] = target_image
|
||||
else:
|
||||
update_pop_live_status("Face could not be detected in last upload!")
|
||||
return map
|
||||
return map
|
||||
|
Loading…
x
Reference in New Issue
Block a user