public class Image extends Object
ImagePath
that maintains a list of places, where image files are
loaded from.ImageGroup
will allow to look at images in a folder as a
group.Settings.setImageCache(int)
Modifier and Type | Field and Description |
---|---|
protected boolean |
wasRecaptured |
Constructor and Description |
---|
Image(BufferedImage img)
create a new image from a buffered image
can only be reused with the object reference |
Image(BufferedImage img,
String name)
create a new image from a buffered image
giving it a descriptive name for printout and logging can only be reused with the object reference |
Image(ScreenImage img)
create a new image from a Sikuli ScreenImage (captured)
can only be reused with the object reference |
Image(ScreenImage img,
String name)
create a new image from a Sikuli ScreenImage (captured)
giving it a descriptive name for printout and logging can only be reused with the object reference |
Modifier and Type | Method and Description |
---|---|
String |
asFile()
stores the image as PNG file in the standard temp folder
with a created filename (sikuli-image-#unique-random#.png)
if not yet stored before
|
protected boolean |
backup() |
static void |
clearCache(int maxSize) |
protected static byte[] |
convertBufferedImageToByteArray(BufferedImage img) |
protected static Mat |
convertBufferedImageToMat(BufferedImage img) |
static ByteBuffer |
convertImageData(BufferedImage bi)
Converts
BufferedImage to ByteBuffer . |
static BufferedImage |
convertImageToGrayscale(BufferedImage image)
A simple method to convert an image to gray scale.
|
static Image |
create(Image imgSrc)
create a new Image as copy of the given Image
|
static Image |
create(Pattern p)
create a new Image with Pattern aspects from an existing Pattern
|
static Image |
create(String fName)
create a new image from a filename
file ending .png is added if missing (currently valid: png, jpg, jpeg) relative filename: [...path.../]name[.png] is searched on current image path absolute filename is taken as is if image exists, it is loaded to cache already loaded image with same name (given path) is reused (taken from cache) if image not found, it might be a text to be searched (imageIsText = true) |
static Image |
create(URL url)
create a new image from the given url
file ending .png is added if missing filename: ...url-path.../name[.png] is loaded from the url and and cached already loaded image with same url is reused (reference) and taken from cache |
protected static BufferedImage |
createBufferedImage(int w,
int h) |
protected static Mat |
createMat(BufferedImage img) |
static Image |
createThumbNail(String fName)
FOR INTERNAL USE: from IDE - suppresses load error message
|
void |
delete() |
static void |
dump()
Print the current state of the cache
|
static void |
dump(int lvl)
Print the current state of the cache, verbosity depends on debug level
|
Match |
find(Image img)
find an image in another image
|
Iterator<Match> |
findAll(Image img)
find all images in another image
|
BufferedImage |
get()
return the image's BufferedImage (load it if not in cache)
|
protected BufferedImage |
get(boolean shouldLoad) |
protected static Image |
get(String fName)
FOR INTERNAL USE: see get(String, boolean)
|
protected static Image |
get(URL imgURL) |
Image |
getCell(int r,
int c)
get the specified cell counting from (0, 0), if a raster is setup
negative counts reverse from the end (last = -1) values outside range are 0 or last respectively |
Image |
getCol(int c)
get the specified column counting from 0, if columns or raster are setup
negative counts reverse from the end (last = -1) values outside range are 0 or last respectively |
int |
getCols() |
int |
getColW() |
String |
getFilename() |
URL |
getFileURL() |
ImageGroup |
getGroup() |
static boolean |
getIDEshouldReload() |
protected static <PSI> Image |
getImageFromTarget(PSI target) |
String |
getImageName() |
Rectangle |
getLastSeen()
if the image was already found before
|
double |
getLastSeenScore()
if the image was already found before
|
Mat |
getMat()
get the OpenCV Mat version of the image's BufferedImage
|
protected Mat |
getMatNative()
Deprecated.
|
String |
getName()
Get the image's descriptive name
|
Location |
getOffset()
Get the value of offset
|
Image |
getRow(int r)
get the specified row counting from 0, if rows or raster are setup
negative counts reverse from the end (last = -1) values outside range are 0 or last respectively |
int |
getRowH() |
int |
getRows() |
float |
getSimilarity()
Get the value of similarity
|
Dimension |
getSize() |
Image |
getSub(int part)
create a sub image from this image
|
Image |
getSub(int x,
int y,
int w,
int h)
create a sub image from this image
|
String |
getText() |
URL |
getURL() |
int |
getWaitAfter()
Get the value of waitAfter
|
boolean |
hasIOException() |
boolean |
isAbsolute() |
boolean |
isBundled()
INTERNAL USE: image is contained in a bundle (.sikuli)
|
boolean |
isFile() |
boolean |
isPattern()
true if this image contains pattern aspects
only useable with the new ImageFinder |
boolean |
isRecaptured() |
boolean |
isText() |
boolean |
isUseable()
checks, wether the Image can be used with the new ImageFinder
|
boolean |
isValid()
check whether image is available for Finder.find()
This is for backward compatibility The new ImageFinder uses isUsable() |
protected static void |
purge(ImagePath.PathEntry path) |
static void |
purge(String bundlePath)
INTERNAL USE: IDE: to get rid of cache entries at script save, close or
save as
|
protected static void |
purge(URL pathURL) |
static void |
reload(String fpImage) |
File |
remove() |
static void |
reset()
clears all caches (should only be needed for debugging)
|
BufferedImage |
resize(float factor)
resize the loaded image with factor using Graphics2D.drawImage
|
protected boolean |
restore() |
protected static void |
set(Image img) |
protected Image |
setBimg(BufferedImage bimg) |
Image |
setCols(int n)
store info: this image is divided horizontally into n even columns
a preparation for using getCol() |
Image |
setFileURL(URL fileURL) |
void |
setGroup(ImageGroup group)
set the ImageGroup this image should belong to
|
void |
setHasIOException(boolean state) |
static void |
setIDEshouldReload(Image img) |
Image |
setImageName(String imageName) |
Image |
setIsAbsolute(boolean val) |
Image |
setIsPattern(boolean imageIsPattern) |
protected Image |
setLastSeen(Rectangle lastSeen,
double sim)
Internal Use: set the last seen info after a find
|
Image |
setOffset(Location offset)
Set the value of offset
|
Image |
setRaster(int r,
int c)
store info: this image is divided into a raster of even cells
a preparation for using getCell() |
Image |
setRows(int n)
store info: this image is divided vertically into n even rows
a preparation for using getRow() |
Image |
setSimilarity(float similarity)
Set the value of similarity
|
Image |
setWaitAfter(int waitAfter)
Set the value of waitAfter
|
String |
text()
OCR-read the text from the image
|
static String |
text(String imgFile)
convenience method: get text from given image file
|
String |
toString() |
static void |
unCacheBundledImage(String imgFileName)
purge the given image file's in memory image data and remove it from cache.
|
static void |
unCacheImage(URL imgURL)
purge the given image's in memory image data and remove it from cache.
|
public Image(BufferedImage img)
img
- BufferedImagepublic Image(BufferedImage img, String name)
img
- BufferedImagename
- descriptive namepublic Image(ScreenImage img)
img
- ScreenImagepublic Image(ScreenImage img, String name)
img
- ScreenImagename
- descriptive namepublic static void clearCache(int maxSize)
public static void reload(String fpImage)
public static void setIDEshouldReload(Image img)
public static boolean getIDEshouldReload()
public boolean isRecaptured()
public boolean hasIOException()
public void setHasIOException(boolean state)
public String getImageName()
public URL getFileURL()
protected Image setBimg(BufferedImage bimg)
public boolean isText()
public String getText()
public boolean isAbsolute()
public Image setIsAbsolute(boolean val)
public boolean isBundled()
public boolean isPattern()
public Image setIsPattern(boolean imageIsPattern)
public int getWaitAfter()
public Image setWaitAfter(int waitAfter)
waitAfter
- new value of waitAfterpublic Location getOffset()
public Image setOffset(Location offset)
offset
- new value of offsetpublic float getSimilarity()
public Image setSimilarity(float similarity)
similarity
- new value of similaritypublic Rectangle getLastSeen()
public double getLastSeenScore()
protected Image setLastSeen(Rectangle lastSeen, double sim)
lastSeen
- Matchsim
- SimilarityScorepublic static Image create(Image imgSrc)
imgSrc
- given Imagepublic static Image create(String fName)
fName
- image filenamepublic static Image create(Pattern p)
p
- a Patternpublic static Image create(URL url)
url
- image file URLprotected static <PSI> Image getImageFromTarget(PSI target)
public static Image createThumbNail(String fName)
fName
- image filenamepublic String asFile()
protected static Image get(String fName)
fName
- image filenameprotected static void set(Image img)
public static void purge(String bundlePath)
bundlePath
- absolute path for an image set in this folderprotected static void purge(ImagePath.PathEntry path)
protected static void purge(URL pathURL)
public boolean isFile()
public File remove()
public void delete()
protected boolean backup()
protected boolean restore()
public static void unCacheBundledImage(String imgFileName)
imgFileName
- an absolute filenamepublic static void unCacheImage(URL imgURL)
imgURL
- URL of an image filepublic static void dump()
public static void dump(int lvl)
lvl
- debug level used herepublic static void reset()
public String getName()
public ImageGroup getGroup()
public void setGroup(ImageGroup group)
group
- ImageGrouppublic boolean isValid()
public boolean isUseable()
public URL getURL()
public String getFilename()
public BufferedImage get()
protected BufferedImage get(boolean shouldLoad)
public Dimension getSize()
public BufferedImage resize(float factor)
factor
- resize factorpublic Image getSub(int x, int y, int w, int h)
x
- pixel columny
- pixel roww
- widthh
- heightpublic Image getSub(int part)
part
- (the constants Region.XXX as used with Region.get(int)
)public Image setRows(int n)
n
- number of rowspublic Image setCols(int n)
n
- number of Columnspublic int getRows()
public int getRowH()
public int getCols()
public int getColW()
public Image setRaster(int r, int c)
r
- number of rowsc
- number of columnspublic Image getRow(int r)
r
- row numberpublic Image getCol(int c)
c
- column numberpublic Image getCell(int r, int c)
r
- row numberc
- column numberpublic Mat getMat()
protected static Mat createMat(BufferedImage img)
@Deprecated protected Mat getMatNative()
protected static Mat convertBufferedImageToMat(BufferedImage img)
protected static byte[] convertBufferedImageToByteArray(BufferedImage img)
protected static BufferedImage createBufferedImage(int w, int h)
public static ByteBuffer convertImageData(BufferedImage bi)
BufferedImage
to ByteBuffer
.bi
- Input imagepublic static BufferedImage convertImageToGrayscale(BufferedImage image)
image
- input imagepublic Match find(Image img)
img
- imagepublic Iterator<Match> findAll(Image img)
img
- imagepublic String text()