码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2017-02-10 14:53:32      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:read   for   nts   return   imageio   trace   result   图片   jpg   

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;
}

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

标签:read   for   nts   return   imageio   trace   result   图片   jpg   

原文地址:http://www.cnblogs.com/tester-huang/p/6386047.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!