【发布时间】:2019-08-30 08:56:46
【问题描述】:
我需要在numpy.ndarray 中找到png 文件。甚至有可能吗?
list_of_files 包含扩展名为 ['jpg', 'jpeg', 'bmp', 'tif', 'tiff', 'png'] 的文件。
for f in list_of_files:
stream = open(f, 'rb')
bytes = bytearray(stream.read())
numpy_array = numpy.asarray(bytes, dtype=numpy.uint8)
image = cv2.imdecode(numpy_array, cv2.IMREAD_UNCHANGED)
【问题讨论】:
-
您应该对字符串本身进行解码,而不是对 numpy 数组进行解码。你是什么意思“数组中的png文件”?
-
您是否有理由不打开带有 png 扩展名的文件?您是否也在尝试查找没有扩展名或错误扩展名的 png 文件?