marker_separation/py/comparison_comparison.py

41 lines
1.2 KiB
Python
Raw Normal View History

2023-10-23 14:32:35 +00:00
import cv2
import numpy as np
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) :
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')
color_spaces = ['RGB', 'LAB', 'HSV']
for space in color_spaces :
print(f'Comparing in color space {space}')
colors = self.get_colors(pallete.colors, space)
show = []
for cc in comp_colors :
cccompare = convert_color(cc, 'RGB', space)
closest = closest_color(colors, cccompare)
ccbgr = convert_color(cc, 'RGB', 'BGR')
chosenbgr = convert_color(closest, space, 'BGR')
chosen = create_colored_image(100, 100, chosenbgr)
original = create_colored_image(100, 100, ccbgr)
combined = np.hstack([original, chosen])
show.append(combined)
show = np.vstack(show)
cv2.imshow("image", show)
2023-10-24 20:45:22 +00:00
cv2.waitKey(0)
2023-10-23 20:09:08 +00:00
def get_colors (self, pallete, space) :
colors = []
for color in pallete :
colors.append(convert_color(color['color'], color['space'], space))
return colors
2023-10-23 20:09:08 +00:00
2023-10-23 14:32:35 +00:00
if __name__ == "__main__":
ComparisonComparison()