marker_separation/py/comparison_comparison.py

41 lines
1.2 KiB
Python

import cv2
import numpy as np
from pallete_schema import PalleteSchema
from common import convert_color, closest_color, create_colored_image
class ComparisonComparison:
def __init__ (self) :
red = [0, 10, 200]
green = [5, 250, 5]
blue = [240, 0, 20]
comp_colors = [red, green, blue]
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)
cv2.waitKey(0)
def get_colors (self, pallete, space) :
colors = []
for color in pallete :
colors.append(convert_color(color['color'], color['space'], space))
return colors
if __name__ == "__main__":
ComparisonComparison()