Programming, Projects, Python, Tutorials

Eye Dropper Color Picker tool in Python using OpenCV

A eye dropper tool also called as color picker is used to pick color from an image.

An image is made of pixels (Read : Anatomy Of a Digital Image) and each pixel has a RGB value, a color picker tool extracts the RGB value of a pixel in an image by hovering the mouse pointer on the image and clicking.

Eye Dropper tool

The eyedropper is one of the default tools of any image manipulation software, it would be fun to make one ourselves and learn how it works.

In this tutorial we will learn how to make a color picker from scratch in python using OpenCV.

Color Picker in OpenCV Python

In this color picker application we will hav 3 windows :

  • Image Window ( to show the sample image )
  • Live Color Update window ( color in the window will update as mouse hover over the sample image)
  • Selected Color Window ( color is selected when user click left mouse button )

After the user picks a color he can save the RGB value of the selected color in a text file by clicking the Right mouse button.

Python Color Picker widows

Color Picker Pseudocode

  • Import the necessary packages cv2 and numpy
  • create 2 np array to store color picker values (color_explore, color_selected)
  • define a function to save the RGB value of selected color in file ( def write_to_file ) (Read: How to write file in python )
  • define a mouse callback function which:
    • update the color value of color explore window on mouse hover
    • update the color value of the selected color window on mouse left click
    • call write_to_file function to write RGB value in file on mouse right click
  • create named window for color_explore, color_selected, sample image
  • read image from path
  • bind mousecall back function with sample image named window ( cv2.setMouseCallback(‘image’,show_color) )
  • use while loop to shoe and refresh the named windows.
Color picker Working Demo

Code For Color Picker in OpenCV python


Stay updated with the latest advancements Explore event, webinars and conferences


Thank you for reading, Happy Learning, drop your suggestion in the comments.

Feel free to follow us on Youtube , Linked In , Instagram

0 0 vote
Article Rating