← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #200617]: Get pixel color in region and compare to Color

 

Question #200617 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/200617

    Status: Open => Answered

RaiMan proposed the following answer:
-- the Color class is not needed in this case
-- c = myRobot.getPixelColor(p.x,p.y).getRGB() returns a 32Bit integer value
-- if c == 0x6969FF: should work (as j-the-k mentioned: you can only compare primitive datatypes with == ) 

BTW:
myRobot.getPixelColor()
is a rather "slow" feature: checking 1000 pixels (a region of 33x33 pixels !) might last some seconds. So it is not really applicable for searching pixels. Verifications of single pixels after a find() operation can be done though.

Having this in mind, it is vital to have in the loop only the things, that are really needed.
using a loop with for should be more efficient to.

x = area.x
w = area.w
y = area.y
h = area.h

color = 0x6969FF

# run through pixel rows
for r in range(y, h+1):
    for c in range (x, w+1):
        if myRobot.getPixelColor(p.x,p.y).getRGB() = color:
            # do what should be done

You received this question notification because you are a member of
Sikuli Drivers, which is an answer contact for Sikuli.