# -*- coding: utf-8 -*-
##------------------------------------------
## Color table 80
## テキスト配色テーブル
## 2021.09.20 Masahiro Izutsu
##------------------------------------------
## color_table80.py
# import処理
import sys
import cv2
import numpy as np
CR_white = (255,255,255)
CR_black = ( 0, 0, 0)
CR_yellow = (255,255, 0)
CR_fuchsia = (255, 0,255)
CR_lime = ( 0,255, 0)
CR_red = (255, 0, 0)
CR_aquq = ( 0,255,255)
CR_silber = (192,192,192)
CR_gray = (128,128,128)
CR_green = ( 0, 80, 0)
CR_teal = (128,128, 0)
CR_maroon = (128, 0, 0)
CR_purple = (128, 0,128)
CR_tomato = (255, 99, 71)
CR_blue = ( 0, 0,255)
CR_navy = ( 0, 0,128)
CR_olive = (128,128, 0)
# ** Text Color White Group **
# CR_green (6)
CR00 = ( 0,102,102)
CR01 = ( 0,102, 51)
CR02 = ( 0,102, 0)
CR03 = ( 51,102,102)
CR04 = ( 51,102, 51)
CR05 = ( 51,102, 0)
# CR_teal (6)
CR06 =( 0,102,255)
CR07 = ( 0,102,204)
CR08 = ( 0,102,153)
CR09 = ( 51, 51,255)
CR10 = ( 51, 51,204)
CR11 = ( 51, 51,153)
# CR_maroon (6)
CR12 = (102,102,102)
CR13 = (102,102, 51)
CR14 = (102,102, 0)
CR15 = (153,102,102)
CR16 = (153,102, 51)
CR17 = (153,102, 0)
# CR_purple (17)
CR18 = (102,102,255)
CR19 = (102,102,204)
CR20 = (102,102,153)
CR21 = (153,102,255)
CR22 = (153,102,204)
CR23 = (153,102,153)
CR24 = (204,102,204)
CR25 = (204,102,153)
CR26 = (204, 51,255)
CR27 = (204, 51,204)
CR28 = (204, 51,153)
CR29 = (153, 0,255)
CR30 = (153, 0,204)
CR31 = (153, 0,153)
CR32 = (204, 0,255)
CR33 = (204, 0,204)
CR34 = (204, 0,153)
# CR_tomato (9)
CR35 = (204,102,102)
CR36 = (204,102, 51)
CR37 = (204,102, 0)
CR38 = (204, 51,102)
CR39 = (204, 51, 51)
CR40 = (204, 51, 0)
CR41 = (204, 0,102)
CR42 = (204, 0, 51)
CR43 = (204, 0, 0)
# CR_blue (12)
CR44 = ( 0, 51,255)
CR45 = ( 0, 51,204)
CR46 = ( 0, 51,153)
CR47 = ( 51, 51,255)
CR48 = ( 51, 51,204)
CR49 = ( 51, 51,153)
CR50 = ( 0, 0,255)
CR51 = ( 0, 0,204)
CR52 = ( 0, 0,153)
CR53 = ( 51, 0,255)
CR54 = ( 51, 0,204)
CR55 = ( 51, 51,153)
# CR_navy (12)
CR56 = ( 51, 0,102)
CR57 = ( 51, 0, 51)
CR58 = ( 51, 0, 0)
CR59 = (102, 0,102)
CR60 = (102, 0, 51)
CR61 = (102, 0, 0)
CR62 = (102, 0,255)
CR63 = (102, 0,204)
CR64 = (102, 0,153)
CR65 = (102, 51,255)
CR66 = (102, 51,204)
CR67 = (102, 51,153)
# CR_olive (12)
CR68 = (153,153, 51)
CR69 = (153,153, 0)
CR70 = (153,153,102)
CR71 = (204,153,102)
CR72 = (204,153, 51)
CR73 = (204,153, 0)
CR74 = (255,102,102)
CR75 = (255,102, 51)
CR76 = (255,102, 0)
CR77 = (204,204,102)
CR78 = (204,204, 51)
CR79 = (204,204, 0)
# 80 Back color table for white text
# [Back color, Border color]
TEXT_COLOR_SET80 = [[CR00, CR_green], # 0
[CR06, CR_teal], # 1
[CR12, CR_maroon], # 2
[CR18, CR_purple], # 3
[CR35, CR_tomato], # 4
[CR44, CR_blue], # 5
[CR56, CR_navy], # 6
[CR68, CR_olive], # 7
[CR01, CR_green], # 8
[CR07, CR_teal], # 9
[CR13, CR_maroon], # 10
[CR19, CR_purple], # 11
[CR36, CR_tomato], # 12
[CR45, CR_blue], # 13
[CR57, CR_navy], # 14
[CR69, CR_olive], # 15
[CR02, CR_green], # 16
[CR08, CR_teal], # 17
[CR14, CR_maroon], # 18
[CR20, CR_purple], # 19
[CR37, CR_tomato], # 20
[CR46, CR_blue], # 21
[CR58, CR_navy], # 22
[CR70, CR_olive], # 23
[CR03, CR_green], # 24
[CR09, CR_teal], # 25
[CR15, CR_maroon], # 26
[CR21, CR_purple], # 27
[CR38, CR_tomato], # 28
[CR47, CR_blue], # 29
[CR59, CR_navy], # 30
[CR71, CR_olive], # 31
[CR04, CR_green], # 32
[CR10, CR_teal], # 33
[CR16, CR_maroon], # 34
[CR22, CR_purple], # 35
[CR39, CR_tomato], # 36
[CR48, CR_blue], # 37
[CR60, CR_navy], # 38
[CR72, CR_olive], # 39
[CR05, CR_green], # 40
[CR11, CR_teal], # 41
[CR17, CR_maroon], # 42
[CR23, CR_purple], # 43
[CR40, CR_tomato], # 44
[CR49, CR_blue], # 45
[CR61, CR_navy], # 46
[CR73, CR_olive], # 47
[CR24, CR_purple], # 48
[CR41, CR_tomato], # 49
[CR50, CR_blue], # 50
[CR62, CR_navy], # 51
[CR74, CR_olive], # 52
[CR25, CR_purple], # 53
[CR42, CR_tomato], # 54
[CR51, CR_blue], # 55
[CR63, CR_navy], # 56
[CR75, CR_olive], # 57
[CR26, CR_purple], # 58
[CR43, CR_tomato], # 59
[CR52, CR_blue], # 60
[CR64, CR_navy], # 61
[CR76, CR_olive], # 62
[CR27, CR_purple], # 63
[CR53, CR_blue], # 64
[CR65, CR_navy], # 65
[CR77, CR_olive], # 66
[CR28, CR_purple], # 67
[CR54, CR_blue], # 68
[CR66, CR_navy], # 69
[CR78, CR_olive], # 70
[CR29, CR_purple], # 71
[CR55, CR_blue], # 72
[CR67, CR_navy], # 73
[CR79, CR_olive], # 74
[CR30, CR_purple], # 75
[CR31, CR_purple], # 76
[CR32, CR_purple], # 77
[CR33, CR_purple], # 78
[CR34, CR_purple]] # 79
def get_back_rgb80(index):
return TEXT_COLOR_SET80[index][0]
def get_boder_rgb80(index):
return TEXT_COLOR_SET80[index][1]
def get_back_bgr80(index):
color = TEXT_COLOR_SET80[index][0]
return (color[2], color[1], color[0])
def get_boder_bgr80(index):
color = TEXT_COLOR_SET80[index][1]
return (color[2], color[1], color[0])
# ** main関数 **
def main():
win_w = 640
win_h = 480
size = np.array([win_h, win_w, 3]) # 縦×横 3チャンネル
# 白ベースの画像を生成
image = np.full(size, (255, 255, 255), dtype=np.uint8)
# 1ピースのサイズ
w = win_w / 10
h = win_h / 8
title = 'ABC'
for hn in range(8):
for wn in range(10):
color_id = hn * 10 + wn
bk_color = get_back_bgr80(color_id)
bd_color = get_boder_bgr80(color_id)
pos1 = (int(wn*w+2), int(hn*h+2))
pos2 = (int(wn*w+w-1-4), int(hn*h+h-1-4))
pos3 = (int(wn*w+8), int(hn*h+h-12))
pos4 = (int(wn*w+8), int(hn*h+h-46))
indx = format(color_id, '02')
# 塗りつぶし
cv2.rectangle(image, pos1, pos2, bk_color, -1)
# 枠線
cv2.rectangle(image, pos1, pos2, bd_color, 2)
# 文字
cv2.putText(image, title, pos3, cv2.FONT_HERSHEY_DUPLEX, fontScale=0.8, color=CR_white, lineType=cv2.LINE_AA)
cv2.putText(image, indx, pos4, cv2.FONT_HERSHEY_DUPLEX, fontScale=0.4, color=CR_white, lineType=cv2.LINE_AA)
window_name = "Color Table80 Test (hit 'q' or 'esc' key to exit)"
cv2.imshow(window_name, image)
while(True):
key = cv2.waitKey(1)
prop_val = cv2.getWindowProperty(window_name, cv2.WND_PROP_ASPECT_RATIO)
if cv2.getWindowProperty(window_name, cv2.WND_PROP_VISIBLE) < 1:
sys.exit(0)
if key == 27 or key == 113 or (prop_val < 0.0): # 'esc' or 'q'
break
cv2.destroyAllWindows()
if __name__ == "__main__":
sys.exit(main())