Смотрите по преобладающему цвету в канале RGB.
Вот пример на коленке:
import os
import matplotlib.pyplot as plt
from matplotlib.pyplot import imshow
import cv2
import numpy
import pytesseract
os.environ['TESSDATA_PREFIX'] = r'C:/Program Files (x86)/Tesseract-OCR/tessdata'
TESS_PATH = r"C:/Program Files (x86)/Tesseract-OCR/tesseract.exe"
pytesseract.pytesseract.tesseract_cmd = TESS_PATH
IMAGE1 = '.\img\Screenshot_9.png'
IMAGE2 = '.\img\Screenshot_10.png'
IMAGE3 = '.\img\Screenshot_11.png'
IMAGE4 = '.\img\Screenshot_12.png'
def detect_color(color):
THRES = 10
if bool(color[2] - color[1] > THRES and color[2] - color[0] > THRES):
return 'red'
if bool(color[1] - color[2] > THRES and color[1] - color[0] > THRES):
return 'green'
if bool(color[0] - color[1] > THRES and color[0] - color[2] > THRES):
return 'blue'
return 'unknown'
plt.rcParams['figure.figsize'] = [15, 7]
f1,ax = plt.subplots(4,2)
for i,im in enumerate([IMAGE1, IMAGE2, IMAGE3, IMAGE4]):
image = cv2.imread(im)
average = image.mean(axis=0).mean(axis=0)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
(thresh, bw) = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY)
print(pytesseract.image_to_string(bw).strip().ljust(60), detect_color(average))
ax[i][0].imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
fillcolor = numpy.full((3, 3, 3), average, dtype=numpy.ubyte)
ax[i][1].imshow(cv2.cvtColor(numpy.full((3, 3, 3), average, dtype=numpy.ubyte), cv2.COLOR_BGR2RGB))