0

I'm looking for a better and "deeper" method of scanning my screen for certain images. In my case I am automating online processes and the current method I have for scanning my screen and looking for the "box" is this

private boolean boxChecker() {
    Robot iris = null;
    data.boxFound = false;
    try{
        iris = new Robot();
    }catch (Exception e){}

    System.out.println("flash");
    BufferedImage TestShot = iris.createScreenCapture(new Rectangle(0,0,width,height));

    // finding points
    boolean FoundPoint = false;
    int FirstX = 0;
    int FirstY = 0;        
    int tempx = (int)width/2 ;
    int tempy = 60;
    tan = 0;
    grey = TestShot.getRGB(tempx, tempy);
    black = 0; 
    System.out.println("before i start, tempx is "+tempx+" and tempy is "+tempy);
    try{

    do{
        int colour = TestShot.getRGB(tempx, tempy);
        if (colour != grey ){ // this is the first point here!!
            System.out.println("the first point is at "+tempx+" by "+tempy);
            tan = colour;
            FirstX = tempx;
            FirstY = tempy;
            FoundPoint = true;
        }
        else{
            tempy++;
        }

    } while(!FoundPoint);

    FoundPoint = false;
    do{
        int colour = TestShot.getRGB(tempx, tempy);

        if (colour == grey ){ // this is the second point here!!
            tempx++;
            System.out.println("the second point is at "+tempx+" by "+tempy);
            FoundPoint = true;

        }
        else{
            tempx--;
        }
    } while(!FoundPoint);

    FoundPoint = false;
    do{ // this is for the third point
        int colour = TestShot.getRGB(tempx, tempy);
        if (colour != tan ){ // this is the third point here!!
            black = colour;
            System.out.println("the third point is at "+tempx+" by "+tempy);
            FoundPoint = true;
        }
        else{
            tempy++;
        }
    } while(!FoundPoint);

    FoundPoint = false;
    do{
        int colour = TestShot.getRGB(tempx, tempy);

        if (colour == grey ){ // this is the fourth point here!!
            tempx--;
            System.out.println("the fourth point is at "+tempx+" by "+tempy);
            FoundPoint = true;

        }
        else{
            tempx++;
        }
    } while(!FoundPoint);

    FoundPoint = false;
    do{
        int colour = TestShot.getRGB(tempx, tempy);
        if (colour == grey ){ // this is the fifth point here!!
            tempy++;
            System.out.println("the fifth point is at "+tempx+" by "+tempy);
            FoundPoint = true;
        }
        else{
            tempy--;
        }
    } while(!FoundPoint);

    FoundPoint = false;
    do{
        if (FirstX == tempx && FirstY == tempy ){ // this is the sixth point here!!
            System.out.println("the sixth point is at "+tempx+" by "+tempy);
            FoundPoint = true;
        }
        else{
            tempx--;
        }
    } while(!FoundPoint);

    data.boxFound = true;
    return true;
    } catch (Exception e){
        System.err.println("wrong screen bro");
        data.boxFound = false;
        return false;
    }
}

Now I know this is a horrible way of doing this because it is dependant on the screen and everything but thats why I need a better way of doing it.

Just as a note, this does work for my program as it is.

  • In what way do you want to improve it? Do you want a different way of capturing the screen? or do you want a better way of analyzing the image (such as higher-level stuff than for-loops over pixels)? – migle Jun 07 '13 at 20:37
  • What I would like is that it not to be screen dependant. If I run this program on one screen blue is -16777088 while on another screen its a different number (albeit a slightly different number). To answer your question migle, I would like a better way of capturing the screen and/or a better way of analyzing. Perhaps a more efficient way also, although the efficiency is not a big deal as it is already very fast – Joel Newman Jun 07 '13 at 21:51

0 Answers0