2023-10-23 14:32:35 +00:00
|
|
|
import cv2
|
|
|
|
import numpy as np
|
2023-10-24 02:46:18 +00:00
|
|
|
from pallete_schema import PalleteSchema
|
2023-10-24 20:45:22 +00:00
|
|
|
from common import convert_color, closest_color, create_colored_image
|
2023-10-23 14:32:35 +00:00
|
|
|
|
|
|
|
class ComparisonComparison:
|
2023-10-23 20:09:08 +00:00
|
|
|
def __init__ (self) :
|
2023-10-24 20:14:56 +00:00
|
|
|
red = [0, 10, 200]
|
|
|
|
green = [5, 250, 5]
|
|
|
|
blue = [240, 0, 20]
|
|
|
|
comp_colors = [red, green, blue]
|
2023-10-24 20:45:22 +00:00
|
|
|
pallete = PalleteSchema('./palletes/printed_pallete.json')
|
2023-10-24 20:14:56 +00:00
|
|
|
colors = self.get_colors(pallete.colors)
|
|
|
|
for cc in comp_colors :
|
2023-10-24 20:45:22 +00:00
|
|
|
ccbgr = convert_color(cc, 'RGB', 'HSV')
|
|
|
|
closest = closest_color(colors, ccbgr)
|
|
|
|
ccbgr = convert_color(cc, 'RGB', 'BGR')
|
|
|
|
#print(f'{convert_color(closest,"BGR","RGB")} for {convert_color(ccbgr,"BGR","RGB")}')
|
|
|
|
original = create_colored_image(100, 100, convert_color(closest, 'HSV', 'BGR'))
|
|
|
|
chosen = create_colored_image(100, 100, ccbgr)
|
|
|
|
combined = np.hstack([original, chosen])
|
|
|
|
cv2.imshow("image", combined)
|
|
|
|
cv2.waitKey(0)
|
2023-10-23 20:09:08 +00:00
|
|
|
|
2023-10-24 20:14:56 +00:00
|
|
|
def get_colors (self, pallete) :
|
|
|
|
colors = []
|
|
|
|
for color in pallete :
|
2023-10-24 20:45:22 +00:00
|
|
|
colors.append(convert_color(color['color'], 'BGR', 'HSV'))
|
2023-10-24 20:14:56 +00:00
|
|
|
return colors
|
2023-10-23 20:09:08 +00:00
|
|
|
|
2023-10-23 14:32:35 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
ComparisonComparison()
|