customizing how an observer finds an event
Hi, I would like to use observer to find images based on color. I am using the java code from user aguelle for finding a match by color and the example java code from RaiMan for observers. Code for both methods is below.
The custom class MinSimColoredScreen from aguelle that extends Screen overrides the following methods:
<PatternOrString> Match wait(PatternOrS
Observer getObserver()
I assumed when I called onAppear and observeInBackground from a MinSimColoredScreen instance, that observe would use the wait method from MinSimColoredSc
btw, Sikuli is great, thanks RaiMan!
Josh
---
/**
* This class implements support for colored pattern matching if similarity has
* to be quite low.
*
* @author aguelle
*
*/
public class MinSimColoredScreen extends Screen {
public MinSimColoredSc
super();
}
/**
* Constructor
*
* @param searchRegion
* The search region
*/
public MinSimColoredSc
}
static Logger log = Logger.
private final double MAX_COLOR_
private Region searchRegion;
@Override
public <PatternOrString> Match wait(PatternOrS
throws FindFailed {
long startingTime = System.
long timeoutMS = (long) (timeout * 1000);
boolean found = false;
Match match = null;
long usedTime = 0;
Color colorFoundImage = null;
Color colorTargetImage = null;
double colorDifference = -1;
while (usedTime < timeoutMS && found == false) {
match = super.wait(target, timeout);
try {
} catch (InterruptedExc
}
// take screenshot of found region
try {
} catch (AWTException e) {
}
// compare average colors of target image and screenshot of the
// found region
if (colorDifference <= MAX_COLOR_
}
}
if (!found) {
throw new FindFailed("Color does not match");
}
return match;
}
/**
* Sets the search region for the screen
*
* @param searchRegion
* The search region
*/
public void setSearchRegion
}
public Region getSearchRegion() {
return searchRegion;
}
@Override
public Observer getObserver() {
return super.getObserv
}
}
---
public class Example {
public Example() {}
//a helper for the formatted printout:
private static void p(String msg, Object... args) {
}
//the example:
private void findColor() {
String orange = "orange.png";
Region reg = new Region(0, 0, 880, 580); // define the observed region
public void appeared(
if (evt.isAppear()) {
} else {
}
}
});
int n = 0;
while (minSimColoredS
p("%d - observing", n);
n++;
}
}
public static void main(String args[]) {
Example example = new Example();
}
}
Question information
- Language:
- English Edit question
- Status:
- Solved
- For:
- SikuliX Edit question
- Assignee:
- No assignee Edit question
- Solved by:
- RaiMan
- Solved:
- Last query:
- Last reply: