This commit is contained in:
HuangHai
2026-01-12 16:12:36 +08:00
parent 8606709510
commit 45303dfcb2
6 changed files with 166 additions and 65 deletions

View File

@@ -12,6 +12,19 @@ logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(level
logger = logging.getLogger(__name__)
def clean_station_name(name):
"""
清理场站名称,去掉末尾的省略号和空格
"""
if not name:
return ""
# 去掉末尾的 ... 或 ……
name = name.strip()
while name.endswith(".") or name.endswith("。"):
name = name[:-1]
return name.strip()
def get_file_md5(file_path):
"""计算文件的 MD5 值"""
if not os.path.exists(file_path):
@@ -25,10 +38,17 @@ def get_file_md5(file_path):
def read_image(path):
"""读取图片,支持中文路径"""
if not path or not os.path.exists(path):
return None
try:
return cv2.imdecode(np.fromfile(path, dtype=np.uint8), -1)
# 使用 np.fromfile 解决中文路径问题
data = np.fromfile(path, dtype=np.uint8)
if data.size == 0:
return None
img = cv2.imdecode(data, -1)
return img
except Exception as e:
logger.info(f"Error reading image {path}: {e}")
logger.error(f"Error reading image {path}: {e}")
return None