/** * FOR INTERNAL USE: see get(String, boolean) * * @param fName image filename * @return this */ protected static Image get(String fName) { return get(fName, false); }
/** * resize the loaded image with factor using Graphics2D.drawImage * @param factor resize factor * @return a new BufferedImage resized (width*factor, height*factor) */ public BufferedImage resize(float factor) { int type; BufferedImage bufimg = get(); type = bufimg.getType() == 0 ? BufferedImage.TYPE_INT_ARGB : bufimg.getType(); int width = (int) (getSize().getWidth() * factor); int height = (int) (getSize().getHeight() * factor); BufferedImage resizedImage = new BufferedImage(width, height, type); Graphics2D g = resizedImage.createGraphics(); g.drawImage(bufimg, 0, 0, width, height, null); g.dispose(); return resizedImage; }
if (img.isValid()) { if (!img.isText()) { Image bimage = img.get(false); if (bimage != null) { String rescale = "";
/** * ONLY FOR INTERNAL USE! Might vanish without notice! * * @return might be null */ public BufferedImage getBImage() { return image.get(); }
/** * return the image's BufferedImage (load it if not in cache) * * @return BufferedImage (might be null) */ public BufferedImage get() { return get(true); }
/** * to get old style OpenCV Mat for FindInput * * @return SWIG interfaced OpenCV Mat * @deprecated */ @Deprecated protected org.sikuli.natives.Mat getMatNative() { return convertBufferedImageToMat(get()); }
/** * forwarded to Image.create(filename).get() * * @return a BufferedImage from the given filename or null * @deprecated */ @Deprecated public static BufferedImage getImage(String filename) { return Image.create(filename).get(); }
/** * FOR INTERNAL USE: from IDE - suppresses load error message * * @param fName image filename * @return this */ public static Image createThumbNail(String fName) { Image img = get(fName, true); return createImageValidate(img, false); }
/** * get the OpenCV Mat version of the image's BufferedImage * * @return OpenCV Mat */ public Mat getMat() { return createMat(get()); }
/** * create a new image from a filename <br> * file ending .png is added if missing (currently valid: png, jpg, jpeg)<br> * relative filename: [...path.../]name[.png] is searched on current image path<br> * absolute filename is taken as is * if image exists, it is loaded to cache <br> * already loaded image with same name (given path) is reused (taken from cache) <br> * * if image not found, it might be a text to be searched (imageIsText = true) * * @param fName image filename * @return an Image object (might not be valid - check with isValid()) */ public static Image create(String fName) { Image img = get(fName, false); return createImageValidate(img, true); }
/** * create a sub image from this image * * @param x pixel column * @param y pixel row * @param w width * @param h height * @return the new image */ public Image getSub(int x, int y, int w, int h) { BufferedImage bi = createBufferedImage(w, h); Graphics2D g = bi.createGraphics(); g.drawImage(get().getSubimage(x, y, w, h), 0, 0, null); g.dispose(); return new Image(bi); }
public SxImage(String filename) { super(); init(Image.create(filename).get()); }
public void resetImage(Image img) { _findInput.setSource(Image.convertBufferedImageToMat(img.get())); }
/** * create a new image from the given url <br> * file ending .png is added if missing <br> * filename: ...url-path.../name[.png] is loaded from the url and and cached * <br> * already loaded image with same url is reused (reference) and taken from * cache * * @param url image file URL * @return the image */ public static Image create(URL url) { Image img = get(url); if (img == null) { img = new Image(url); } return createImageValidate(img, true); }
protected static <PSI> Image getImageFromTarget(PSI target) { if (target instanceof Pattern) { return ((Pattern) target).getImage(); } else if (target instanceof String) { Image img = get((String) target, true); img = createImageValidate(img, true); return img; } else if (target instanceof Image) { return (Image) target; } else { runTime.abortScripting("aborting script at:", String.format("find, wait, exists: invalid parameter: %s", target)); } return null; }
/** * Finder constructor for special use from an Image * * @param img Image */ public Finder(Image img) { log(lvl, "Image: %s", img); _findInput.setSource(Image.convertBufferedImageToMat(img.get())); }
/** * OCR-read the text from the image * @return the text or null */ public String text() { //TODO: use Tess4J here already?? if (Settings.OcrTextRead) { TextRecognizer tr = TextRecognizer.getInstance(); if (tr == null) { Debug.error("text: text recognition is now switched off"); return null; } String textRead = tr.recognize(this.get()); log(lvl, "text: #(" + textRead + ")#"); return textRead; } Debug.error("text: text recognition is currently switched off"); return null; }
/** * Finder constructor (finding within an image within the given region). * <br>internally used with a screen snapshot * * @param imageFilename a string (name, path, url) * @param region search Region within image - topleft = (0,0) * @throws java.io.IOException if imagefile not found */ public Finder(String imageFilename, Region region) throws IOException { Image img = Image.create(imageFilename); if (img.isValid()) { _findInput.setSource(Image.convertBufferedImageToMat(img.get())); _region = region; screenFinder = false; } else { log(-1, "imagefile not found:\n%s"); valid = false; } }
state = null; } else { img.get();