Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def FindColorIn(r,g,b, xmin, xmax, ymin, ymax):
- image = ImageGrab.grab()
- for x in range(xmin, xmax):
- for y in range(ymin,ymax):
- px = image.getpixel((x, y))
- if px[0] == r and px[1] == g and px[2] == b:
- return x, y
- def FindColor(r,g,b):
- image = ImageGrab.grab()
- size = image.size
- pos = FindColorIn(r,g,b, 1, size[0], 1, size[1])
- return pos
- if ((X-X1)^2 + (Y-Y1)^2 + (Z-Z1)^2) <= (Tol^2) then
- ...
- typedef struct {
- unsigned char r, g, b;
- } RGB;
- double ColourDistance(RGB e1, RGB e2)
- {
- long rmean = ( (long)e1.r + (long)e2.r ) / 2;
- long r = (long)e1.r - (long)e2.r;
- long g = (long)e1.g - (long)e2.g;
- long b = (long)e1.b - (long)e2.b;
- return sqrt((((512+rmean)*r*r)>>8) + 4*g*g + (((767-rmean)*b*b)>>8));
- }
- def ColorDistance(rgb1,rgb2):
- '''d = {} distance between two colors(3)'''
- rm = 0.5*(rgb1[0]+rgb2[0])
- d = sum((2+rm,4,3-rm)*(rgb1-rgb2)**2)**0.5
- return d
- >>> import numpy
- >>> rgb1 = numpy.array([1,1,0])
- >>> rgb2 = numpy.array([0,0,0])
- >>> ColorDistance(rgb1,rgb2)
- 2.5495097567963922
- if abs(px[0]- r) <= rtol and
- abs(px[1]- g) <= gtol and
- abs(px[2]- b) <= btol:
- return x, y
- if px[0] == r and px[1] == g and px[2] == b:
- if max(map(lambda a,b: abs(a-b), px, (r,g,b))) < tolerance:
- def eq_with_tolerance(a, b, t):
- return a-t <= b <= a+t
- def FindColorIn(r,g,b, xmin, xmax, ymin, ymax, tolerance=0):
- image = ImageGrab.grab()
- for x in range(xmin, xmax):
- for y in range(ymin,ymax):
- px = image.getpixel((x, y))
- if eq_with_tolerance(r, px[0], tolerance) and eq_with_tolerance(g, px[1], tolerance) and eq_with_tolerance(b, px[2], tolerance):
- return x, y
- def pixelMatchesColor(x, y, expectedRGBColor, tolerance=0):
- r, g, b = screenshot().getpixel((x, y))
- exR, exG, exB = expectedRGBColor
- return (abs(r - exR) <= tolerance) and (abs(g - exG) <= tolerance) and (abs(b - exB) <= tolerance)
- def color_distance(rgb1, rgb2):
- rm = 0.5 * (rgb1[0] + rgb2[0])
- rd = ((2 + rm) * (rgb1[0] - rgb2[0])) ** 2
- gd = (4 * (rgb1[1] - rgb2[1])) ** 2
- bd = ((3 - rm) * (rgb1[2] - rgb2[2])) ** 2
- return (rd + gd + bd) ** 0.5
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement