import numpy as np import os from glob import glob from pathlib import Path from multiprocessing import Pool import argparse ######################################################## # 函数区 ######################################################## spacetySliceEnvPathExEPath=r"D:\ProgramData\miniconda3\envs\spacetySliceEnv\python.exe" def find_tif_files_pathlib(directory): """ 使用pathlib.Path.rglob递归查找指定目录下所有.tif和.tiff文件 参数: directory (str): 要搜索的根目录路径 返回: list: 包含所有找到的.tif/.tiff文件完整路径的列表 """ path = Path(directory) # 使用rglob递归匹配所有.tif和.tiff文件 tif_files = list(path.rglob('*.bin')) # 将Path对象转换为字符串路径 return [str(file) for file in tif_files] def find_txt_files_pathlib(directory): """ 使用pathlib.Path.rglob递归查找指定目录下所有.tif和.tiff文件 参数: directory (str): 要搜索的根目录路径 返回: list: 包含所有找到的.tif/.tiff文件完整路径的列表 """ path = Path(directory) # 使用rglob递归匹配所有.tif和.tiff文件 tif_files = list(path.rglob('*.txt')) # 将Path对象转换为字符串路径 return [str(file) for file in tif_files] def matchTiff_Txt(tiffpaths,txtPaths): match_results={} tiffID=0 for tid in range(len(tiffpaths)): tiffID=tiffID+1 match_results[tiffID]={"tiff":tiffpaths[tid],"txt":[]} rootname=Path(tiffpaths[tid]).stem for txtpath in txtPaths: txtrootname=Path(txtpath).stem if txtrootname.startswith(rootname): match_results[tiffID]["txt"].append(txtpath) return match_results def getParams(): parser = argparse.ArgumentParser() parser.add_argument('-i','--inbinfile',type=str,default=r'D:\Annotation_Y\港口\聚束模式\20250505_sp\bc3-sp-org-vv-20250410t053930-020615-000034-005087-01.tiff', help='输入tiff的bin文件') parser.add_argument('-l', '--labelfilepath',type=str,default=r"D:\Annotation_Y\港口\聚束模式\20250505_sp\bc3-sp-org-vv-20250410t053930-020615-000034-005087-01_LC.txt", help='输入标注') parser.add_argument('-o', '--outfolderpath',type=str,default=r'D:\Annotation_Y\结果文件', help='切片文件夹地址') args = parser.parse_args() return args