Blame | Last modification | View Log | RSS feed
function theStruct = readOpenCVXML(filename)
try
tree = xmlread(filename);
catch
error('Failed to read XML file %s.',filename);
end
opencv_storage = tree.item(0);
if opencv_storage.hasChildNodes
objects = opencv_storage.getChildNodes;
numObjects = objects.getLength;
theStruct = struct();
for count = 1:numObjects
object = objects.item(count-1);
name = char(object.getNodeName);
if strcmp(name, '#text')
continue;
end
% if object is a matrix
if object.hasAttributes
attributes = object.getAttributes;
aName = attributes.item(0).getName;
aValue = attributes.item(0).getValue;
if(strcmp(aName, 'type_id') && strcmp(aValue, 'opencv-matrix'))
fields = object.getChildNodes;
rows = str2double(fields.item(1).item(0).getData);
%cols = str2double(fields.item(3).item(0).getData);
%data = str2num(fields.item(7).item(0).getData);
data = sscanf(char(fields.item(7).item(0).getData), '%f ');
if ~isempty(data)
data = reshape(data, rows, []);
theStruct = setfield(theStruct, name, transpose(data));
end
end
% if object is a scalar
else
data = str2double(object.item(0).getData);
theStruct = setfield(theStruct, name, data);
end
end
end