Find Dominant Common Color With Telegram Bot

Amirhossein Douzandeh
2 min readDec 3, 2022
Find Dominant Common Color With Telegram Bot
Find Dominant Common Color With Telegram Bot

In the last few days, I decided to play with the telegram bot but I need to have a simple scenario for my application so I think “finding the most common colors” can be the best choice for me. So Let’s code:

👋 Initial Step

As a first step, You Need to run the below list of commands to install packages inside your virtual environment which helps you to start coding:

pip install opencv-python numpy matplotlib scikit-learn pyTelegramBotAPI

after that, we have to get the new token from BotFather to connect our application to the telegram. This step is so easy you just need to send a message to the bot that I told you about and follow the steps.

🎨 Color Clustering

To find the most common colors that exist inside a single picture, we need to export all the color codes and then cluster them by clustering algorithms like KMeans. To achieve this goal we use the below script:

🤖 Telegram Bot

Before start processing the images we have to save them in the folder and after that, we can analyze them. Thus, our telegram bot just needs to handle the image inputs and after saving them it must call the above scripts like this:

Finally, I put all of this code in my GitHub profile and if you want to play with it you just need to clone it.

☕ Buy me a coffee

In the end, if you like this medium you can buy me a coffee or more if you like by clicking on the link below:

Buy me a coffee

--

--

Amirhossein Douzandeh

Expert Front-End Developer. Software engineer with a Master of Science in Computer Engineering with a focus in Artificial Intelligent and Robotics.