Java机器人与图像对比
我正在考虑创建一个 Java 应用程序来自动化我必须定期执行的流程,在开始任何编码之前,我想我应该寻求有关实现它的最佳方法的建议。
基本上,我使用的应用程序在任何时候都会在屏幕上显示大量图像,我想知道是否有一种方法可以让 Java 识别这两个图像中的任何一个是否相同。如果是的话,我想自动化鼠标移动和按钮点击。
经过一番阅读后,我认为 PixelGrabber
和 Robot
类可能是正确的开始方式,但就像我说的,我正在寻找任何信息对此可以提供。
您有什么建议?
I'm toying with an idea for creating a Java application to automate a process that I have to do regularly and before I start any coding I thought I would seek advice as to the best way to approach it.
Basically, the application I use has a large number of images present on the screen at any one time, and what I would like to know is if there is a way to have Java identify if any of these two images are the same. If they are, I would like to automate mouse movement and button clicks.
After a bit of reading, I'm thinking that the PixelGrabber
and Robot
classes might be the right way to start, but like I said, I'm looking for any information on this that can be offered.
What are your suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我相信机器人类和像素抓取器就足够了。如果您倾向于自己编写解决方案(也许是出于教育目的),请务必这样做。但是,如果您不想重新发明轮子,您可以看看这个项目:
http://sikuli.org /
例如,我用它来做一些单独使用 Selenium 很难实现的事情。如果您在编写一些脚本后仍然无法实现您的目标,Sikuli 提供了一个很好的 API,您可以在 java 程序中使用它。
I believe the Robot class and a Pixel Grabber would be sufficient. If you are inclined to program the solution yourself, maybe for educational purpose, by all means please do. If you, however, don't want to reinvent the wheel, you may take a look at this project:
http://sikuli.org/
I, for example, use it to do stuff that would be hard to achieve with Selenium alone. If you still can't achieve your goal after some scripting, Sikuli provides a nice API which you can use from inside your java program.
Robot 类足以拍摄图像并能够检查像素。但使用 java 应用程序(一个非常简单的图库应用程序)内的图像重新创建桌面似乎更有意义。那么操作就更简单了。我没有看到另一种实现操作的方式。
The Robot class would be sufficient to take images and being able to inspect pixels. But it seems to make more sense, to recreate your desktop with images inside of a java application (a very simple gallery application). Then operations are simplier. An other way of realizing operations I do not see.