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