【BAT】批量测试运行结果

来源:互联网 发布:价格监控软件开发 编辑:程序博客网 时间:2024/05/22 06:52


目录(?)
[+]

经常用到批处理,但还是各种不熟。记录一些写的小文件,以后方便查询~

生成文件目录

将文件(及子文件下的图片)写入list.txt
[plain] view plaincopy
  1. @echo off&setlocal enabledelayedexpansion  
  2. for /r %%i in (*.jpg *.png *.tif) do (  
  3. echo %%i >>list.txt  
  4. )  
  5. pause  

测试文件,统计结果

使用test.exe测试list.txt中的文件,并记录结果,测试失败会输出“decoding failed”

[plain] view plaincopy
  1. @echo off  
  2.   
  3. set /a passed=0  
  4. set /a all=0  
  5.   
  6. del /f /s /q result.txt  
  7.   
  8. for %%p in (*.jpg *.png) do Release\test.exe %%p --more >>list.txt  
  9.   
  10. for /f "delims=" %%i in (result.txt) do (   
  11.     echo %%i  
  12.     if not "%%i"=="decoding failed" set /a passed=passed+1  
  13.     set /a all=all+1  
  14. )  
  15. echo %passed% passed in %all% pictures  

test.exe 可以接受几种可选参数:
[cpp] view plaincopy
  1. int main(int argc, char** argv) {  
  2.   if (argc <= 1) {  
  3.     cout << "Usage: " << argv[0] << " [OPTION]... <IMAGE>..." << endl  
  4.          << "Read barcodes from each IMAGE file." << endl  
  5.          << endl  
  6.          << "Options:" << endl  
  7.          << "  (-h|--hybrid)             use the hybrid binarizer (default)" << endl  
  8.          << "  (-g|--global)             use the global binarizer" << endl  
  9.          << "  (-v|--verbose)            chattier results printing" << endl  
  10.          << "  --more                    display more information about the barcode" << endl  
  11.          << "  --test-mode               compare IMAGEs against text files" << endl  
  12.          << "  --try-harder              spend more time to try to find a barcode" << endl  
  13.          << "  --search-multi            search for more than one bar code" << endl  
  14.          << endl  
  15.          << "Example usage:" << endl  
  16.          << "  zxing --test-mode *.jpg" << endl  
  17.          << endl;  
  18.     return 1;  
  19.   }  
  20.   
  21.   int total = 0;  
  22.   int gonly = 0;  
  23.   int honly = 0;  
  24.   int both = 0;  
  25.   int neither = 0;  
  26.   
  27.   for (int i = 1; i < argc; i++) {  
  28.     string filename = argv[i];  
  29.     if (filename.compare("--verbose") == 0 ||  
  30.         filename.compare("-v") == 0) {  
  31.       verbose = true;  
  32.       continue;  
  33.     }  
  34.     if (filename.compare("--hybrid") == 0 ||  
  35.         filename.compare("-h") == 0) {  
  36.       use_hybrid = true;  
  37.       continue;  
  38.     }  
  39.     if (filename.compare("--global") == 0 ||  
  40.         filename.compare("-g") == 0) {  
  41.       use_global = true;  
  42.       continue;  
  43.     }  
  44.     if (filename.compare("--more") == 0) {  
  45.       more = true;  
  46.       continue;  
  47.     }  
  48.     if (filename.compare("--test-mode") == 0) {  
  49.       test_mode = true;  
  50.       continue;  
  51.     }  
  52.     if (filename.compare("--try-harder") == 0) {  
  53.       try_harder = true;  
  54.       continue;  
  55.     }  
  56.     if (filename.compare("--search-multi") == 0){  
  57.       search_multi = true;  
  58.       continue;  
  59.     }  
  60.   
  61.     if (filename.length() > 3 &&  
  62.         (filename.substr(filename.length() - 3, 3).compare("txt") == 0 ||  
  63.          filename.substr(filename.length() - 3, 3).compare("bin") == 0)) {  
  64.       continue;  
  65.     }  
  66.   
  67.     if (!use_global && !use_hybrid) {  
  68.       use_global = use_hybrid = true;  
  69.     }  
  70.   
  71.     if (test_mode) {  
  72.       cerr << "Testing: " << filename << endl;  
  73.     }  
  74.   
  75.     Ref<LuminanceSource> source;  
  76.     try {  
  77.       source = ImageReaderSource::create(filename);  
  78.     } catch (const zxing::IllegalArgumentException &e) {  
  79.       cerr << e.what() << " (ignoring)" << endl;  
  80.       continue;  
  81.     }  
  82.   
  83.     string expected = read_expected(filename);  
  84.   
  85.     int gresult = 1;  
  86.     int hresult = 1;  
  87.     if (use_hybrid) {  
  88.       hresult = read_image(source, true, expected);  
  89.     }  
  90.     if (use_global && (verbose || hresult != 0)) {  
  91.       gresult = read_image(source, false, expected);  
  92.       if (!verbose && gresult != 0) {  
  93.         cout << "decoding failed" << endl;  
  94.       }  
  95.     }  
  96.     gresult = gresult == 0;  
  97.     hresult = hresult == 0;  
  98.     gonly += gresult && !hresult;  
  99.     honly += hresult && !gresult;  
  100.     both += gresult && hresult;  
  101.     neither += !gresult && !hresult;  
  102.     total = total + 1;  
  103.   }  
  104.   
  105.   if (test_mode) {  
  106.     cout << endl  
  107.          << "Summary:" << endl  
  108.          << " " << total << " images tested total," << endl  
  109.          << " " << (honly + both)  << " passed hybrid, " << (gonly + both)  
  110.          << " passed global, " << both << " pass both, " << endl  
  111.          << " " << honly << " passed only hybrid, " << gonly  
  112.          << " passed only global, " << neither << " pass neither." << endl;  
  113.   }  
  114.   
  115.   return 0;  
  116. }  


(转载请注明作者和出处:http://blog.csdn.net/xiaowei_cqu 未经允许请勿用于商业用途)

原创粉丝点击