Subversion Repositories seema-scanner

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
203 jakw 1
function theStruct = readOpenCVXML(filename)
2
 
3
try
4
   tree = xmlread(filename);
5
catch
6
   error('Failed to read XML file %s.',filename);
7
end
8
 
9
opencv_storage = tree.item(0);
10
 
11
if opencv_storage.hasChildNodes
12
   objects = opencv_storage.getChildNodes;
13
   numObjects = objects.getLength;
14
 
15
   theStruct = struct();
16
 
17
    for count = 1:numObjects
18
        object = objects.item(count-1);
19
 
20
        name = char(object.getNodeName);
21
 
22
        if strcmp(name, '#text')
23
            continue;
24
        end
25
 
26
        % if object is a matrix
27
        if object.hasAttributes
28
            attributes = object.getAttributes;
29
            aName = attributes.item(0).getName;
30
            aValue = attributes.item(0).getValue;
31
            if(strcmp(aName, 'type_id') && strcmp(aValue, 'opencv-matrix'))
32
 
33
                fields = object.getChildNodes;
34
                rows = str2double(fields.item(1).item(0).getData);
35
                %cols = str2double(fields.item(3).item(0).getData);
36
                %data = str2num(fields.item(7).item(0).getData);
37
                data = sscanf(char(fields.item(7).item(0).getData), '%f ');
38
                if ~isempty(data)
39
                    data = reshape(data, rows, []);
40
                    theStruct = setfield(theStruct, name, transpose(data));
41
                end
42
            end
43
        % if object is a scalar
44
        else
45
            data = str2double(object.item(0).getData);
46
            theStruct = setfield(theStruct, name, data);
47
        end
48
 
49
 
50
    end
51
end