2

enter image description here

I need to find the name of the color of the car in images in python.

All the techniques I tried to look up always output the color/rgd/hsv/hsl values But I need the Name of the color in text.

I am trying to find a simple straightforward approach no CNNs! Preferably using some library like Pillow/OpenCv etc. in Python

Thanks a ton for your help folks! Any help to point me in right direction is much appreciated!

Miki
  • 40,887
  • 13
  • 123
  • 202
inkarar
  • 85
  • 9
  • Since it sounds like you've already got a rgb value, how about this? https://stackoverflow.com/questions/9694165/convert-rgb-color-to-english-color-name-like-green-with-python – Macattack Oct 22 '21 at 04:44
  • Thanks for quick reply! Yes this doable. But then it becomes a detour. I am looking from an approach that directly gives the Name of the Color. Because then I will only have to check for output of one program. – inkarar Oct 22 '21 at 04:47

1 Answers1

1

You could create a dictionary containing lists.

colorDict = {'blue': ['#0000cd', '#10174f'], 'black': ['#000000'], etc}

Then use a function that iterate's through it to display the color.

def colorFunc(inputHexColor):
    colorStr = None
    colorKeys = colorDict.keys()
    for colorKey in colorKeys:
        colorList = colorDict[colorKey]
        if inputHexColor in colorList:
            colorStr = colorKey
            break
    return colorStr

However it would likely be inefficient creating the dictionary of hex codes.

JB Larson
  • 76
  • 2
  • 15
  • 1
    Thanks for quick reply! I thought of this but since Im going to be dealing with cars. Some colors might not be as straightforward as red, orange, blue, etc. It could be teal, maroon, etc. So its inefficient to create a mapping for every possible color. Thats why Im trying to get the name of the color in text directly from image. – inkarar Oct 22 '21 at 04:55
  • @inkarar The easy way out you want is not possible. *The name is not in the file.* There are more RGB values than colour names, and many borderline cases. So you need a lookup table of RGB values or a function to call that decides which numbers map to which names and which ones are similar enough to get the same name. If you don't want to build your own then you will have find one that someone else has written. – BoarGules Oct 22 '21 at 07:05