

Never take a pill, capsule, or any form of unidentified medication. If this does not display any results, we recommend taking the medication to a pharmacist and asking them to help you identify it. If your search returns a ‘NO RESULT FOUND’ message try one of the other search method fields. Our distance is calculated by this formula:ĭ = abs(Red - ithRedColor) + (Green - ithGreenColor) + (Blue - ithBlueColor) def getColorName(R,G,B): minimum = 10000 for i in range(len(csv)): d = abs(R- int(csv.loc)) + abs(G- int(csv.loc))+ abs(B- int(csv.loc)) if(d=600): cv2.putText(img, text,(50,50),2,0.8,(0,0,0),2,cv2.LINE_AA) clicked=False if cv2.waitKey(20) & 0xFF =27: break cv2.Pill Identifier Example for the drug Adderall XR 5mg What if my search returns no results when using the Drug Genius medication identification tool? 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. Now, we need another function which will return us the color name from RGB values. def draw_function(event, x,y,flags,param): if event = cv2.EVENT_LBUTTONDBLCLK: global b,g,r,xpos,ypos, clicked clicked = True xpos = x ypos = y b,g,r = img b = int(b) g = int(g) r = int(r) 6. 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. The function parameters have the event name, (x,y) coordinates of the mouse position, etc. It will calculate the rgb values of the pixel which we double click. cv2.namedWindow(‘color detection’) cv2.setMouseCallback(‘color detection’,draw_function) 5. Then, we set a callback function which will be called when a mouse event happens. Set a mouse callback event on a windowįirst, we created a window in which the input image will display. index= csv = pd.read_csv(‘colors.csv’, names=index, header=None) 4. We have assigned each column with a name for easy accessing. pd.read_csv() reads the CSV file and loads it into the pandas DataFrame. The pandas library is very useful when we need to perform various operations on data files like CSV. importing required package and load the image import cv2 import numpy as np import pandas as pd img_path = “D://OpenCV//shape-detection//New folder//color palette.jpg” img = cv2.imread(img_path) 3. Colors.csv - a file that contains our data set.Ģ.color palette.jpg - sample image for experimenting.

#Color identifier app code

But don’t worry, we don’t need to map all the values. In our dataset, we need to map each color’s values with their corresponding names. There are approximately 16.5 million different ways to represent a color. So in how many ways we can define a color? The answer is 256*256*256 = 16,581,375. In computers, we define each color value within a range of 0 to 255. The Data setĬolors are made up of 3 primary colors red, green, and blue. Then we will calculate the distance from each color and find the shortest one. So for this, we will have a data file that contains the color name and its values. 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. If you want to jump straight into the code without explanation then you can scroll down to the bottom of this page, where the complete code is provided or click here for GitHub link. Color detection - python project About the Python Project
