CopyImage.py 962 B

1234567891011121314151617181920212223242526
  1. from pathlib import Path
  2. import requests
  3. imageUrl = "http://192.168.10.18:10088/Table_Figure_V1.3_20230208/train2017/"
  4. destPath = "./project-22-at-2024-09-04-06-33-61be369e"
  5. def download_file(url, local_filename):
  6. # 发送带有流式响应的 GET 请求
  7. with requests.get(url, stream=True) as r:
  8. # 检查请求结果是否成功
  9. if r.status_code == 200:
  10. # 打开本地文件以便写入
  11. with open(local_filename, 'wb') as f:
  12. for chunk in r.iter_content(chunk_size=8192):
  13. # 写入文件块
  14. f.write(chunk)
  15. else:
  16. print(f"Failed to download file: {r.status_code}")
  17. labels_path = Path(destPath+'/labels')
  18. for file in labels_path.iterdir():
  19. if file.is_file():
  20. imageName = file.name.replace('.txt', '.jpg')
  21. download_file(imageUrl+imageName, destPath+'/images/'+imageName)
  22. print('下载完成')