download-onnxocr.ps1 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. # 从 GitHub 下载 OnnxOCR 到当前 python 目录
  2. # 用法:在 PowerShell 中执行 .\download-onnxocr.ps1
  3. $ErrorActionPreference = "Stop"
  4. $pythonDir = $PSScriptRoot
  5. $zipPath = Join-Path $pythonDir "onnxocr-main.zip"
  6. $extractPath = Join-Path $pythonDir "onnxocr-temp"
  7. $targetPath = Join-Path $pythonDir "OnnxOCR"
  8. Write-Host "Downloading OnnxOCR from GitHub..."
  9. try {
  10. Invoke-WebRequest -Uri "https://github.com/jingsongliujing/onnxocr/archive/refs/heads/main.zip" `
  11. -OutFile $zipPath -UseBasicParsing
  12. } catch {
  13. Write-Host "Download failed. Try git clone:"
  14. Write-Host " cd $pythonDir"
  15. Write-Host " git clone --depth 1 https://github.com/jingsongliujing/onnxocr.git OnnxOCR"
  16. exit 1
  17. }
  18. Write-Host "Extracting..."
  19. if (Test-Path $extractPath) { Remove-Item -Recurse -Force $extractPath }
  20. Expand-Archive -Path $zipPath -DestinationPath $extractPath -Force
  21. $innerFolder = Get-ChildItem $extractPath -Directory | Select-Object -First 1
  22. if ($innerFolder) {
  23. if (Test-Path $targetPath) { Remove-Item -Recurse -Force $targetPath }
  24. Move-Item -Path $innerFolder.FullName -Destination $targetPath
  25. }
  26. Remove-Item -Recurse -Force $extractPath -ErrorAction SilentlyContinue
  27. Remove-Item -Force $zipPath -ErrorAction SilentlyContinue
  28. Write-Host "Done. OnnxOCR is at: $targetPath"