确保Numpy数组是内存连续的,可以使用np.ascontiguousarray。 代码语言:txt 复制 array = np.ascontiguousarray(array) 3. 检查维度 确保Numpy数组的维度正确。对于彩色图像,通常是(height, width, 3)或(height, width, 4)。 代码语言:txt 复制 if array.ndim != 3 or array.shape[2] not in [3, 4]: ...