Java实现图像对比类
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; /*
* 这个是一个照片比对功能实现类
*/
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); //对比照片路径
File testfile = new File(test_photo); //测试照片路径
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:\\Users\\prize\\Desktop\\TOOLS\\DCIM\\Camera\\log.txt");
//File file1 = new File("C:\\Users\\prize\\Desktop\\TOOLS\\DCIM\\Camera\\log1.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; //将值转化成16进制
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]); //相减并且求绝对值
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; //
final int L = 130;
int Q = Difference_R+Difference_G+Difference_B;
if (Difference_R > R && Difference_G > R && Q>L) { //判断每个值的浮动不超过35
k++;
}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实现图像对比类的更多相关文章
- c#语法与c++ 及 java语法的对比分析
早期开发的时候一直用c/c++,后来主要用的是java.最近需要用下c#. 熟悉了下c#,发现c#语言在对c/c++基础上做了很多简化,同时参考了很多java的语法习惯,本来在语法上c/c++就有很多 ...
- Java文件类型工具类
package *; import java.util.HashMap; import java.util.Map; /** * <p> * <b>FileTypeEnum2& ...
- JAVA微信支付代码(WeChatPay.java 才是调用类)
微信官方文档:https://pay.weixin.qq.com/wiki/doc/api/index.html MD5Util.java package weixin; import java.se ...
- Java中的Graphics2D类基本使用教程
Java语言在Graphics类提供绘制各种基本的几何图形的基础上,扩展Graphics类提供一个Graphics2D类,它拥用更强大的二维图形处理能力,提供.坐标转换.颜色管理以及文字布局等更精确的 ...
- Java 2-Java 对象和类
Java 对象和类 Java作为一种面向对象语言.支持以下基本概念: 多态 继承 封装 抽象 类 对象 实例 方法 消息解析 本节我们重点研究对象和类的概念. 对象:对象是类的一个实例,有状态和行为. ...
- java 中常用的类
java 中常用的类 Math Math 类,包含用于执行基本数学运算的方法 常用API 取整 l static double abs(double a) 获取double 的绝对值 l sta ...
- Java数学函数Math类
Java数学函数Math类常用: Math.abs(12.3); //12.3 返回这个数的绝对值 Math.abs(-12.3); //12.3 Math.copySign(1.23, -12.3) ...
- Atitit。D&D drag&drop拖拽功能c#.net java swing的对比与实现总结
Atitit.D&D drag&drop拖拽功能c#.net java swing的对比与实现总结 1. 实现一个D&D操作一般包括三个步骤: 1 2. .net黑头的拖曳机制 ...
- Java学习笔记二十四:Java中的Object类
Java中的Object类 一:什么是Object类: Object类是所有类的父类,相当于所有类的老祖宗,如果一个类没有使用extends关键字明确标识继承另外一个类,那么这个类默认继承Object ...
随机推荐
- iis上的aps.net1.1程序池如何添加
http://www.jb51.net/article/84668.htm iis上的aps.net1.1 的程序池是默认有的,如果不小心将其删掉,或者改成其他版本,将没办法在iis工具上还原或新建一 ...
- 1.初步认识TypeScript
简介:typescript是C#之父主导的一门语言,本质上是向Javascript语言添加了可选的静态类型和基于面向对象的诸多特性.相当于javascript的超集,其包含es6.由于是和C#之父创造 ...
- sparkSQL以JDBC为数据源
一.环境准备 安装oracle后,创建测试表.数据: create table test ( username varchar2(32) primary key , password varchar2 ...
- sqlalchemy操作----外键关联,relationship
... #!_*_coding:utf-8_*_ #__author__:"Alex huang" import sqlalchemy from sqlalchemy import ...
- VUE简单组件通信
[x] 1.prop组件通信 1.简单理解 2.多层嵌套 [x] 2.使用ref进行组件通信 [x] 3.$emit组件通信 1.prop组件通信 1.简单理解 有点类似于应式的感觉,我不管你要不要只 ...
- 无法连接到 OPC服务器[无此类接口支持(异常来自HRESULT:0x80004002(E_NOINTERFACE))]
来源:https://stackoverrun.com/cn/q/10400663 无法连接到ABB Freelance OPC服务器[无此类接口支持(异常来自HRESULT:0x80004002(E ...
- Linux环境下查看线程数的几种方法
1.cat /proc/${pid}/status 2.pstree -p ${pid} 3.top -p ${pid} 再按H,或者直接输入 top -bH -d 3 -p ${pid} top ...
- 黄聪:wordpress获取hook所有function
list_hooked_functions('wp_footer'); function list_hooked_functions($tag=false) { global $wp_filter; ...
- django之中间件middleware
django 中的中间件(middleware),在django中,中间件其实就是一个类,在请求到来和结束后,django会根据自己的规则在合适的时机执行中间件中相应的方法. 在django项目的se ...
- awk中使用shell的环境变量
awk中使用shell的环境变量一:"'$var'"这种写法大家无需改变用'括起awk程序的习惯,是老外常用的写法.如:var="test"awk 'BEGIN ...