Modify ratio calculations to get better accuracy
This commit is contained in:
parent
94d0594361
commit
2c4cefd1f8
1 changed files with 8 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue