是否可以使用Sikuli断言在无GUI模式下图像是相同的? [英] Is it possible to use Sikuli to assert that images are the same in GUI-less mode?

查看:222
本文介绍了是否可以使用Sikuli断言在无GUI模式下图像是相同的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一台无头运行的测试服务器.我要进行的一项测试是检查通过特定URL提供的图像是否与某些参考图像匹配.

I have a testing server which runs headless. One test I want is to check that an image served off a particular URL matches some reference image.

Sikuli中是否有一个API可以直接接受图像作为流并将其与从本地资源文件中获取的其他图像进行比较?不幸的是,没有关于Sikuli的Java API的完整教程,我发现的所有教程都是假设有可用的显示.

Is there an API in Sikuli which can directly accept an image as a stream and compare it with some other image taken from the local resource file? Unfortunately, there is no complete tutorial on Sikuli's Java API, all I've found is tutorials that assume that there is a display available.

我很高兴看到任何示例,或者至少链接到Sikuli javadocs的所需部分.另外,欢迎提出其他方法的建议.

I'll be glad to see any examples or at least links to the needed parts of Sikuli javadocs. Also, suggestions for other approaches are welcome.

推荐答案

要使用Sikuli,您需要

To use Sikuli you need

  1. 将在其上搜索另一张图像的基本图像.
  2. 将在另一张图像中搜索的图像.

如果图像1是您的本地资源图像,则可以创建org.sikuli.Finder实例,其中包含该图像的路径以及将被搜索的该图像的Region. 示例(java级):

If image 1 is your local resource image, you can create a org.sikuli.Finder instance with the path to the image and the Region of this image which will be searched. Example (java level):

finder = new Finder("path/to/image", new Region(0, 0, <imgwidth>, <imgheight>));

如果图像1是您的流,则必须以某种方式用它制作一个BufferedImage(我不知道执行此操作的最佳方法). 然后,您可以在java.awt.Rectangle和org.sikuli.Region的帮助下,从此BufferedImage创建org.sikuli.ScreenImage.

If image 1 is your stream, you have to make a BufferedImage out of it somehow (I do not know the best way to do this). Then you can make a org.sikuli.ScreenImage from this BufferedImage with the help of an java.awt.Rectangle and an org.sikuli.Region.

finder = new Finder(new ScreenImage(new Rectangle(0,0,<imgwidth>,<imgheight>), bufferedImage), new Region(0,0,<imgwidth>,<imgheight>))

从图像1创建查找器后,可以在该图像中搜索图像2.

After you created the finder from image 1, you can search image 2 within this image.

同样,您有两种可能. 如果第二个图像是您的本地资源图像,则可以创建org.sikuli.Pattern对象,其文件位置为:

Again, you have two possibilities. If the second image is your local resource image, you can create an org.sikuli.Pattern object with the file location:

pattern = new Pattern("path/to/image.png");

否则,如果这是您的流,则必须以某种方式从流中制作一个BufferedImage.然后,您可以根据该图像创建图案:

Else, if this is your stream, you have to make a BufferedImage out of the stream somehow. You can then create a pattern from this image:

pattern = new Pattnern(bufferedImage);

最后一步,您现在可以运行查找器以搜索图案:

As a last step, you can now run the finder to search for the pattern:

finder.find(pattern);

您可以使用以下方法检查发现者是否发现了任何东西:

You can check if the finder found anything with:

finder.hasNext();

您应该可以使用以下命令迭代所有发现:

And you should be able to iterate all findings with:

for (Match m : finder):
    //do something with the match

尽管您的问题已经有几个星期了,但我希望能为您提供帮助.

I hope I could help you although your question is already some weeks old.

这篇关于是否可以使用Sikuli断言在无GUI模式下图像是相同的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆