← Back to team overview

sikuli-driver team mailing list archive

[Question #194581]: Creating an image library/patterns in java

 

New question #194581 on Sikuli:
https://answers.launchpad.net/sikuli/+question/194581

I'm pretty new to Java so please bear with me.

I've got a folder where I store all the screenshots that I use for my tests. Rather than defining the patterns one by one like this:

saveLocation = new Pattern("save_location.png") [similarity and offset go here, removed for readability]

I'd like to create all the patterns in one go, so my friend came up with this, though it doesnt work as intended:
	  
	  File folder = new File("D:/SIKULI/library.sikuli/");
	  File[] listOfFiles = folder.listFiles();
	  
	  
	  Pattern pattern[] = new Pattern[listOfFiles.length];
	  for(int i = 0; i < listOfFiles.length; ++i){
		  pattern[i] = new Pattern( listOfFiles[i].getName() );
	  }
 
So what I get for e.g. first image
pattern[0] = new Pattern("D:/SIKULI/library.sikuli/firstimage.png");

What I'd like to get is something like this:
pattern(firstimage) = new Pattern ("D:/SIKULI/library.sikuli/firstimage.png");

____________________________________________________________________________

So I decided to use the HashMap to create:
key = file name 
value = path

import java.io.File;
import java.util.HashMap;
import java.util.Map;

public class ImageMap {

  public static void main(String[] args) {
	  
	  File folder = new File("D:/SIKULI/library.sikuli/");
	  Map<String,String> imageMap = toMap(folder.listFiles());
  }
  
  private static Map<String,String> toMap(File[] table){
	  Map<String,String> imageMap = new HashMap<String, String>();
	  for(int i = 0; i < table.length; i++){
		  imageMap.put(table[i].getName(), table[i].getAbsolutePath());
	  }
	  return imageMap;
  }
}

The output here is:
Key = back.png
Value = D:\SIKULI\library.sikuli\back.png

And the problem here is - how do i go about creating patterns that will take the key as part of their name
Pattern Pattern(Key) = new Pattern(value);

e.g.
Pattern Pattern(Back.png) = new Pattern( "D:\SIKULI\library.sikuli\back.png");

This example obviously wont work but I hope you get what I mean and can help me with this issue! :)

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