[1.0.1] Java: Pattern(BufferedImage) is not found (silently does nothing) --- usage: load images from jar
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SikuliX |
Fix Committed
|
Critical
|
RaiMan |
Bug Description
Hello,
I am a relative newcomer to Java coding and Sikuli both so please keep that in mind as you try to guide me on my way! Also, before coming here, I searched through existing questions on this site and many others, but have been unable to find something that explains a solution in a way that I understand.
Using Eclipse, I am attempting to write stand alone executable in Java that searches for images and clicks on them using org.sikuli.script classes but I cannot seem to get either an executable jar or exe version of my code to match images on-screen. In Eclipse, when I create a pattern using relative path names the script matches the image on-screen. For example, if I do:
Pattern imagePattern = new Pattern(
or
Pattern imagePattern = new Pattern(
Then run my script within Eclipse, the script will find the above image without a problem. But, if I right click my project and Export as a runnable JAR file then attempt to run that JAR file, the image is no longer found. If I unzip the executable JAR, I can see that the Images directory with all of the images is there so the image are definitely being added to the JAR file. My research has led to look at using something along the lines of:
this.getClass(
to handle resources that are stored in a JAR file. Since it looks like I can create a Pattern using a BufferedImage, I have tried to use that to access and manipulate the images in my executable JAR file. Here is the code I am currently toying with to try and get this to work in Eclipse:
public boolean test() throws Exception {
URL imageURL = this.getClass(
String imageString = imageURL.
BufferedImage imageBuffered = ImageIO.
System.
System.
System.
Pattern imagePattern = new Pattern(
Screen newScreen = new Screen();
float floatPercentage = convertIntMatch
System.
if(newScreen.
System.
}
else{
System.
}
}
When I run that code in Eclipse, the output I get is:
imageURL is: file:/C:
imageString is: file:/C:
imageBuffered is: BufferedImage@
=====Searching for image: BufferedImage@
ERROR: Could not find an onscreen match for the following image ----> P(-- BufferedImage --) S: 0.8
It looks like the imagePattern using the buffered image displays the contents of the image in the console log, but it never finds a match. If I change:
Pattern imagePattern = new Pattern(
to
Pattern imagePattern = new Pattern(
so that the pattern is based on a String instead of a BufferedImage, then a match is found on-screen.
What am I doing wrong in the code above that is preventing my BufferedImage based Pattern to fail to find a match?
My Project Heirarchy is:
FFAuto
|
|-------src
| |
| |-------(default package)
| |
| |-------Images
Thanks in advance for any help. If any additional details are needed please let me know!
Changed in sikuli: | |
status: | New → Incomplete |
status: | Incomplete → In Progress |
importance: | Undecided → High |
assignee: | nobody → RaiMan (raimund-hocke) |
milestone: | none → 1.1.0 |
Changed in sikuli: | |
status: | In Progress → Fix Committed |
Changed in sikuli: | |
importance: | High → Critical |
I have already implemented getting images from a jar and use them with find() as buffered images and other features that internally use find() (findAll, observe and some minor aspects have to be adapted still). some_image. png") will work in both cases.
The usage is rather convenient, since with one setImagePath() you can say, which jar on the classpath to use by just giving a classname and for the cases you do not run from the jar (e.g. when running/debugging in the IDE) you can give an alternate file path to load the images from.
so a find("images/
I am a little bit behind, but hope I can give you something to test latest on monday.