极验验证码-判断需要移动的距离

public static int compare(String file1,String file2,String file3,int threshold){
int result=0;
try
{
//读取第一张图片
File fileOne = new File(file1);
BufferedImage ImageOne = ImageIO.read(fileOne);
int width = ImageOne.getWidth();//图片宽度
int height = ImageOne.getHeight();//图片高度
int[]ImageArrayOne = new int[width*height];
int[]ImageArrayTwo = new int[width*height];
int[]ImageArrayThr = new int[width*height];
ImageArrayOne = ImageOne.getRGB(0,0,width,height,ImageArrayOne,0,width);//把图片1数据放入数组
File fileTwo = new File(file2);
BufferedImage ImageTwo = ImageIO.read(fileTwo);
ImageArrayTwo = ImageTwo.getRGB(0,0,width,height,ImageArrayTwo,0,width);//把图片2数据放入数组
//System.out.println("bgImageRGBData值"+ImageArrayOne[200]+"fullImageRGBData值"+ImageArrayTwo[200]);
图片下半部分
BufferedImage ImageNew = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
int count[]=new int[width];
for(int x = 0; x < width; x = x+1) {
count[x]=0;
}
for(int x = 0; x < width*height; x = x+1) {
if ((Math.abs(ImageArrayOne[x]-ImageArrayTwo[x]))<threshold)
{
ImageArrayThr[x]=0;

}
else{
count[x%width]++;
//System.out.println("宽度"+x%width);
//ImageArrayThr[x]=ImageArrayOne[x];
ImageArrayThr[x]=99999999;
}
}

//System.out.println(Arrays.toString(count));

for(int x = 0; x < width; x = x+1) {
if (count[x]>5 )
{
//System.out.println("猜测的轴坐标是"+x);
result=x;
//System.out.println("猜测的轴坐标是"+count[x]+" "+count[x+1]);
break;
}
}
ImageNew.setRGB(0,0,width,height,ImageArrayThr,0,width);

File outFile = new File(file3);
ImageIO.write(ImageNew, "jpg", outFile);//写图片
return result;
}
catch(Exception e)
{
e.printStackTrace();
}
return result;
}

转载于:https://www.cnblogs.com/tester-huang/p/6386047.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值