Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jquery-ui/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
屏幕上的java搜索图像_Java_Image_Search_Screen_Awtrobot - Fatal编程技术网

屏幕上的java搜索图像

屏幕上的java搜索图像,java,image,search,screen,awtrobot,Java,Image,Search,Screen,Awtrobot,有没有在屏幕上快速找到图像的方法 我这样做了:(在此之前,我用Robot.createScreenCapture(…)捕获了屏幕) 公共静态点搜索(BuffereImage大,BuffereImage小){ 机器人=零; 试一试{ 机器人=新机器人(); }捕获(awtexe){ e、 printStackTrace(); } 长时间=System.currentTimeMillis(); 对于(int x=0;x

有没有在屏幕上快速找到图像的方法

我这样做了:(在此之前,我用Robot.createScreenCapture(…)捕获了屏幕)

公共静态点搜索(BuffereImage大,BuffereImage小){
机器人=零;
试一试{
机器人=新机器人();
}捕获(awtexe){
e、 printStackTrace();
}
长时间=System.currentTimeMillis();
对于(int x=0;x
但有时只需要200毫秒,但有时需要10000毫秒!:(

<编辑>:如果有人知道Autohotkey,那是另一种编程语言,有一个叫做“图像搜索”的函数,它在几毫秒内找到这些图像……(基于C++我认为)

< P> >两个可能的事情:

  • 您使用的算法并不是很快:它是一个O(mn)算法,所以您可能应该研究诸如KMP算法之类的算法

  • 在搜索图像之前,可能先对图像进行压缩,然后再进行搜索,并使用另一项检查确保压缩不会影响算法。简单的“每隔一行取出一行”应该可以大大加快程序的速度

  • 两件可能的事情:

  • 您使用的算法并不是很快:它是一个O(mn)算法,所以您可能应该研究诸如KMP算法之类的算法

  • 在搜索图像之前,可能先对图像进行压缩,然后再进行搜索,并使用另一项检查确保压缩不会影响算法。简单的“每隔一行取出一行”应该可以大大加快程序的速度


  • 如果我使用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;
    }