Package: fast-color-checker
A couple of fast algorithms for counting and locating colors in picturesGet all coordinates of a certain color in your picture$pipinstallfast-color-checkerfromfast_color_checkerimportColorCheckpic=ColorCheck(r"https://www.python.org/static/opengraph-icon-200x200.png")x0,y0,xy0=pic.get_coords_of_color((255,212,59))x0Out[4]:array([164,162,163,164,161,162,163,159,160,161,162,163,158,159,160,161,162,157,158,159,160,161,162,155,156,157,158,159,160,161,154,155,156,157,158,159,160,161,152,153,154,155,156,157,158,159,160,151,152,153,154,155,156,157,158,159,160,149,150,151,152,153,154,155,156,....y0Out[7]:array([117,118,118,118,119,119,119,120,120,120,120,120,121,121,121,121,121,122,122,122,122,122,122,123,123,123,123,123,123,123,124,124,124,124,124,124,124,124,125,125,125,125,125,125,125,125,125,126,126,126....xy0Out[9]:(ifzipxyisTrue)/(NoneifzipxyisFalse)((164,117),(162,118),(163,118),(164,118),(161,119),(162,119),(163,119),(159,120),(160,120),(161,120),(162,120),(163,120),....Parameters:color:Union[str,tuple,list]examplesofvalidinputs:(255,212,59),ffa7d7,#ffa9d9, blackzipxy:bool[50,100,200],[20,120,220]->[(50,20),(100,120),(200,220)](default=True)highlightcolor:Union[None,tuple]=NoneOnlyrelevantifyouwanttoseetheoutputresultswithpic.show_result()examplesofvalidinputs:(255,212,59),ffa7d7,#ffa9d9, black(default=None)Returns:tuple(allxcoordinates,allycoordinates,zippedx,ycoordinates/None)Get all coordinates of a certain color range in your picturepic=ColorCheck(r"https://www.python.org/static/opengraph-icon-200x200.png")each_color_detailed1,sum_1=pic.get_coords_of_color_range(start=(255,215,60),end='#FFE262',highlightcolor=(255,0,255))#result https://github.com/hansalemaos/screenshots/raw/main/colorfind2.pngeach_color_detailed1....((255,210,60),()),((255,211,55),()),((255,211,56),()),((255,211,57),()),((255,211,58),()),((255,211,59),()),((255,211,60),()),((255,212,55),()),((255,212,56),()),((255,212,57),()),((255,212,58),()),((255,212,59),((164,117),(162,118),(163,118),(164,118),(161,119),(162,119),(163,119),(159,120),(160,120),(161,120),(162,120),(163,120),....sum1...(132,125),(130,126),(131,126),(129,127),(130,127),(128,128),(126,129),(127,129),(125,130),(123,131),(124,131),(115,137),(113,138),(114,138),(112,139),(110,140),(111,140),...Parameters:start:Union[str,tuple,list]startofthecolorrangeexamplesofvalidinputs:(255,212,59),ffa7d7,#ffa9d9, blackend:Union[str,tuple,list]endofthecolorrangeexamplesofvalidinputs:(255,212,59),ffa7d7,#ffa9d9, blackhighlightcolor:Union[None,tuple]=NoneOnlyrelevantifyouwanttoseetheoutputresultswithpic.show_result()examplesofvalidinputs:(255,212,59),ffa7d7,#ffa9d9, black(default=None)Returns:tuple(allxcoordinates,allycoordinates,zippedx,ycoordinates/None)Count how often a certain color is presentCounthowoftenacertaincolorispresentpic=ColorCheck(r"https://www.python.org/static/opengraph-icon-200x200.png")pic.count_color((255,212,59))Out[12]:477Parameters:color:Union[str,tuple,list]examplesofvalidinputs:(255,212,59),ffa7d7,#ffa9d9, blackReturns:intCount how often the colors of a certain color range are presentCounthowoftenthecolorsofacertaincolorrangearepresentpic=ColorCheck(r"https://www.python.org/static/opengraph-icon-200x200.png")each_color_detailed,sum_=pic.count_color_range(start=(255,215,60),end="FFE262")sum_Out[5]:2976each_color_detailedOut[6]:[((255,215,60),0),((255,215,61),0),((255,215,62),0),((255,215,63),0),((255,215,64),0),((255,215,65),0),((255,215,66),48),((255,215,67),69),((255,215,68),87),((255,215,69),19),...Parameters:start:Union[str,tuple,list]startofthecolorrangeexamplesofvalidinputs:(255,212,59),ffa7d7,#ffa9d9, blackend:Union[str,tuple,list]endofthecolorrangeexamplesofvalidinputs:(255,212,59),ffa7d7,#ffa9d9, blackReturns:tupleGet all colors in an imagepic=ColorCheck(r"https://www.python.org/static/opengraph-icon-200x200.png")pic.get_all_colors_in_image()((0,0,0),(77,64,18),(80,66,18),(83,69,20),(86,72,20),(87,72,20),(88,73,20),(77,66,21),(73,63,23),(81,70,26),(118,98,27),...Count all colorspic.count_all_colors()Out[4]:[((0,0,0),27515),((77,64,18),1),((80,66,18),1),((83,69,20),1),((86,72,20),1),((87,72,20),1),((88,73,20),1),((77,66,21),1),...Limit search regionLimitsearchtoacertainregionofthepicturepic=ColorCheck(r"https://www.python.org/static/opengraph-icon-200x200.png")pic.crop_imageselection((100,100),(150,150))each_color_detailed1,sum_1=pic.get_coords_of_color_range(start=(255,215,60),end="#FFE262",highlightcolor=(255,0,255))pic.reset_cropped_imageselection()x1,y1,xy1=pic.get_coords_of_color((255,212,59),zipxy=False,highlightcolor=(255,0,0))pic.show_result()#result: https://github.com/hansalemaos/screenshots/raw/main/colorfind4.pngParameters:start:tuplex,ycoordinatesend:tuplex,ycoordinatesReturns:selfReset limited search regionpic.reset_cropped_imageselection()Show resultspic.show_result()ShowresultsParameters:window_name:strOpenCVwindowtitle(default="")quit_key:strKeytocloseOpenCVwindow(default="q")Returns:self