El ejemplo de este artículo cuenta la forma de comparar dos imágenes de Java. Compártelo para todos para su referencia. Los detalles son los siguientes:
resumen:
Importjava.awt.image.bufferedImage;
ImportJava.io.file;
ImportJavax.Imageio.Imageio;
/*** Compare la similitud de las dos imágenes*@autorguihu **/publicClassBMPloader {// Cambiar al código binario
Publicstring [] [] [] getpx (StrinDargs) {int [] rgb = newInt [3];
FileFile = newFile (args);
BufferedImagebi = nulo;
intentar
El código principal es el siguiente:
Import java.awt.image.buffredimage; Code public staty String [] [] getpx (string args) {int [] rgb = new int [3]; ; ] list = new String [width] [altura]; ); ] [i] [i] [i] [i] [i] [i] [i] [i] j] = rgb [0] + "," + rgb [1] + "," + rgb [2] ;} Lista de retorno;} public static void compareImage (String imgpath1, string imgpath2) {string [] images = {{imgpath1, imgpath2}; bmploader imageFile.bmp "); system.exit (0);} // Analizar la similitud de imagen Begin S TRING [] [] list1 = getpx (imágenes [0]); string [] [] list2 = getpx (imágenes [1] ); = list1.length) {continuar;} para (int m = 0; m <strings.length; m ++) {try {string [] value1 = list1 [i] [j] .tring (). ","); ; RuntimeException e) {continuar;} j ++;} i ++;} list1 = getpx (imágenes [1]); = list1.length) {continuar;} para (int m = 0; m <strings.length; m ++) {try {string [] value1 = list1 [i] [j] .tring (). ","); <<<<<< Value2.Length; {Busi ++;}}}} Catch (runtimeException e) {continúa;} j ++;} i ++;} string baifen = "" ""; / Double. PARTIRSE ((Busi + xiangsi) + "" "" "")) + ""); ;} Catch (Exception e) {baifen = "0";} if (baifen. Longitud () <= 0) {baifen = "0";} if (busi == 0) {baifen = "100";} sistema .out.println ("Cantidad de píxeles similar: + xiangsi +": " + busi +" similitud: " + integer.parseInt (baifen) +"%");} public static void main (string [] args) {bmploader. CompareImage ("E: //12.bmp", "e: //1.bmp");}}Se espera que este artículo sea útil para el diseño del programa Java de todos.