I want to be able to return the coordinates of small image on my screen, how can I go about sensing its location and returning those coordinates? For example if I wanted to make the Robot class click on this no matter where I move it on the screen.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
I want to be able to return the coordinates of small image on my screen, how can I go about sensing its location and returning those coordinates? For example if I wanted to make the Robot class click on this no matter where I move it on the screen.
I would use the following algorithm:
0. Convert a sample image in a BufferedImage - just so you can compare.
1. For each pixel on the screen:
1.1. Create screenshot of a rectangular part of a screen with the upper left corner in this pixel and dimensions equal to your target image ones. You can do that with Robot.createScreenCapture.
1.2. Use BufferedImage.getRGB to get array of RGB data
1.3. Use similar function on your sample image from (0)
1.4. Compare (1.2.) and (1.3.) to first (bunch) of failures. If failed (n times) - go to the next pixel, if not - return the coordinates.
Or, for instance, you can use some neural network libs for image recognition.