OpenCV does not read arbitrary XML.
cv::FileStorage
is made to store and read OpenCV types like cv::Mat
only. It assumes a specific structure to the file. This is specific to cv::FileStorage
.
For your data as it is formatted, you need to use a library for XML in general. OpenCV is not supposed to read arbitrary XML.
If you can change your file’s format to fit cv::FileStorage
, then sure, you can use it to read the file.
cv:FileStorage
would produce this format:
# images = ['20170720_024951.jpg', '20170720_025001.jpg', '20170720_025014.jpg', '20170720_025023.jpg', '20170720_025034.jpg', '20170720_025048.jpg', '20170720_025103.jpg', '20170720_025115.jpg', '20170720_025124.jpg', '20170720_025133.jpg', '20170720_025147.jpg', '20170720_025155.jpg', '20170720_025211.jpg']
fs = cv.FileStorage(
"opencv-filestorage.xml",
cv.FileStorage_WRITE | cv.FileStorage_FORMAT_XML)
fs.write("images", images)
fs.release()
The XML file:
<?xml version="1.0"?>
<opencv_storage>
<images>
"20170720_024951.jpg" "20170720_025001.jpg" "20170720_025014.jpg"
"20170720_025023.jpg" "20170720_025034.jpg" "20170720_025048.jpg"
"20170720_025103.jpg" "20170720_025115.jpg" "20170720_025124.jpg"
"20170720_025133.jpg" "20170720_025147.jpg" "20170720_025155.jpg"
"20170720_025211.jpg"</images>
</opencv_storage>
That format you can read with cv::FileStorage
.
fs = cv.FileStorage(
"opencv-filestorage.xml",
cv.FileStorage_READ | cv.FileStorage_FORMAT_XML)
node = fs.getNode("images")
assert node.isSeq()
print(node.size(), "images")
images = [
node.at(i).string()
for i in range(node.size())
]