From 2c4cefd1f8248573aa62581389272cf8ed7a053e Mon Sep 17 00:00:00 2001 From: Zevaryx Date: Sat, 26 Jun 2021 23:25:17 -0600 Subject: [PATCH] Modify ratio calculations to get better accuracy --- jarvis/cogs/image.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/jarvis/cogs/image.py b/jarvis/cogs/image.py index 54cdad2..ec4a459 100644 --- a/jarvis/cogs/image.py +++ b/jarvis/cogs/image.py @@ -67,8 +67,10 @@ class ImageCog(commands.Cog): ratio = tgt_size / size - 0.02 + accuracy = 0.0 # TODO: Optimize to not run multiple times while len(file) > tgt_size: + old_file = file buffer = np.frombuffer(file, dtype=np.uint8) img = cv2.imdecode(buffer, flags=-1) @@ -78,7 +80,12 @@ class ImageCog(commands.Cog): new_img = cv2.resize(img, (width, height)) file = cv2.imencode(".png", new_img)[1].tobytes() - ratio = tgt_size / len(file) - 0.02 + accuracy = (len(file) / tgt_size) * 100 + if accuracy <= 0.50: + file = old_file + ratio = ratio + 0.1 + else: + ratio = tgt_size / len(file) - 0.02 bufio = BytesIO(file) accuracy = (len(file) / tgt_size) * 100