L'exemple de cet article indique la façon de comparer deux photos de Java. Partagez-le pour tout le monde pour votre référence. Les détails sont les suivants:
résumé:
Importjava.awt.image.bufferedImage;
Importjava.io.file;
Importjavax.imageio.imageio;
/ *** Comparez la similitude des deux images * @ Authorguihu ** / publicClassBmploader {// Changer en code binaire
PublicString [] [] [] getPx (stringargs) {int [] rgb = newint [3];
FileFile = newFile (args);
BufferedImageBi = null;
essayer
Le code principal est le suivant:
Import java.awt.image.buffredImage; Code publique statique [] [] getpx (String args) {int [] rgb = new int [3]; ; ] list = new String [width] [height]; )); ] [i] [i] [i] [i] [i] [i] [i] [i] j] = rgb [0] + "," + rgb [1] + "," + rgb [2] } Return list;} public static void compareImage (string imgpath1, string imgpath2) {string [] images = {{imgpath1, imgpath2}; bmploader imagefile.bmp "); system.exit (0);} // analyser la similitude de la similitude des images ST Tring [] [] list1 = getPx (images [0]); string [] [] list2 = getpx (images [1] ); = list1.length) {continu;} pour (int m = 0; m <strings.length; m ++) {try {string [] value1 = list1 [i] [j] .tring (). ","); ; n ++) {if (math.abs (Integer.Parseint (valeur1 [k]) -edeger.parseInt (valeur 2 [k]) <5) {Xiangsi ++;} RuntimeException e) {continue;} j ++;} i ++;} list1 = getpx (images [1]); = list1.length) {continu;} pour (int m = 0; m <strings.length; m ++) {try {string [] value1 = list1 [i] [j] .tring (). ","); String [] Value2 = List2 [i] [J] .tring (). <<<<<< Value2.Length; n ++) {if (math.abs (Integer.ParseInt (Value1 [K]) -Cleger.Parseint (Value2 [K]) <5) {Xiangsi ++;} {BUSI ++;}}}} catch (RuntimeException e) {continue;} j ++;} i ++;} String baifen = "" ""; / Double.PARSED ALLÉMENT (BUSI + XIANGSI) + "" "" "")) + ""); ;} Catch (exception e) {baifen = "0";} if (baifen. Length () <= 0) {baifen = "0";} if (busi == 0) {baifen = "100";} système système .out.println ("Quantité de pixel similaire: + Xiangsi +": "+ BUSI +" Similité: "+ Integer.Parseint (Baifen) +"% ");} public static void main (String [] args) {bmploader. compareImage ("e: //12.bmp", "e: //1.bmp");}}On espère que cet article est utile à la conception du programme Java de tous.