dustyroo

fast find

Sep 13th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. start = time()
  2. def pixelFindColor2(match, p_x, p_x_max, p_y, tolerance=0):
  3.     while not p_x == p_x_max:
  4.         p_x += 1
  5.         colour = grab_pixel(p_x, p_y)
  6.         if colour == match:
  7.             print('found match = {} {}'.format((p_x, p_y), colour))
  8.             return p_x, p_y
  9.         if tolerance > 0:
  10.             for index in range(len(colour)):
  11.                 if colour[index]-tolerance > match[index]:
  12.                     print("x{},y{} +t{} mi{}".format(p_x, p_y, colour[index]-tolerance, match[index]))
  13.                     # too high
  14.                     pass
  15.                 elif colour[index]+tolerance < match[index]:
  16.                     print("x{},y{} +t{} mi{}".format(p_x, p_y, colour[index]+tolerance, match[index]))
  17.                     # too low
  18.                     pass
  19.                 else:
  20.                     print('tolerance found match = {} {}'.format((p_x, p_y), colour))
  21.                     return p_x, p_y
  22.     print('Search done no match, retry!')
  23.     return p_x, p_y
  24. x_2, y_2 = pixelFindColor2((121, 174, 98), 1688, 1835, 823, tolerance=30)
  25. # with 10 workers and 20 tasks, with each task being .5 seconds, then the completed job
  26. # is ~1 second using threading. Normally 20 tasks with .5 seconds each would take 10 seconds.
  27. print('Entire job took:',time() - start)
Advertisement
Add Comment
Please, Sign In to add comment