Java 照片對(duì)比功能的實(shí)現(xiàn)
package com.function;import java.awt.image.BufferedImage;import java.io.BufferedWriter;import java.io.File;import java.io.FileWriter;import java.io.IOException;import java.util.*;import javax.imageio.ImageIO;/* * 這個(gè)是一個(gè)照片比對(duì)功能實(shí)現(xiàn)類 */public class Tools_PhotoMatching { public int mactching(String contrast_photo ,String test_photo) { int contras_rgb[] = new int[3]; int test_rgb[] = new int[3]; int k = 0; File contrastfile = new File(contrast_photo); //對(duì)比照片路徑 File testfile = new File(test_photo); //測(cè)試照片路徑 BufferedImage contrasphoto = null; BufferedImage testphoto = null; try { contrasphoto = ImageIO.read(contrastfile); testphoto = ImageIO.read(testfile); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } int contraswidth = contrasphoto.getWidth(); int contrasheight = contrasphoto.getHeight(); int testwidth = testphoto.getWidth(); int testheight = testphoto.getHeight(); //File file = new File('C:UsersprizeDesktopTOOLSDCIMCameralog.txt'); //File file1 = new File('C:UsersprizeDesktopTOOLSDCIMCameralog1.txt'); try { //FileWriter fileWriter = new FileWriter(file); //FileWriter fileWriter1 = new FileWriter(file1); //BufferedWriter bufferedWriter = new BufferedWriter(fileWriter); //BufferedWriter bufferedWriter2 = new BufferedWriter(fileWriter1); for (int i = 0; i < testwidth; i++) { for (int j = 0; j < testheight; j++) {//StringBuffer astringBuffer1 = new StringBuffer(); //StringBuffer bstringBuffer1 = new StringBuffer();int pixel1 = contrasphoto.getRGB(i, j); int pixle2= testphoto.getRGB(i, j); contras_rgb[0] = (pixel1 & 0xff0000) >> 16; //將值轉(zhuǎn)化成16進(jìn)制 contras_rgb[1] = (pixel1 & 0xff00) >> 8; contras_rgb[2] = (pixel1 & 0xff);//astringBuffer1.append(i+'行'+j+'列 R='+contras_rgb[0]+'G='+contras_rgb[1]+'B='+contras_rgb[2] ); //bufferedWriter.write(astringBuffer1.toString()); //bufferedWriter.newLine(); test_rgb[0] = (pixle2 & 0xff0000) >> 16; test_rgb[1] = (pixle2 & 0xff00) >> 8; test_rgb[2] = (pixle2 & 0xff); //bstringBuffer1.append(i+'行'+j+'列 R='+test_rgb[0]+'G='+test_rgb[1]+'B='+test_rgb[2]);//bufferedWriter2.write(bstringBuffer1.toString()); //bufferedWriter2.newLine();int Difference_R = Math.abs(contras_rgb[0]-test_rgb[0]); //相減并且求絕對(duì)值 int Difference_G= Math.abs(contras_rgb[1]-test_rgb[1]); int Difference_B= Math.abs(contras_rgb[2]-test_rgb[2]); //System.out.println('第'+j+'次:'+Math.abs(Difference));final int R = 35; //35 final int L = 130; int Q = Difference_R+Difference_G+Difference_B; if (Difference_R > R && Difference_G > R && Q>L) { //判斷每個(gè)值的浮動(dòng)不超過(guò)35k++; }else if (Difference_G >R && Difference_B>R && Q>L) { k++; }else if (Difference_R > R && Difference_B>R && Q>L) { k++; } } } //bufferedWriter.close(); //bufferedWriter2.close(); //fileWriter.close(); //fileWriter1.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return k; }}
以上就是Java 照片對(duì)比功能實(shí)現(xiàn)類的詳細(xì)內(nèi)容,更多關(guān)于Java 照片對(duì)比的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!
相關(guān)文章:
1. python excel和yaml文件的讀取封裝2. moment轉(zhuǎn)化時(shí)間戳出現(xiàn)Invalid Date的問(wèn)題及解決3. python爬蟲(chóng)實(shí)戰(zhàn)之制作屬于自己的一個(gè)IP代理模塊4. php實(shí)現(xiàn)當(dāng)前用戶在線人數(shù)5. Android中的緩存6. Android Studio插件7. .net6 在中標(biāo)麒麟下的安裝和部署過(guò)程8. Python中內(nèi)建模塊collections如何使用9. Python內(nèi)存映射文件讀寫方式10. java——Byte類/包裝類的使用說(shuō)明
