目录
python 保存 视频的轮廓点,1800个,最高效的存取方式是什么
import numpy as np
# 假设 contours 是一个 list,每帧一个 list of (x, y) 点
# 比如:contours[帧号] = [(x1, y1), (x2, y2), ...]
contours = [...] # 你的1800帧轮廓数据
# 转成统一结构,假设每帧点数不一致,需用 object dtype
contours_array = np.array(contours, dtype=object)
# 保存为 .npy
np.save('contours.npy', contours_array)
# 读取
loaded_contours = np.load('contours.npy', allow_pickle=True)
np.savez('contours_data.npz', contours=contours_array, other_data=...)
补充选项:pickle
(Python专用格式)
import pickle
with open('contours.pkl', 'wb') as f:
pickle.dump(contours, f)
with open('contours.pkl', 'rb') as f:
contours = pickle.load(f)
适合你完全在 Python 环境内使用(比 json
更快,但不如 npy
干净可靠)。