当前位置: 代码迷 >> Java相关 >> 希望各位大神看看,代码有点长,新手希望大家多多赐教
  详细解决方案

希望各位大神看看,代码有点长,新手希望大家多多赐教

热度:309   发布时间:2013-09-15 17:12:52.0
希望各位大神看看,代码有点长,新手希望大家多多赐教
package jianmo;

import java.awt.image.BufferedImage;
import java.io.File;
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上运行有错误,希望大神讲详细点,谢谢。。。
搜索更多相关的解决方案: import  public  package  Desktop  Users  

----------------解决方案--------------------------------------------------------
你代码编译没有报错????
----------------解决方案--------------------------------------------------------
这个编译到处都是错,你怎么运行的???
----------------解决方案--------------------------------------------------------
你想实现什么?
----------------解决方案--------------------------------------------------------
程序代码:
String path = "E:\\Media";  //文件路径(我电脑上的,你换成上面的)
        File file = new File(path);
        File[] fileList = file.listFiles();
        for(File filename : fileList){
            System.out.println(filename); //打印文件名
}

这段代替
  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
你这段代码根本编译不过。
这样你就可以读文件名了,然后自己再看看,自己哪里哟偶问题,我拷贝你代码到myeclipse上面到处是红的。都不知道你哪些变量和方法从哪里来的,自己调试下。
----------------解决方案--------------------------------------------------------
好的
----------------解决方案--------------------------------------------------------
搞定了问题结贴啊
----------------解决方案--------------------------------------------------------
  相关解决方案