使用 python 从 XML 文件中提取 2D 数组数据



我有一个立体图像的深度图女巫被保存为xml文件,我想从这个文件中提取2D浮点数组并将其保存为浮点图像,我解决了我的请求女巫的第二部分是将2D数组保存为浮点图像成功,我已经搜索了相关答案,但没有找到, 那么有人会帮我吗?我的 XML 文件如下所示:

?xml 版本="1.0"?
opencv_storage深度 type_id="OpenCV-matrix" 行480/行  Cols640/ColsDT F/DT数据2.66372559E+02 2.66372559E+02 2.66372559E+02 2.66372559E+02 2.66372559e+02 2.66372559e+02 2.66372559e+02 2.66372559e+02 2.66372559e+02 2.66372559e+02 2.66372559e+02 2.66372559e+02 2.66372559e+02 2.66372559e+02 2.66372559e+02 2.65196075e+02 2.64019592e+02 2.64019592e+02 2.64019592e+02 2.64019592e+02
2.64019592e+02 2.63823517e+02 2.63823517e+02 2.64607849e+02 ....

我已经解决了如下问题:

from PIL import Image
import cv2
cv_file = cv2.FileStorage("test.xml", cv2.FILE_STORAGE_READ)       % reading my xml file as a storage file
matrix = cv_file.getNode("depth").mat()               % getting the node of the 2D array named "depth" as shown in the  above xml file.
img1 = Image.fromarray(matrix)                        % reading the 2D array as an image
img1.save(dest, "tiff")                               % saving the image with a tiff format

最新更新