Reputation: 349
I am currently working on a AI for minesweeper and I am trying to detect the color of the numbers to see which number is there and I am having trouble finding the exact RGB code of it and when I print it it seems to change by slight amounts I am wondering if there is a way for to detect colors that are very similar to an RGB value? Thanks!
Upvotes: 0
Views: 621
Reputation: 349
The solution was this:
def check_clicked(self, rgb):
ok = str(rgb).replace("(", "").replace(" ", "").replace(")", "").split(",")
r = int(ok[0])
g = int(ok[1])
b = int(ok[2])
r_min = 205
r_max = 220
g_min = 175
g_max = 195
b_min = 145
b_max = 163
r2_min = 225
r2_max = 235
g2_min = 185
g2_max = 205
b2_min = 150
b2_max = 170
if (r >= r_min and r <= r_max and b >= b_min and b <= b_max and g >= g_min and g <= g_max or r >= r2_min and r <= r2_max and b >= b2_min and b <= b2_max and g >= g2_min and g <= g2_max):
self.set_properties(0)
explanation: I could not find the exact RGB value and sometimes they were inconsistent so instead I checked if the minimum/maximum fit in a certain range for each value and this solution worked and didn't create any false positives!
DISCLAIMER: This solution will only work for a single-channeled color.
Upvotes: 1