mirror of
https://github.com/RaiMan/SikuliX1.git
synced 2023-06-02 10:04:55 +03:00
ongoing: class Image
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -21,4 +21,3 @@ original/
|
||||
*.java.ignore
|
||||
.DS_Store
|
||||
native/
|
||||
Images*/
|
||||
|
||||
@@ -291,6 +291,11 @@ public abstract class Element {
|
||||
content = mat;
|
||||
}
|
||||
|
||||
public void setContentAndSize(Mat mat) {
|
||||
setContent(mat);
|
||||
setSize(mat);
|
||||
}
|
||||
|
||||
private Mat content = SXOpenCV.newMat();
|
||||
|
||||
private final static String PNG = "png";
|
||||
|
||||
@@ -51,6 +51,11 @@ import java.util.*;
|
||||
*/
|
||||
public class Image extends Element {
|
||||
|
||||
void log() {
|
||||
//TODO ****************** debug stop
|
||||
log(-1, "DebugStop");
|
||||
}
|
||||
|
||||
//<editor-fold desc="00 0 instance">
|
||||
public static Image getDefaultInstance4py() {
|
||||
return new Image(new Screen().capture());
|
||||
@@ -206,7 +211,7 @@ public class Image extends Element {
|
||||
}
|
||||
if (scheme.equals("file")) {
|
||||
init(new File(validFilename));
|
||||
} else if (scheme.equals("class")) {
|
||||
} else {
|
||||
init(uri);
|
||||
}
|
||||
}
|
||||
@@ -276,6 +281,7 @@ public class Image extends Element {
|
||||
}
|
||||
|
||||
private void init(URI uri) {
|
||||
URL resource = null;
|
||||
if (uri.getScheme().equals("class")) {
|
||||
Class clazz = null;
|
||||
try {
|
||||
@@ -283,10 +289,18 @@ public class Image extends Element {
|
||||
} catch (ClassNotFoundException e) {
|
||||
terminate("init: %s (%s)", uri, e.getMessage());
|
||||
}
|
||||
URL resource = clazz.getResource(uri.getPath());
|
||||
resource = clazz.getResource(uri.getPath());
|
||||
if (resource == null) {
|
||||
terminate("init: %s (not found)", uri);
|
||||
}
|
||||
} else if (uri.getScheme().startsWith("http")) {
|
||||
try {
|
||||
resource = uri.toURL();
|
||||
} catch (MalformedURLException e) {
|
||||
terminate("init: %s (not valid)", uri);
|
||||
}
|
||||
}
|
||||
if (null != resource) {
|
||||
try {
|
||||
InputStream inputStream = resource.openStream();
|
||||
byte[] bytes = inputStream.readAllBytes();
|
||||
@@ -298,7 +312,6 @@ public class Image extends Element {
|
||||
} catch (IOException e) {
|
||||
terminate("init: %s (io-error)", uri);
|
||||
}
|
||||
log(-1, "DebugStop");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
2
API/src/main/resources/images/images.py
Normal file
2
API/src/main/resources/images/images.py
Normal file
@@ -0,0 +1,2 @@
|
||||
test = "test.png"
|
||||
testBig = "testBig.png"
|
||||
BIN
API/src/main/resources/images/test.png
Normal file
BIN
API/src/main/resources/images/test.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
BIN
API/src/main/resources/images/testBig.png
Normal file
BIN
API/src/main/resources/images/testBig.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 285 KiB |
@@ -8,11 +8,9 @@ import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.opencv.highgui.HighGui;
|
||||
import org.sikuli.basics.Debug;
|
||||
import org.sikuli.script.Image;
|
||||
import org.sikuli.script.ImagePath;
|
||||
import org.sikuli.script.Location;
|
||||
import org.sikuli.script.Region;
|
||||
import org.sikuli.script.*;
|
||||
import org.sikuli.script.support.RunTime;
|
||||
|
||||
import java.io.File;
|
||||
@@ -26,6 +24,7 @@ public class ElementTest {
|
||||
String methodName = "NotValid";
|
||||
RunTime runTime = RunTime.get();
|
||||
String bundlePath = null;
|
||||
static boolean showImage = true;
|
||||
|
||||
void testIntro() {
|
||||
methodName = Thread.currentThread().getStackTrace()[2].getMethodName();
|
||||
@@ -36,6 +35,19 @@ public class ElementTest {
|
||||
Debug.logp(methodName + ": " + message, args);
|
||||
}
|
||||
|
||||
void testShow(Image image) {
|
||||
if (!showImage || !image.isValid()) {
|
||||
return;
|
||||
}
|
||||
HighGui.namedWindow(methodName);
|
||||
Screen screen = Screen.getPrimaryScreen();
|
||||
int x = (screen.w - image.w) / 2;
|
||||
int y = (screen.h - image.h) / 2;
|
||||
HighGui.moveWindow(methodName, x, y);
|
||||
HighGui.imshow(methodName, image.getContent());
|
||||
HighGui.waitKey(3000);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
if (null == bundlePath) {
|
||||
@@ -49,6 +61,7 @@ public class ElementTest {
|
||||
public void test000_StartUp() {
|
||||
Region region = new Region(100, 200, 300, 400);
|
||||
Image image = new Image(region);
|
||||
showImage = false;
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,6 +69,7 @@ public class ElementTest {
|
||||
Region region = new Region(100, 200, 300, 400);
|
||||
Image image = new Image(region);
|
||||
testOutro("%s", image);
|
||||
testShow(image);
|
||||
assertTrue("NotValid: " + image.toString(), image.isValid());
|
||||
}
|
||||
|
||||
@@ -64,6 +78,7 @@ public class ElementTest {
|
||||
Location location = new Location(100, 200);
|
||||
Image image = new Image(location);
|
||||
testOutro("%s", image);
|
||||
testShow(image);
|
||||
assertFalse("Valid???: " + image.toString(), image.isValid());
|
||||
}
|
||||
|
||||
@@ -72,6 +87,7 @@ public class ElementTest {
|
||||
Region region = new Region(100, 200, 300, 400);
|
||||
Image image = region.getImage();
|
||||
testOutro("%s", image);
|
||||
testShow(image);
|
||||
assertTrue("NotValid: " + image.toString(), image.isValid());
|
||||
}
|
||||
|
||||
@@ -82,6 +98,7 @@ public class ElementTest {
|
||||
String imageName = "../images/" + testName;
|
||||
Image image = new Image(imageName);
|
||||
testOutro("%s (%s)", image, imageName);
|
||||
testShow(image);
|
||||
assertTrue("NotValid: " + image.toString(), image.isValid());
|
||||
}
|
||||
|
||||
@@ -90,6 +107,7 @@ public class ElementTest {
|
||||
String imageName = testName;
|
||||
Image image = new Image(imageName);
|
||||
testOutro("%s (%s)", image, imageName);
|
||||
testShow(image);
|
||||
assertTrue("NotValid: " + image.toString(), image.isValid());
|
||||
}
|
||||
|
||||
@@ -98,6 +116,17 @@ public class ElementTest {
|
||||
String resName = "class:///images/" + testName;
|
||||
Image image = new Image(org.sikuli.script.Image.class, "images/" + testName);
|
||||
testOutro("%s (%s)", image, resName);
|
||||
testShow(image);
|
||||
assertTrue("NotValid: " + image.toString(), image.isValid());
|
||||
}
|
||||
|
||||
String httpURI = "https://sikulix-2014.readthedocs.io/en/latest/_images/popup.png";
|
||||
|
||||
@Test
|
||||
public void test007_ImageFileHTTP() {
|
||||
Image image = new Image(httpURI);
|
||||
testOutro("%s (%s)", image, httpURI);
|
||||
testShow(image);
|
||||
assertTrue("NotValid: " + image.toString(), image.isValid());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user