[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖

[文件操作] 求助批处理实现图片ocr归类

一堆001.jpg  002.jpg  003.jpg……

我用convert截取顶部 然后ocr识别导出tmp.txt

如果txt有银行二字,就截取底部指定位置,ocr识别出数字保存到tmp2.txt 并将这个数字新建文件夹,将被截取的图片放进去。

否则,否则就将图片直接放到上一个新建的文件夹中。
  1. @echo off
  2. Setlocal enabledelayedexpansion
  3. FOR /D %%a IN (*) DO (
  4. echo %%~fa
  5. cd /d %%~fa
  6. for /r %%i in (*.jpg) do (
  7. convert.exe -crop 2470x180+20+193 "%%i" "tmp.jpg"
  8. tesseract "tmp.jpg" "tmp" -l chi_sim
  9. findstr /i "银行" "tmp.txt" >nul
  10. if errorlevel 1 (convert -crop 555x80+505+370 "%%i" "tmp2.jpg"
  11. tesseract.exe "tmp2.jpg" "tmp2" -l chi_sim
  12. ping -n 2 127.0.0.1>nul
  13. set /P file=<"tmp2.txt"
  14. mkdir !file!
  15. move "%%i" !file!
  16. ) else ( set /P file=<"tmp2.txt"
  17. move "%%i" !file!)
  18. )
  19. )
  20. pause
复制代码
现在的问题是,就算tmp.txt没有"银行"二字,他也是会执行  else 之前的步骤。

回复 2# 77七


  我用 &&goto A||goto B
根本不会正常运行。直接就是B

TOP

回复 4# 77七

现在可以运行了,但是只运行了一次 :A, 然后就对话框结束了。不会继续处理jpg图片啊
  1. @echo off
  2. Setlocal enabledelayedexpansion
  3. chcp 65001
  4. FOR /D %%a IN (*) DO (
  5. echo %%~fa
  6. cd /d %%~fa
  7. for /r %%i in (*.jpg) do (
  8. set pic=%%~ni.jpg
  9. "C:\Users\暴牙弟\Desktop\ImageMagick\convert.exe" -crop 2470x180+20+193 "%%i" "tmp.jpg"
  10. tesseract "tmp.jpg" "tmp" -l chi_sim
  11. find /i "银行" tmp.txt>nul&&echo goto :A||goto :B
  12. :A
  13. "C:\Users\暴牙弟\Desktop\ImageMagick\convert.exe" -crop 555x80+505+370 "!pic!" "tmp2.jpg"
  14. tesseract.exe "tmp2.jpg" "tmp2" -l chi_sim
  15. ping -n 2 127.0.0.1>nul
  16. set /p file=<"tmp2.txt"
  17. echo !file!
  18. pause
  19. mkdir !file!
  20. move !pic! !file!
  21. exit /b 0
  22. :B
  23. set /P file=<"tmp2.txt"
  24. move "%%i" !file!
  25. exit /b 0
  26. )
  27. )
  28. pause
复制代码

TOP

回复 6# 77七

不行。我不明白  0001截取肯定是有银行  两个字的,0002是没有的,没有的话应该是 执行else 后面的,但是他依然顺序执行。所以才想办法用goto。但是goto又没法跳回 for /r 那里继续处理

TOP

回复 8# 77七

无论是0还是1 他都会执行
  1. set /p file=<"tmp2.txt"
  2.     mkdir !file!
  3.     echo !file!
复制代码
现在我实在搞不懂了。
如果用goto 和call 我应该怎么添加 跳转回 for /r 上方?

TOP

回复 10# 77七

用这个可以了 谢谢,看来是for  /r的问题

TOP

返回列表