简体   繁体   English

如何使用 Java 使用 Sikuli 获取图像位置?

[英]How to get image location with Sikuli using Java?

It's very hard to find Sikuli examples for Java, all is written for Python or Sikuli IDE.很难找到适用于 Java 的 Sikuli 示例,所有示例都是为 Python 或 Sikuli IDE 编写的。 I have defined a pattern that I'm able to click on, hover etc..我已经定义了一个可以点击、悬停等的模式。

How can I save its coordinates into a variable so I'll be able to use it later for navigation?我怎样才能将它的坐标保存到一个变量中,以便以后可以使用它进行导航?

I don't know what you mean when you say "pattern".我不知道你说的“模式”是什么意思。 Do you refer to the actual Sikuli Pattern class?你指的是实际的 Sikuli Pattern类吗? Or just use it as general word?还是只是将其用作通用词? Anyway, you can store the coordinates of a pattern found on the screen like this:无论如何,您可以像这样存储在屏幕上找到的图案的坐标:

Region reg = new Screen();
Pattern p = new Pattern("someImage.png");
Match m = reg.find(p);

Then you can either access the coordinates directly as they all defined using public access level modifiers:然后您可以直接访问坐标,因为它们都使用公共访问级别修饰符定义:

int x = m.x;
int y = m.y;

Or you can use the getter methods available through the same class:或者您可以使用通过同一类可用的 getter 方法:

int x = m.getX();
int y = m.getY();

Alternatively, you can store the whole Location object for your future reference:或者,您可以存储整个Location对象以供将来参考:

Location l = m.getTarget();

int x = l.x;
int y = l.y;

int x = l.getX();
int y = l.getY();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM