日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 人文社科 > 生活经验 >内容正文

生活经验

bash脚本【一】——批量处理文件

發(fā)布時間:2023/11/27 生活经验 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 bash脚本【一】——批量处理文件 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Bash腳本2.0?

?

#!/bin/bashoutput_root_dir="0723weixin"
data_root_dir="D:/data/"$output_root_dir
config_dir="config"# speckle_name="SPEACKLEIMAGE.bmp"
# ir_name="IRIMAGE.bmp"
# rgb_name="RGBIMAGE.jpg"
# config_name="config"speckle_name="speckle.bmp"
ir_name="ir.bmp"
rgb_name="rgb.jpg"
config_name="config"dir=$(ls -l $data_root_dir  |awk '/^d/ {print $NF}')
for subdir in $dir
doif [ "$subdir" != "$config_dir" ];then#echo $subdirdir1=$(ls -l $data_root_dir/$subdir |awk '/^d/ {print $NF}')for subdir1 in $dir1do#echo $data_root_dir/$subdir/$subdir1for((index=1;index<=10 ;index++))dofile_ir=$(ls -l $data_root_dir/$subdir/$subdir1/raw  |awk '/^-/ {print $NF}' |awk '/ir/ {print $NF}' | awk '/_'$index'.bmp/ {print $1}')file_speckle=$(ls -l $data_root_dir/$subdir/$subdir1/raw  |awk '/^-/ {print $NF}' |awk '/speckle/ {print $NF}' | awk '/_'$index'.bmp/ {print $1}')file_rgb=$(ls -l $data_root_dir/$subdir/$subdir1/data/rgb  |awk '/^-/ {print $NF}' |awk '/rgb/ {print $NF}' | awk '/_'$index'.jpg/ {print $1}')echo $data_root_dir/$subdir/$subdir1/raw/$file_irecho $data_root_dir/$subdir/$subdir1/raw/$file_speckleecho $data_root_dir/$subdir/$subdir1/data/rgb/$file_rgbmkdir -vp ./data/$subdir/$subdir1/$index/#mkdir -vp ./data/$output_root_dir/$subdir/$subdir1/raw/$index/./bin/RelWithDebInfo/depth_magic_runner.exe \$data_root_dir/$subdir/$subdir1/raw/$file_speckle \--ir $data_root_dir/$subdir/$subdir1/raw/$file_ir \--rgb $data_root_dir/$subdir/$subdir1/data/rgb/$file_rgb \--config $data_root_dir/$config_dir/$config_name \# --set_depth_hdr_mode=true# --rotate_ir_img=truemv -f ./debug_output/* ./data/$subdir/$subdir1/$index/#mv -f ./debug_output/* ./data/$output_root_dir/$subdir/$subdir1/raw/$index/donedone   fi
done   

Bash腳本1.0?

#!/bin/bashdir=(
"100cm三角/"                
"80cm三角/"                   
)for((i=0;i<=30 ;i++))doecho "The dir is: ${dir[$i]}"mkdir -vp ./data/${dir[$i]}/depth_image/./bin/depth_magic_runner /home/sun/company/優(yōu)圖測試0616/${dir[$i]}\1SPEACKLEIMAGE.bmp \--ir /home/sun/company/優(yōu)圖測試0616/${dir[$i]}\1IRIMAGE.bmp  \--rgb /home/sun/company/優(yōu)圖測試0616/${dir[$i]}\1RGBIMAGE.jpg \--config /home/sun/company/004/ --deptrum_prefix ./data/${dir[$i]}/depth_image/done# do
#   for((i=1;i<=1 ;i++))
#   do
#     for((index=1;index<=1;index++))
#     do
#     echo "The dir is:${dir[$i]}/$index"
#     mkdir -vp ./data/${dir[$i]}/depth_image\[$index\]/
#     ./bin/depth_magic_runner /home/sun/company/優(yōu)圖測試0616/${dir[$i]}\[$index\]SPEACKLEIMAGE.bmp \
#     --ir /home/sun/company/優(yōu)圖測試0616/${dir[$i]}\[$index\]IRIMAGE.bmp  \
#     --rgb /home/sun/company/優(yōu)圖測試0616/${dir[$i]}\[$index\]1RGBIMAGE.jpg \
#     --config /home/sun/company/004/ --deptrum_prefix ./data/${dir[$i]}/depth_image\[$index\]/
#     done
#   done
# donesun@sun:~/company/deptrum/depth-magic$ 

?

  for((i=1;i<=31 ;i++))doecho "The dir is: ${dir[$i]}"mkdir -vp ./data/${dir[$i]}/depth_image/./bin/depth_magic_runner /home/sun/company/優(yōu)圖測試0616/${dir[$i]}\1SPEACKLEIMAGE.bmp \--ir /home/sun/company/優(yōu)圖測試0616/${dir[$i]}\1IRIMAGE.bmp  \--rgb /home/sun/company/優(yōu)圖測試0616/${dir[$i]}\1RGBIMAGE.jpg \--config /home/sun/company/004/ --deptrum_prefix ./data/${dir[$i]}/depth_image/done
#!/bin/bash# index=1
# while(( $index<=10 ))
# do
#     mkdir -vp ./data1/speckle_raw\[$index\]/
#     echo $index
#     ./depth_magic_runner ~/data/fill_hole/50/LaserOn/IR_RAW/speckle_raw\[$index\].raw --ir ~/data/fill_hole/50/LaserOff/IR_RAW/speckle_raw\[$index\].raw  --rgb ~/data/fill_hole/50/LaserOn/RGB/rgb\[$index\].bmp --config ~/data/fill_hole/001/ --deptrum_prefix ./data1/speckle_raw\[$index\]/
#     let "index++"
# done# int=1
# while(( $int<=5 ))
# do
#     echo $int
#     let "int++"
# donedir=(
"Dis_30_Cur_1.8_Exp_2.1_Gain_1_2020-06-01-14-06-15-680/"              
"Dis_30_Cur_1.8_Exp_2.2_Gain_1_2020-06-01-14-06-18-623/"              
)dir1=(
"Dis\ \(30\)\ Cur\ \(1.8\)\ Exp\ \(2.1\)\ Gain\ \(1\)_2020-06-01-14-06-15-680/"                        
"Dis\ \(30\)\ Cur\ \(1.8\)\ Exp\ \(2.2\)\ Gain\ \(1\)_2020-06-01-14-06-18-623/"                        
)# for distance in 30 50 80 100
for distance in 100
dofor((i=1;i<=1 ;i++))dofor((index=1;index<=10;index++))doecho "The dir is: $distance/${dir[$i]}/$index"mkdir -vp ./data2/$distance/${dir[$i]}/speckle_raw\[$index\]/./depth_magic_runner ~/data/fill_hole/Fatman-mini-001_NBF_人臉#0601/$distance/$i/LaserOn/IR_RAW/speckle_raw\[$index\].raw \--ir ~/data/fill_hole/Fatman-mini-001_NBF_人臉#0601/$distance/$i/LaserOff/IR_RAW/speckle_raw\[$index\].raw  \--rgb ~/data/fill_hole/Fatman-mini-001_NBF_人臉#0601/$distance/$i/LaserOn/RGB/rgb\[$index\].bmp \--config ~/data/fill_hole/Fatman-mini-001_NBF_1.8A#0512/ --deptrum_prefix ./data2/$distance/${dir[$i]}/speckle_raw\[$index\]/donedone
done

批量讀文件批量命名

#include <gflags/gflags.h>int aa = 0;
DEFINE_string(deptrum_edge, "./debug_output/", "Prefix to be added to the debug output filename");std::string edge_image_name = FLAGS_deptrum_edge + std::to_string(aa++)+"rgb_roi_on_color.bmp";
cv::imwrite(edge_image_name, trace_edge_color);

之前幫師弟寫個一個批量讀取圖片并且批量修改圖片名的功能的小程序,mark一下便于以后復(fù)用。

#include <iostream>    
#include <sstream> 
#include <string>    
#include <io.h> 
#include <string.h>
using namespace std;
const int N = 4;
const string fileType = ".jpg";
string int2string(int n, int i);
/*created by sunshine on 2018/5/2*/
int main()
{_finddata_t file;  string fileDirectory = "C:\\Users\\Administrator\\Desktop\\owner\\一餐廳"; //文件夾目錄,自己修改  string buffer = fileDirectory + "\\*" + fileType;intptr_t hFile;hFile = _findfirst(buffer.c_str(), &file); if (hFile == -1L)cout << "沒有指定格式的圖片" << endl;//沒有指定格式的圖片  else{/**   序號控制  你只需要改正i就OK了,然后配合上面的string fileDirectory指向你的絕對路徑  ,后期要是大批量處理的話  可以在進(jìn)一步擴(kuò)展一下這個程序*/int i = 530;string newFullFilePath;string oldFullFilePath;string strName;do{oldFullFilePath.clear();newFullFilePath.clear();strName.clear();oldFullFilePath = fileDirectory + "\\" + file.name;++i;strName = int2string(N, i); //類型轉(zhuǎn)換  //char p[20] = "mi-note3-0102-"//第二個字符串  //strName =strcpy(strName, p);//將第一個字符串p拷貝到q中 newFullFilePath = fileDirectory + "\\" +"mi-note3-0102-"+ strName + fileType;int c = rename(oldFullFilePath.c_str(), newFullFilePath.c_str());//重命名  if (c == 0)cout << "重命名成功" << strName << fileType << endl;elsecout << "重命名失敗" << strName << fileType << endl;} while (_findnext(hFile, &file) == 0);_findclose(hFile);}system("pause");return 0;
}string int2string(int n, int i)
{char s[BUFSIZ];sprintf_s(s, "%d", i);int len = strlen(s);if (len > n){cout << "輸入的N太小!";}else{stringstream Num;for (int i = 0; i < n - len; i++)Num << "0";Num << i;return Num.str();}
}
  std::string filename1 = "./debug_output/points1.txt";FILE* fp = fopen(filename1.c_str(), "at+");cv::Mat norm_obj_points, norm_ref_points;for (std::vector<cv::Point2d>::iterator points1it = points1.begin(); points1it != points1.end(); points1it++) {//std::cout << (*vit).x<<"     " << (*vit).y << std::endl;fprintf(fp,"%10.4f%10.4f\n",(*points1it).x,(*points1it).y);}fclose(fp);std::string filename2 = "./debug_output/points2.txt";FILE* fp2 = fopen(filename2.c_str(), "at+");for (std::vector<cv::Point2d>::iterator points2it = points2.begin(); points2it != points2.end(); points2it++) {//std::cout << (*vit).x<<"     " << (*vit).y << std::endl;fprintf(fp2,"%10.4f%10.4f\n",(*points2it).x,(*points2it).y);}fclose(fp2);

?? ?std::string filename = "./debug_output/theta.txt";
?? ?FILE* fp = fopen(filename.c_str(), "at+");?? ??? ?
?? ??? ??? ??? ??? ?fprintf(fp,
?? ??? ??? ??? ??? ??? ??? ?"%10.4f %10.3f %10.3f %10.3f %10.2f\n",
?? ??? ??? ??? ??? ??? ??? ?self_calib_theta_,
?? ??? ??? ??? ??? ??? ??? ?self_calib_theta_x,
?? ??? ??? ??? ??? ??? ??? ?self_calib_theta_y,
?? ??? ??? ??? ??? ??? ??? ?self_calib_theta_z,
?? ??? ??? ??? ??? ??? ? ? ?mean_move_y);

?? ?fclose(fp);

總結(jié)

以上是生活随笔為你收集整理的bash脚本【一】——批量处理文件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。