Subversion Repositories seema-scanner

Rev

Rev 203 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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