The essence of this I opened the saved image, then opened it in jpeg and Java should find an area on the entire working screen and click the mouse (left or right) or the message to show that the image was found 1 time or not found
- Nobody will do this for you. Attach the code where you tried to do it. - MihailPw
- You can avoid a lot of problems right away if you use any lossless compression format. JPEG does not apply to them. - D-side
|
1 answer
image search in the image. There are two images: big and small. On the big need to find a little. For example: so that on the desktop the program knew the location of the folders? Has anyone encountered such a problem?
Here is the code
import java.awt.image.BufferedImage;
public class Motor {
int[] findSubimage(BufferedImage im1, BufferedImage im2){ int w1 = im1.getWidth(); int h1 = im1.getHeight(); int w2 = im2.getWidth(); int h2 = im2.getHeight(); assert(w2 <= w1 && h2 <= h1); // will keep track of best position found int bestX = 0; int bestY = 0; double lowestDiff = Double.POSITIVE_INFINITY; // brute-force search through whole image (slow...) for(int x = 0;x < w1-w2;x++){ for(int y = 0;y < h1-h2;y++){ double comp = compareImages(im1.getSubimage(x,y,w2,h2),im2); if(comp < lowestDiff){ bestX = x; bestY = y; lowestDiff = comp; } } } // output similarity measure from 0 to 1, with 0 being identical System.out.println(lowestDiff); System.out.println(bestX+" "+bestY); // return best location return new int[]{bestX,bestY}; } /** * Determines how different two identically sized regions are. */ private double compareImages(BufferedImage im1, BufferedImage im2) { assert(im1.getHeight() == im2.getHeight() && im1.getWidth() == im2.getWidth()); double variation = 0.0; for(int x = 0;x < im1.getWidth();x++){ for(int y = 0;y < im1.getHeight();y++){ variation += compareARGB(im1.getRGB(x,y),im2.getRGB(x,y))/Math.sqrt(3); } } return variation/(im1.getWidth()*im1.getHeight()); } /** * Calculates the difference between two ARGB colours (BufferedImage.TYPE_INT_ARGB). */ private double compareARGB(int rgb1, int rgb2) { double r1 = ((rgb1 >> 16) & 0xFF)/255.0; double r2 = ((rgb2 >> 16) & 0xFF)/255.0; double g1 = ((rgb1 >> 8) & 0xFF)/255.0; double g2 = ((rgb2 >> 8) & 0xFF)/255.0; double b1 = (rgb1 & 0xFF)/255.0; double b2 = (rgb2 & 0xFF)/255.0; double a1 = ((rgb1 >> 24) & 0xFF)/255.0; double a2 = ((rgb2 >> 24) & 0xFF)/255.0; // if there is transparency, the alpha values will make difference smaller return a1*a2*Math.sqrt((r1-r2)*(r1-r2) + (g1-g2)*(g1-g2) + (b1-b2)*(b1-b2)); } }
ps How to make it work? Where is the path to the file (picture in jpg)? How to make a GUI stupidly 2 buttons clicked, uploaded a file, clicked, he found a picture, issued a message, found or not found.
pss Sorry, in Java only 2 months. I will program ......
|