LBP训练正负样本处理

批量重命名图片

public static String [] getFileName(String path)
{
    File file = new File(path);
    String [] fileName = file.list();
    return fileName;
}
 public static void renameFile(String path,String oldname,String newname){
     if(!oldname.equals(newname)){//新的文件名和以前文件名不同时,才有必要进行重命名
         File oldfile=new File(path+"\\"+oldname);
         File newfile=new File(path+"\\"+newname);
         if(!oldfile.exists()){
             return;//重命名文件不存在
         }
         if(newfile.exists())//若在该目录下已经有一个文件和新文件名相同,则不允许重命名
         {

         }
         else{
             oldfile.renameTo(newfile);
         }
     }else{

     }
 }
 public static void main(String[] args)
 {
     String [] fileName = getFileName("E:\\OpenCVCode\\INRIAPerson\\train_64x128_H96\\bg");//<span style="font-family: Arial, Helvetica, sans-serif;">此处修改为你的本地路径</span>
     for (int i = 0; i < fileName.length; i++) {
         renameFile("E:\\OpenCVCode\\INRIAPerson\\train_64x128_H96\\bg", fileName[i], ""+i+".jpg");//cx修改为你要修改的文件名格式
     }
 }

批量生产描述文件

public static void createSampleInfoDataFile(){
    // Context of the app under test.


    try{
        File dir=new File("E:\\OpenCVCode\\INRIAPerson\\train_64x128_H96\\bg");
        File[] subdirs=dir.listFiles();
        File infodata=new File("E:\\OpenCVCode\\INRIAPerson\\train_64x128_H96\\bg.txt");
        PrintWriter pw = new PrintWriter(new FileOutputStream(infodata));
        for(File imgdir : subdirs)
        {
            int w=1;
            int h=1;
            if(dir.listFiles()==null)
            {
                continue;
            }
            for(File file : dir.listFiles())
            {
                BufferedImage image= ImageIO.read(file);
                if(image==null)continue;
                int w=image.getWidth();
                int h=image.getHeifht();
                pw.println("bg"+"/"+file.getName()+" 1 0 0 "+w+h);

            }
        }
        pw.flush();
        pw.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
public static void main(String[] args)
{
    createSampleInfoDataFile();
}

猜你喜欢

转载自blog.csdn.net/YuannaY/article/details/89933646