Jaa*_*nus 10 java image-processing
你能给我一些关于如何在屏幕上找到图像的提示吗?我的意思是,一个简单的像素组合.例如,它找到30x30像素白色方块的坐标.
Java机器人类允许我找到某些像素的颜色.但我需要反对,我希望我的程序扫描我的屏幕,然后告诉我这个小图像的坐标.好吧,我可以通过机器人查看所有像素,但它应该比这更快.快多了.
有什么建议?
实际上,对此有一个更简单或更可靠的解决方案.您可以在Java应用程序中实现Sikuli库,以在屏幕上发现图像元素并与它们进行交互.它的目的是自动化UI测试,但我认为它可以很容易地满足您的需求.
示例应用程序(来源):
import java.net.MalformedURLException;
import java.net.URL;
import org.sikuli.api.*;
import org.sikuli.api.robot.Mouse;
import org.sikuli.api.robot.desktop.DesktopMouse;
import org.sikuli.api.visual.Canvas;
import org.sikuli.api.visual.DesktopCanvas;
import static org.sikuli.api.API.*;
public class HelloWorldExample {
public static void main(String[] args) throws MalformedURLException {
// Open the main page of Google Code in the default web browser
browse(new URL("http://code.google.com"));
// Create a screen region object that corresponds to the default monitor in full screen
ScreenRegion s = new DesktopScreenRegion();
// Specify an image as the target to find on the screen
URL imageURL = new URL("http://code.google.com/images/code_logo.gif");
Target imageTarget = new ImageTarget(imageURL);
// Wait for the target to become visible on the screen for at most 5 seconds
// Once the target is visible, it returns a screen region object corresponding
// to the region occupied by this target
ScreenRegion r = s.wait(imageTarget,5000);
// Display "Hello World" next to the found target for 3 seconds
Canvas canvas = new DesktopCanvas();
canvas.addLabel(r, "Hello World").display(3);
// Click the center of the found target
Mouse mouse = new DesktopMouse();
mouse.click(r.getCenter());
}
}
Run Code Online (Sandbox Code Playgroud)
另请参阅如何在Java程序中使用Sikuli进行设置.
好吧,我可以用机器人浏览所有像素,但它应该比这更快。快多了。
恐怕这正是你必须做的。
如果所有像素都应为白色,则可以首先采取 30 个像素宽的步骤,如果找到白色像素,则采取 5 个像素的步骤,然后如果这些像素也是白色的,则检查正方形中的其余像素。
像这样的东西:
. . . . . .
. .......... . . .
......
. . . .
. . . .
. . . .......... .
..........
..........
..........
..........
. . . ..........
Run Code Online (Sandbox Code Playgroud)