屏幕上的java搜索图像
有没有在屏幕上快速找到图像的方法 我这样做了:(在此之前,我用Robot.createScreenCapture(…)捕获了屏幕)屏幕上的java搜索图像,java,image,search,screen,awtrobot,Java,Image,Search,Screen,Awtrobot,有没有在屏幕上快速找到图像的方法 我这样做了:(在此之前,我用Robot.createScreenCapture(…)捕获了屏幕) 公共静态点搜索(BuffereImage大,BuffereImage小){ 机器人=零; 试一试{ 机器人=新机器人(); }捕获(awtexe){ e、 printStackTrace(); } 长时间=System.currentTimeMillis(); 对于(int x=0;x
公共静态点搜索(BuffereImage大,BuffereImage小){
机器人=零;
试一试{
机器人=新机器人();
}捕获(awtexe){
e、 printStackTrace();
}
长时间=System.currentTimeMillis();
对于(int x=0;x
但有时只需要200毫秒,但有时需要10000毫秒!:(
<编辑>:如果有人知道Autohotkey,那是另一种编程语言,有一个叫做“图像搜索”的函数,它在几毫秒内找到这些图像……(基于C++我认为)< P> >两个可能的事情:
如果我使用KMP进行搜索,那会快得多?或者从autohotkey生成一个exe更好,然后我会以某种方式实现它?可能会,但如果你搜索一些实现快速字符串匹配算法的库会好得多。因为在你提到autohotkey之前,我从来没有听说过autohotkey,我对此无话可说。也许我应该试一下!这里有一个…但是我怎么能用它来做像素呢?如果我用KMP来搜索,那会快得多?或者用自动热键生成一个exe会更好,然后我会以某种方式实现它?可能会,但如果你搜索它会更好实现快速字符串匹配算法的me库。在您提到autohotkey之前,我从未听说过autohotkey,对此我无话可说。也许我应该尝试一下!这里有一个…但我如何才能将其用于像素?
public static Point search(BufferedImage big, BufferedImage small) {
Robot robot = null;
try {
robot = new Robot();
} catch (AWTException e) {
e.printStackTrace();
}
long time=System.currentTimeMillis();
for (int x = 0; x < big.getWidth() - small.getWidth(); x++) {
for (int y = 0; y < big.getHeight() - small.getHeight(); y++) {
if (compare(x, y, big, small)) {
return new Point(x, y);
}
}
}
System.out.println(System.currentTimeMillis()-time);
return null;
}
private static boolean compare(int xs, int ys, BufferedImage img1, BufferedImage img2) {
for (int x = 0; x < img2.getWidth(); x++) {
for (int y = 0; y < img2.getHeight(); y++) {
if (img1.getRGB(x + xs, y + ys) != img2.getRGB(x, y)) {
return false;
}
}
}
return true;
}