Last active
December 22, 2020 09:17
-
-
Save Bouni/4d512f27879fca478a8a5b121a90002b to your computer and use it in GitHub Desktop.
Get dominant color from an image and determin the operating state of a decalcifying device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
import sys | |
import os | |
from colorthief import ColorThief | |
from PIL import Image | |
original = Image.open(sys.argv[1]) | |
left = 950 | |
right = left + 50 | |
top = 1200 | |
bottom = top + 50 | |
cropped = original.crop((left, top, right, bottom)) | |
memfile = io.BytesIO() | |
cropped.save(memfile, format="JPEG") | |
color_thief = ColorThief(memfile) | |
dominant_color = color_thief.get_color(quality=1) | |
mode = "unknown" | |
if dominant_color[2] > 200: | |
mode = "normal" | |
if dominant_color[1] > 150: | |
mode = "regeneration" | |
with open("mode.txt", "w") as f: | |
f.write(mode) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment