[request] add feature to get pixel color of a captured image

Bug #1251163 reported by RaiMan
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SikuliX
In Progress
Medium
RaiMan

Bug Description

Hi! I'm trying to find colored pixels in a region with this code, but no luck :(
Can someone tell me whats wrong?

def findItemsOfColor():
    area = Region(playground.x + 75,playground.y + 90,600,400)
    area.highlight(1)
    wait(1)
    x = area.x
    y = area.y
    i=0
    while i==0:
        x = x+1
        p = Location(x,y)
        aColor = Color(0x6969FF)
        if myRobot.getPixelColor(p.x, p.y) == aColor:
            print "FOUND ITEM!!!"
            click(x+4,y+4)
            wait(1)
        if x > area.x + area.w:
            print "Searched row"
            x = area.x
            y = y + 1
            if y > area.y + area.h:
                i = 1
                break

RaiMan (raimund-hocke)
Changed in sikuli:
status: New → In Progress
importance: Undecided → High
assignee: nobody → RaiMan (raimund-hocke)
milestone: none → 1.1.0
Revision history for this message
obiwan-92 (obiwan-92) wrote :

from java.awt import Robot
from java.awt import Color
from java.awt import Rectangle

def getListColor(SCREEN, r, g, b):
    i = Robot().createScreenCapture(Rectangle(SCREEN.getX(),
                SCREEN.getY(), SCREEN.getW(), SCREEN.getH()))
    c = Color(r, g, b)
    l = []
    for x in range(0, SCREEN.getW()):
        for y in range(0, SCREEN.getH()):
            if c == Color(i.getRGB(x, y)):
                l.append(Location(x, y))
    return l

# Create your Region
r = Region.create(playground.x + 75,playground.y + 90,600,400)
# call the function (Color : 0x6969FF)
l = getListColor(r, 105, 105, 255)

# Should be work.

Revision history for this message
obiwan-92 (obiwan-92) wrote :

-- @Railman --
Hi !
There is already a bug with this problem (Bug #810301 ).
Is thre any way to link the two bugs together ?
Regards.

Revision history for this message
obiwan-92 (obiwan-92) wrote :

I try to launch your code with some modification :

from java.awt import Color
from java.awt import Robot

def findItemsOfColor():
    area = Region(0,0,600,400)
    area.highlight(1)
    wait(1)
    x = area.x
    y = area.y
    i=0
    while i==0:
        x = x+1
        p = Location(x,y)
        aColor = Color(0x6969FF)
        if Robot().getPixelColor(p.x, p.y) == aColor:
            print "FOUND ITEM!!!"
            click(x+4,y+4)
            wait(1)
        if x > area.x + area.w:
            print "Searched row"
            x = area.x
            y = y + 1
            if y > area.y + area.h:
                i = 1
                break

findItemsOfColor()

---
It's working but it's very slow. It's probably because you ask the color of each pixel directly without using a buffered image.
Try the code I release in #1. It should be faster. The function Robot().createScreenCapture() return a BufferedImage object.

Regards.

RaiMan (raimund-hocke)
Changed in sikuli:
status: In Progress → Fix Committed
RaiMan (raimund-hocke)
Changed in sikuli:
milestone: 1.1.0 → 1.2.0
RaiMan (raimund-hocke)
Changed in sikuli:
importance: High → Medium
status: Fix Committed → In Progress
milestone: 2.0.0 → 2.1.0
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.