

{"id":73759,"date":"2019-12-24T12:34:10","date_gmt":"2019-12-24T07:04:10","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=73759"},"modified":"2025-07-29T20:56:02","modified_gmt":"2025-07-29T15:26:02","slug":"project-in-python-colour-detection","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/","title":{"rendered":"Project in Python &#8211; Colour Detection using Pandas &amp; OpenCV"},"content":{"rendered":"<div class='__iawmlf-post-loop-links' style='display:none;' data-iawmlf-post-links='[{&quot;id&quot;:1271,&quot;href&quot;:&quot;https:\\\/\\\/github.com\\\/codebrainz\\\/color-names\\\/blob\\\/master\\\/output\\\/colors.csv&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20250313125925\\\/https:\\\/\\\/github.com\\\/codebrainz\\\/color-names\\\/blob\\\/master\\\/output\\\/colors.csv&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2025-12-09 04:26:09&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2025-12-12 04:48:07&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2025-12-15 06:33:20&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-18 06:59:25&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2025-12-21 11:02:10&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-24 12:10:55&quot;,&quot;http_code&quot;:503},{&quot;date&quot;:&quot;2025-12-27 15:35:44&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2025-12-31 00:58:05&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-03 04:05:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-06 04:09:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-09 05:11:40&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-01-12 07:26:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-15 08:04:39&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-01-18 17:26:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-21 19:12:33&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-24 21:19:57&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-01-28 02:26:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-01-31 08:23:44&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-02-03 08:40:01&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-02-06 08:40:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-09 11:08:29&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-12 12:31:21&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-02-15 17:07:07&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-18 17:28:18&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-02-21 18:50:53&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-25 01:57:19&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-02-28 09:31:54&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-03 09:45:22&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-06 13:45:56&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-09 14:52:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-12 15:10:44&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-15 15:26:06&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-18 17:37:28&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-21 20:39:45&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-25 05:22:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-03-28 05:51:49&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-03-31 08:56:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-03 09:56:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-06 10:57:48&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-04-09 16:42:32&quot;,&quot;http_code&quot;:404},{&quot;date&quot;:&quot;2026-04-12 16:42:36&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-16 06:25:57&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-19 08:04:09&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-04-22 09:25:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-25 10:21:37&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-04-28 11:28:24&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-05-01 18:34:52&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-05 05:08:02&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-08 09:01:45&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-11 09:44:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-14 12:55:26&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-17 17:38:31&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-20 21:48:48&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-24 03:48:21&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-27 07:08:51&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-05-30 08:19:42&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-06-02 08:52:54&quot;,&quot;http_code&quot;:429},{&quot;date&quot;:&quot;2026-06-05 10:36:15&quot;,&quot;http_code&quot;:206},{&quot;date&quot;:&quot;2026-06-08 14:06:28&quot;,&quot;http_code&quot;:404}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-08 14:06:28&quot;,&quot;http_code&quot;:404},&quot;process&quot;:&quot;done&quot;},{&quot;id&quot;:1272,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/open?id=1pbiX55FY0ohdlGfLyed0SDZ6vGQPKNkW&quot;,&quot;archived_href&quot;:&quot;&quot;,&quot;redirect_href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1pbiX55FY0ohdlGfLyed0SDZ6vGQPKNkW\\\/view?usp=drive_open&quot;,&quot;checks&quot;:[],&quot;broken&quot;:false,&quot;last_checked&quot;:null,&quot;process&quot;:&quot;done&quot;}]'><\/div>\n<p><strong>Python Project on Color Detection<\/strong><\/p>\n<p>Today\u2019s project will be exciting and fun to build. We will be working with colors and you will get to learn about many concepts throughout this project. Colour detection is necessary to recognize objects, it is also used as a tool in various image editing and drawing apps.<\/p>\n<p>This is the 10th project in the DataFlair&#8217;s series of 20 Python projects. I suggest you to bookmark the previous projects:<\/p>\n<ol>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/advanced-python-project-detecting-fake-news\/\">Fake News Detection Python Project<\/a><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-machine-learning-project-detecting-parkinson-disease\/\">Parkinson\u2019s Disease Detection Python Project<\/a><\/li>\n<li>Color Detection Python Project<\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-mini-project-speech-emotion-recognition\/\">Speech Emotion Recognition Python Project<\/a><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/project-in-python-breast-cancer-classification\/\">Breast Cancer Classification Python Project<\/a><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-project-gender-age-detection\/\">Age and Gender Detection Python Project<\/a><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-deep-learning-project-handwritten-digit-recognition\/\">Handwritten Digit Recognition Python Project<\/a><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-chatbot-project\/\">Chatbot Python Project<\/a><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-project-driver-drowsiness-detection-system\/\">Driver Drowsiness Detection Python Project<\/a><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-project-traffic-signs-recognition\/\">Traffic Signs Recognition Python Project<\/a><\/li>\n<li><a href=\"https:\/\/data-flair.training\/blogs\/python-based-project-image-caption-generator-cnn\/\">Image Caption Generator Python Project<\/a><\/li>\n<\/ol>\n<h3>What is Colour Detection?<\/h3>\n<p>Colour detection is the process of detecting the name of any color. Simple isn\u2019t it? Well, for humans this is an extremely easy task but for computers, it is not straightforward. Human eyes and brains work together to translate light into color. Light receptors that are present in our eyes transmit the signal to the brain. Our brain then recognizes the color. Since childhood, we have mapped certain lights with their color names. We will be using the somewhat same strategy to detect color names.<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/color-detection-python-project.gif\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-73983\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/color-detection-python-project.gif\" alt=\"color detection project in python\" width=\"1350\" height=\"720\" \/><\/a><\/p>\n<h3>About the Python Project<\/h3>\n<p>In this color detection Python project, we are going to build an application through which you can automatically get the name of the color by clicking on them.\u00a0So for this, we will have a data file that contains the color name and its values. Then we will calculate the distance from each color and find the shortest one.<\/p>\n<h3>The Dataset<\/h3>\n<p>Colors are made up of 3 primary colors; red, green, and blue. In computers, we define each color value within a range of 0 to 255. So in how many ways we can define a color? The answer is 256*256*256 = 16,581,375. There are approximately 16.5 million different ways to represent a color. In our dataset, we need to map each color&#8217;s values with their corresponding names. But don\u2019t worry, we don\u2019t need to map all the values. We will be using a dataset that contains RGB values with their corresponding names. The CSV file for our dataset has been taken from this link:<\/p>\n<p><strong><a href=\"https:\/\/github.com\/codebrainz\/color-names\/blob\/master\/output\/colors.csv\">Colors Dataset<\/a><\/strong><\/p>\n<p>The colors.csv file includes 865 color names along with their RGB and hex values.<\/p>\n<h3>Prerequisites<\/h3>\n<p>Before starting with this Python project with source code, you should be familiar with the computer vision library of Python that is <a href=\"https:\/\/data-flair.training\/blogs\/opencv-python-tutorial\/\"><em><strong>OpenCV<\/strong><\/em><\/a> and <a href=\"https:\/\/data-flair.training\/blogs\/pandas-tutorials-home\/\"><em><strong>Pandas<\/strong><\/em><\/a>.<\/p>\n<p>OpenCV, Pandas, and numpy are the Python packages that are necessary for this project in Python. To install them, simply run this pip command in your terminal:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">pip install opencv-python numpy pandas<\/pre>\n<h3>Steps for Building a Project in\u00a0Python &#8211; Color Detection<\/h3>\n<p>Here are the steps to build an application in Python that can detect colors:<\/p>\n<h3>1. Download and unzip the zip file<\/h3>\n<p><a href=\"https:\/\/drive.google.com\/open?id=1pbiX55FY0ohdlGfLyed0SDZ6vGQPKNkW\">Color Detection Zip File<\/a><\/p>\n<p>The project folder contains 3 files:<\/p>\n<ul>\n<li><strong>Color_detection.py<\/strong> &#8211; main source code of our project.<\/li>\n<li><strong>Colorpic.jpg<\/strong> &#8211;\u00a0sample image for experimenting.<\/li>\n<li><strong>Colors.csv<\/strong> &#8211; a file that contains our dataset.<\/li>\n<\/ul>\n<h3>2. Taking an image from the user<\/h3>\n<p>We are using argparse library to create an argument parser. We can directly give an image path from the command prompt:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">import argparse\r\n\r\nap = argparse.ArgumentParser()\r\nap.add_argument('-i', '--image', required=True, help=\"Image Path\")\r\nargs = vars(ap.parse_args())\r\nimg_path = args['image']\r\n#Reading image with opencv\r\nimg = cv2.imread(img_path)<\/pre>\n<h3>3. Next, we read the CSV file with pandas<\/h3>\n<p>The pandas library is very useful when we need to perform various operations on data files like CSV. <strong>pd.read_csv()<\/strong> reads the CSV file and loads it into the pandas DataFrame. We have assigned each column with a name for easy accessing.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">#Reading csv file with pandas and giving names to each column\r\nindex=[\"color\",\"color_name\",\"hex\",\"R\",\"G\",\"B\"]\r\ncsv = pd.read_csv('colors.csv', names=index, header=None)<\/pre>\n<h3>4. Set a mouse callback event on a window<\/h3>\n<p>First, we created a window in which the input image will display. Then, we set a callback function which will be called when a mouse event happens.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">cv2.namedWindow('image')\r\ncv2.setMouseCallback('image',draw_function)<\/pre>\n<p>With these lines, we named our window as \u2018image\u2019 and set a callback function which will call the <strong>draw_function()<\/strong> whenever a mouse event occurs.<\/p>\n<p class=\"df-text-bold df-text-black\" style=\"text-align: center\">Want to revise the Python concepts?<\/p>\n<p class=\"df-text-bold\" style=\"text-align: center\">Check out <a href=\"https:\/\/data-flair.training\/blogs\/python-tutorials-home\/\">270+ Python Tutorials<\/a> &amp; brush up your basics<\/p>\n<h3>5. Create the draw_function<\/h3>\n<p>It will calculate the rgb values of the pixel which we double click. The function parameters have the event name, (x,y) coordinates of the mouse position, etc. In the function, we check if the event is double-clicked then we calculate and set the r,g,b values along with x,y positions of the mouse.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">def draw_function(event, x,y,flags,param):\r\n    if event == cv2.EVENT_LBUTTONDBLCLK:\r\n        global b,g,r,xpos,ypos, clicked\r\n        clicked = True\r\n        xpos = x\r\n        ypos = y\r\n        b,g,r = img[y,x]\r\n        b = int(b)\r\n        g = int(g)\r\n        r = int(r)<\/pre>\n<h3>6. Calculate distance to get color name<\/h3>\n<p>We have the r,g and b values. Now, we need another function which will return us the color name from RGB values. To get the color name, we calculate a distance(d) which tells us how close we are to color and choose the one having minimum distance.<\/p>\n<p>Our distance is calculated by this formula:<\/p>\n<p><em>d = abs(Red &#8211; ithRedColor) + (Green &#8211; ithGreenColor) + (Blue &#8211; ithBlueColor)<\/em><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">def getColorName(R,G,B):\r\n    minimum = 10000\r\n    for i in range(len(csv)):\r\n        d = abs(R- int(csv.loc[i,\"R\"])) + abs(G- int(csv.loc[i,\"G\"]))+ abs(B- int(csv.loc[i,\"B\"]))\r\n        if(d&lt;=minimum):\r\n            minimum = d\r\n            cname = csv.loc[i,\"color_name\"]\r\n    return cname<\/pre>\n<h3>7. Display image on the window<\/h3>\n<p>Whenever a double click event occurs, it will update the color name and RGB values on the window.<\/p>\n<p>Using the <strong>cv2.imshow()<\/strong> function, we draw the image on the window. When the user double clicks the window, we draw a rectangle and get the color name to draw text on the window using <strong>cv2.rectangle<\/strong> and <strong>cv2.putText()<\/strong> functions.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">while(1):\r\n    cv2.imshow(\"image\",img)\r\n    if (clicked):\r\n        #cv2.rectangle(image, startpoint, endpoint, color, thickness) -1 thickness fills rectangle entirely\r\n        cv2.rectangle(img,(20,20), (750,60), (b,g,r), -1)\r\n\r\n        #Creating text string to display ( Color name and RGB values )\r\n        text = getColorName(r,g,b) + ' R='+ str(r) + ' G='+ str(g) + ' B='+ str(b)\r\n\r\n        #cv2.putText(img,text,start,font(0-7), fontScale, color, thickness, lineType, (optional bottomLeft bool) )\r\n        cv2.putText(img, text,(50,50),2,0.8,(255,255,255),2,cv2.LINE_AA)\r\n  #For very light colours we will display text in black colour\r\n        if(r+g+b&gt;=600):\r\n            cv2.putText(img, text,(50,50),2,0.8,(0,0,0),2,cv2.LINE_AA)\r\n\r\n        clicked=False\r\n\r\n    #Break the loop when user hits 'esc' key \r\n    if cv2.waitKey(20) &amp; 0xFF ==27:\r\n        break\r\n\r\ncv2.destroyAllWindows()<\/pre>\n<h3>8. Run Python File<\/h3>\n<p>The beginner Python project is now complete, you can run the Python file from the command prompt. Make sure to give an image path using &#8216;-i&#8217; argument. If the image is in another directory, then you need to give full path of the image:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"null\">python color_detection.py -i &lt;add your image path here&gt;<\/pre>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/running-python-project.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-73970\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/running-python-project.png\" alt=\"running python mini project\" width=\"979\" height=\"572\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/running-python-project.png 979w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/running-python-project-150x88.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/running-python-project-300x175.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/running-python-project-768x449.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/running-python-project-520x304.png 520w\" sizes=\"auto, (max-width: 979px) 100vw, 979px\" \/><\/a><\/p>\n<p><strong>Screenshots:<\/strong><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/import-cv2.png\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-73971 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/import-cv2.png\" alt=\"import cv2 - python mini project\" width=\"1366\" height=\"545\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/import-cv2.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/import-cv2-150x60.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/import-cv2-300x120.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/import-cv2-768x306.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/import-cv2-1024x409.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/import-cv2-520x207.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/def-getColorName-project-in-python.png\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-73973 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/def-getColorName-project-in-python.png\" alt=\"def getColorName - project in python\" width=\"1366\" height=\"622\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/def-getColorName-project-in-python.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/def-getColorName-project-in-python-150x68.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/def-getColorName-project-in-python-300x137.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/def-getColorName-project-in-python-768x350.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/def-getColorName-project-in-python-1024x466.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/def-getColorName-project-in-python-520x237.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/while-1-python-data-science-project.png\"><img loading=\"lazy\" decoding=\"async\" class=\"img-gray-border aligncenter wp-image-73974 size-full\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/while-1-python-data-science-project.png\" alt=\"while (1) python data science project\" width=\"1366\" height=\"631\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/while-1-python-data-science-project.png 1366w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/while-1-python-data-science-project-150x69.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/while-1-python-data-science-project-300x139.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/while-1-python-data-science-project-768x355.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/while-1-python-data-science-project-1024x473.png 1024w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/while-1-python-data-science-project-520x240.png 520w\" sizes=\"auto, (max-width: 1366px) 100vw, 1366px\" \/><\/a><\/p>\n<p><strong>Output:<\/strong><\/p>\n<p>Double click on the window to know the name of the pixel color<\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/red-color-detection-python-mini-project.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-73975\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/red-color-detection-python-mini-project.png\" alt=\"red color detection - python mini project\" width=\"804\" height=\"557\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/red-color-detection-python-mini-project.png 804w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/red-color-detection-python-mini-project-150x104.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/red-color-detection-python-mini-project-300x208.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/red-color-detection-python-mini-project-768x532.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/red-color-detection-python-mini-project-520x360.png 520w\" sizes=\"auto, (max-width: 804px) 100vw, 804px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/yellow-color-detection-python-project-with-source-code.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-73976\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/yellow-color-detection-python-project-with-source-code.png\" alt=\"yellow color detection - python project with source code\" width=\"804\" height=\"556\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/yellow-color-detection-python-project-with-source-code.png 804w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/yellow-color-detection-python-project-with-source-code-150x104.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/yellow-color-detection-python-project-with-source-code-300x207.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/yellow-color-detection-python-project-with-source-code-768x531.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/yellow-color-detection-python-project-with-source-code-520x360.png 520w\" sizes=\"auto, (max-width: 804px) 100vw, 804px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/blue-color-detection-python-project.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-73977\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/blue-color-detection-python-project.png\" alt=\"blue color detection - python mini project\" width=\"803\" height=\"556\" srcset=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/blue-color-detection-python-project.png 803w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/blue-color-detection-python-project-150x104.png 150w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/blue-color-detection-python-project-300x208.png 300w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/blue-color-detection-python-project-768x532.png 768w, https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/blue-color-detection-python-project-520x360.png 520w\" sizes=\"auto, (max-width: 803px) 100vw, 803px\" \/><\/a><\/p>\n<h3>Summary<\/h3>\n<p>Detecting colors from images is useful in design, games, and tools. In this project, we click on any part of an image and it shows the name of the color. It\u2019s built using Python, OpenCV, and a CSV file containing color names.<\/p>\n<p>In this Python project with source code, we learned about colors and how we can extract color RGB values and the color name of a pixel. We learned how to handle events like double-clicking on the window and saw how to read CSV files with pandas and perform operations on data. This is used in numerous image editing and drawing apps.<\/p>\n<p>This project is very useful for creative tools and color pickers. It teaches event handling, color processing, and using CSV data with OpenCV. It\u2019s simple, useful, and perfect for beginners.<\/p>\n<p class=\"df-text-bold df-text-black\" style=\"text-align: center\">Want to prepare for your Python interview?<\/p>\n<p class=\"df-text-bold\" style=\"text-align: center\">Practice <a href=\"https:\/\/data-flair.training\/blogs\/top-python-interview-questions-answer\/\">150+ Python Interview Questions<\/a> &amp; get hired as Python expert<\/p>\n<p>Hope you enjoyed building this project and keep visiting for more cool projects.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python Project on Color Detection Today\u2019s project will be exciting and fun to build. We will be working with colors and you will get to learn about many concepts throughout this project. Colour detection&#46;&#46;&#46;<\/p>\n","protected":false},"author":7,"featured_media":73985,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[21063,21581,21582,21081,21082,21584,21583,21099],"class_list":["post-73759","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-machine-learning","tag-beginner-python-project","tag-color-detection","tag-project-in-python","tag-python-mini-project","tag-python-project","tag-python-project-example","tag-python-project-idea","tag-python-project-with-source-code"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Project in Python - Colour Detection using Pandas &amp; OpenCV - DataFlair<\/title>\n<meta name=\"description\" content=\"Python project on color detection - Learn to build an application that can detect the type of color by clicking on it with this interesting project in python using opencv &amp; pandas.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Project in Python - Colour Detection using Pandas &amp; OpenCV - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Python project on color detection - Learn to build an application that can detect the type of color by clicking on it with this interesting project in python using opencv &amp; pandas.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2019-12-24T07:04:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-07-29T15:26:02+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/python-project-on-color-detection.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"802\" \/>\n\t<meta property=\"og:image:height\" content=\"420\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Project in Python - Colour Detection using Pandas &amp; OpenCV - DataFlair","description":"Python project on color detection - Learn to build an application that can detect the type of color by clicking on it with this interesting project in python using opencv & pandas.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/","og_locale":"en_US","og_type":"article","og_title":"Project in Python - Colour Detection using Pandas &amp; OpenCV - DataFlair","og_description":"Python project on color detection - Learn to build an application that can detect the type of color by clicking on it with this interesting project in python using opencv & pandas.","og_url":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2019-12-24T07:04:10+00:00","article_modified_time":"2025-07-29T15:26:02+00:00","og_image":[{"width":802,"height":420,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/python-project-on-color-detection.jpg","type":"image\/jpeg"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd"},"headline":"Project in Python &#8211; Colour Detection using Pandas &amp; OpenCV","datePublished":"2019-12-24T07:04:10+00:00","dateModified":"2025-07-29T15:26:02+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/"},"wordCount":1106,"commentCount":139,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/python-project-on-color-detection.jpg","keywords":["Beginner Python Project","Color Detection","Project in Python","Python mini project","Python project","python project example","python project idea","python project with source code"],"articleSection":["Machine Learning Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/","url":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/","name":"Project in Python - Colour Detection using Pandas &amp; OpenCV - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/python-project-on-color-detection.jpg","datePublished":"2019-12-24T07:04:10+00:00","dateModified":"2025-07-29T15:26:02+00:00","description":"Python project on color detection - Learn to build an application that can detect the type of color by clicking on it with this interesting project in python using opencv & pandas.","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/python-project-on-color-detection.jpg","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2019\/12\/python-project-on-color-detection.jpg","width":802,"height":420,"caption":"project in python on color detection"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/project-in-python-colour-detection\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Machine Learning Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/machine-learning\/"},{"@type":"ListItem","position":3,"name":"Project in Python &#8211; Colour Detection using Pandas &amp; OpenCV"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/beb0cab24b7aa54423a3b50e669a9dcd","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c322416204232f4dd97ef3901b0a499a5d34d7ba7fe333f4bfe53a907873d293?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team specializes in creating clear, actionable content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. Backed by industry expertise, we make learning easy and career-oriented for beginners and pros alike.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam3\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/73759","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=73759"}],"version-history":[{"count":21,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/73759\/revisions"}],"predecessor-version":[{"id":146357,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/73759\/revisions\/146357"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/73985"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=73759"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=73759"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=73759"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}