<jupyter_start><jupyter_text>Importing Libraries<jupyter_code>import cv2
import pandas as pd<jupyter_output><empty_output><jupyter_text>Reading CSV File and Image<jupyter_code>index=['color','color_name','hex','R','G','B']
df=pd.read_csv('colors.csv',names=index,header=None)
img=cv2.imread('sample.jpg')
img=cv2.resize(img,(800,600))

clicked=False
r=g=b=xpos=ypos=0<jupyter_output><empty_output><jupyter_text>Function to calculate Minimum distance<jupyter_code>def get_color_name(R,G,B):
    minimum=10000
    for i in range(len(df)):
        d=abs(R-int(df.loc[i,'R'])) + abs(G-int(df.loc[i,'G'])) + abs(B-int(df.loc[i,'B']))
        if d<=minimum:
            minimum=d
            cname=df.loc[i,'color_name']
    return cname<jupyter_output><empty_output><jupyter_text>Function to draw<jupyter_code>def draw_function(event,x,y,flags,params):
    if event==cv2.EVENT_LBUTTONDBLCLK:
        global clicked,r,g,b,xpos,ypos
        clicked=True
        xpos=x
        ypos=y
        b,g,r=img[y,x]
        b=int(b)
        g=int(g)
        r=int(r)<jupyter_output><empty_output><jupyter_text>Draw a Rectangle to show output<jupyter_code>cv2.namedWindow("Color Detection")
cv2.setMouseCallback("Color Detection",draw_function)
while True:
    cv2.imshow("Color Detection",img)
    if clicked==True:
        cv2.rectangle(img,(20,20),(600,60),(b,g,r),-1)
        text=get_color_name(r,g,b) + 'R=' + str(r) + 'G=' + str(g) + 'B=' + str(b)
        cv2.putText(img,text,(50,50),2,0.8,(255,255,255),2,cv2.LINE_AA)
        if r+g+b>=600:
            cv2.putText(img,text,(50,50),2,0.8,(0,0,0),2,cv2.LINE_AA)
    if cv2.waitKey(20) & 0xFF ==27:
        break
cv2.destroyAllWindows()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17819460726846426, 'fraction_numerical': 0.04220398593200469, 'mean_word_length': 4.67109634551495, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '583536', 'license': 'MIT', 'n_tokens_mistral': 741, 'n_tokens_neox': 703, 'n_words': 81, 'path': 'Color Identification in Images.ipynb', 'repo_name': 'Divyakathirvel26/Color-Identification-in-Images', 'size': '1706'}