Comparison of one image with others (analyze whether the chosen image is the same as the others already pre-defined or not)

0

I'm trying to make a Java code that compares an input image with other n already defined images in code. I developed (with a lot of) a similar code, which compared two images only, the problem is to magnify it. To take one image only and to compare with several others, I do not know how to do it.

What I have:

public static boolean compareImage(BufferedImage image1, BufferedImage image2){
    if (image1.getWidth()!= image2.getWidth()|| image1.getHeight() != image2.getHeight()){
        return(false);
                }
    for (int x=0; x<image1.getWidth(); x++){
        for(int y=0; y<image1.getHeight(); y++){
            if(image1.getRGB(x,y)!=image2.getRGB(x,y)){
                return(false);
    
asked by anonymous 26.03.2017 / 17:58

1 answer

1

You can store the images in a list, and make a loop to compare that list with the image you want, using the method of your code. Within this loop, you add a condition to do something when comparing the main image and any of the list returns true or false :

ArrayList<BufferedImage> imageList = new ArrayList<BufferedImage>();


for(int i = 0; i < imageList.size(); i++) {
   if(compareImage(image1, imageList.get(i))) {
      //faz algo se retornar true
   } else {
     //faz algo se retornar false
   }
}
    
26.03.2017 / 18:52