Linked Questions

Popular Questions

Taking into account slight differences in color

Asked by At

I'm trying to make a simple EV training bot for pokemon black where it checks to see if a lillipup is on the screen via color.

The issue is, sometimes when a lillipup appears, it's ever so slightly different in color (obviously, not a shiny). It can be 1-3 higher or lower in any of the RGB channels which makes it almost impossible to predict.

I've tried doing a simple distance check between them (as if they were 3d coordinates) but it doesn't seem to work no matter how low I make the threshold (it still is triggering when the threshold is 1 and lillipups color is no where on the screen).

Code(Color is the 'default' lillipup color I'm comparing against):

        color = img.getpixel((x,y))
        r1=Color[0]
        r2=color[0]
        g1=Color[1]
        g2=color[1]
        b1=Color[2]
        b2=color[2]            

        d=math.sqrt((r1-r2)^2+(g1-g2)^2+(b1-b2)^2)

Am I doing something wrong here or should I be doing this a different way?

Related Questions