希望各位大神看看,代码有点长,新手希望大家多多赐教
package jianmo;import java.awt.image.BufferedImage;
import
import java.util.TreeMap;
import javax.imageio.ImageIO;
public class T01 {
public static void main(String[] args) {
TreeMap<String,String> fileList = FileName.getFile("C:\\Users\\王春晓\\Desktop\\cumcm2013problems\\B\\附件1\\");
for(String s : fileList.keySet()){
//System.out.println(s+"\t"+fileList.get(s));
FileList fileList = getFileList("C:\\Users\\王春晓\\Desktop\\cumcm2013problems\\B\\附件\\"); // get file name list from a folder
int fileNum = fileList.size(); //get the number of file names
BufferedImage bImg = new BufferedImage(fileList[0].getFileName());
int iHeight = bImg.getHeight(); // Image Height
int iWidth = bImg.getWidth(); // Image Width
bImg.close();
int[][] leftArr = new int[fileNum][iHeight]; //left edge array
int[][] rightArr = new int[fileNum][iHeight]; //right edge array
// get the leftArr and rightArr
int i;int j;
for(i = 0; i < fileNum; ++i)
{3
BufferedImage tImg = new BufferedImage(fileList[i].getFileName());
for(j = 0; j < iHeight; ++j)
{
leftArr[i][j] = tImg.getRGB(0, j);
rightArr[i][j] = tImg.getRGB(iWidth - 1, j);
}
}
// calculate the distance between each image
double[][] distMat = new double[fileNum][fileNum];
for(i = 0; i < fileNum; ++i)
{
// use a image's left edge compare with other images' right edge
for(j = 0; j < fileNum; ++j)
{
double tDist = 0; int k; // distance between image[i]' left edge and image[j]' right edge
for(k = 0; k < iHeight; ++k)
{
tDist += getDistance(left[i][k], right[j][k];
}
distMat[i][j] = tDist;
}
}
// TODO: we have the distance matrix between each images, so we should
// have an algorithm to match the images.
// ...
}
// get the distance of two RGB point, using Euclidean distance
// distance lower is better
double getDistance(int aRGB; int bRGB);
{
double dist = 0.0;
int aR = (aRGB & 0x00ff0000) >> 16;
int bR = (bRGB & 0x00ff0000) >> 16;
int aG = (aRGB & 0x0000ff00) >> 8;
int bG = (bRGB & 0x0000ff00) >> 8;
int aB = aRGB & 0x000000ff;
int bB = bRGB & 0x000000ff;
double sqrt;
dist = sqr(((aR - bR) * (aR - bR) +
(aG - bG) * (aG - bG) +
(aB - bB) * (aB - bB))
* 1.0);
}
// TODO Auto-generated method stub
}
private static double sqr(double d) {
// TODO Auto-generated method stub
return 0;
}
}
这个程序在eclipse上运行有错误,希望大神讲详细点,谢谢。。。