← Back to team overview

sikuli-driver team mailing list archive

Re: [Question #233507]: Cleanest way to search if at least one image of a set is present

 

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

Giuseppe Marullo posted a new comment:
While I am learning Java, here it is

FindAllImages(infolder)

RaiMan, I got the getLastMatch optimization but cannot stand break, so I
left the while...

Hopefully you will have a better implementation on 1.1, in the meantime:

public static boolean FindAllImages(Screen k, String path, Float similarity, int timeout) {
    int result;
    
    File pathimages = new File(path);
    File [] files = pathimages.listFiles();
    
    boolean iconfound = false;
    Integer i = 0;
    try{
      
      while ( (i < files.length) && (iconfound == false )) { 
        Pattern ccleanericon = new Pattern(files[i].getAbsolutePath());
        
        if (k.exists(ccleanericon.similar(similarity),timeout)!= null) {
          System.out.println("Found " + files[i].getAbsolutePath() );
          Match m = k.getLastMatch();
          m.highlight(2);        
          k.doubleClick(ccleanericon);
          iconfound = true;
        }
        else {
          System.out.println("Not Found " + files[i].getAbsolutePath());
        }        
        i = i + 1;
      } // end of while      
    }
    catch(FindFailed e){
      e.printStackTrace();
    }
    return iconfound;   
  }
  
Cheers!

Giuseppe Marullo

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