function writeXML(
name,fc,kc,alpha_c,cc,om,t )
%WRITEXML write mat to xml
file
% this function is
used to convert matrix information from matlab to
% opencv
kk=[fc(1) alpha_c*fc(1) cc(1); 0 fc(2)
cc(2);0 0 1];
%write FC
xdoc=com.mathworks.xml.XMLUtils.createDocument('opencv_storage');
xroot=xdoc.getDocumentElement;
[m,n]=size(fc);
type=xdoc.createElement_x_x_x_x_x('fc');
type.setAttribute('type_id','opencv-matrix')
xroot.a(type);
rows=xdoc.createElement_x_x_x_x_x('rows');
rows.a(xdoc.createTextNode(sprintf('%d',m)));
type.a(rows);
cols=xdoc.createElement_x_x_x_x_x('cols');
cols.a(xdoc.createTextNode(sprintf('%d',n)));
type.a(cols);
dt=xdoc.createElement_x_x_x_x_x('dt');
dt.a(xdoc.createTextNode(sprintf('%s','d')));
type.a(dt);
data=xdoc.createElement_x_x_x_x_x('data');
for i=1:m
for j=1:n
data.a(xdoc.createTextNode(sprintf('%d',fc(i,j))));
data.a(xdoc.createTextNode(sprintf('%s','
')));
end
end
type.a(data);
%write KC
[m,n]=size(kc);
type=xdoc.createElement_x_x_x_x_x('kc');
type.setAttribute('type_id','opencv-matrix')
xroot.a(type);
rows=xdoc.createElement_x_x_x_x_x('rows');
rows.a(xdoc.createTextNode(sprintf('%d',m)));
type.a(rows);
cols=xdoc.createElement_x_x_x_x_x('cols');
cols.a(xdoc.createTextNode(sprintf('%d',n)));
type.a(cols);
dt=xdoc.createElement_x_x_x_x_x('dt');
dt.a(xdoc.createTextNode(sprintf('%s','d')));
type.a(dt);
data=xdoc.createElement_x_x_x_x_x('data');
for i=1:m
for j=1:n
data.a(xdoc.createTextNode(sprintf('%d',kc(i,j))));
data.a(xdoc.createTextNode(sprintf('%s','
')));
end
end
type.a(data);
%write ALPHA_C
[m,n]=size(alpha_c);
type=xdoc.createElement_x_x_x_x_x('alpha_c');
type.setAttribute('type_id','opencv-matrix')
xroot.a(type);
rows=xdoc.createElement_x_x_x_x_x('rows');
rows.a(xdoc.createTextNode(sprintf('%d',m)));
type.a(rows);
cols=xdoc.createElement_x_x_x_x_x('cols');
cols.a(xdoc.createTextNode(sprintf('%d',n)));
type.a(cols);
dt=xdoc.createElement_x_x_x_x_x('dt');
dt.a(xdoc.createTextNode(sprintf('%s','d')));
type.a(dt);
data=xdoc.createElement_x_x_x_x_x('data');
for i=1:m
for j=1:n
data.a(xdoc.createTextNode(sprintf('%d',alpha_c(i,j))));
data.a(xdoc.createTextNode(sprintf('%s','
')));
end
end
type.a(data);
%write CC
[m,n]=size(cc);
type=xdoc.createElement_x_x_x_x_x('cc');
type.setAttribute('type_id','opencv-matrix')
xroot.a(type);
rows=xdoc.createElement_x_x_x_x_x('rows');
rows.a(xdoc.createTextNode(sprintf('%d',m)));
type.a(rows);
cols=xdoc.createElement_x_x_x_x_x('cols');
cols.a(xdoc.createTextNode(sprintf('%d',n)));
type.a(cols);
dt=xdoc.createElement_x_x_x_x_x('dt');
dt.a(xdoc.createTextNode(sprintf('%s','d')));
type.a(dt);
data=xdoc.createElement_x_x_x_x_x('data');
for i=1:m
for j=1:n
data.a(xdoc.createTextNode(sprintf('%d',cc(i,j))));
data.a(xdoc.createTextNode(sprintf('%s','
')));
end
end
type.a(data);
%write KK
[m,n]=size(kk);
type=xdoc.createElement_x_x_x_x_x('kk');
type.setAttribute('type_id','opencv-matrix')
xroot.a(type);
rows=xdoc.createElement_x_x_x_x_x('rows');
rows.a(xdoc.createTextNode(sprintf('%d',m)));
type.a(rows);
cols=xdoc.createElement_x_x_x_x_x('cols');
cols.a(xdoc.createTextNode(sprintf('%d',n)));
type.a(cols);
dt=xdoc.createElement_x_x_x_x_x('dt');
dt.a(xdoc.createTextNode(sprintf('%s','d')));
type.a(dt);
data=xdoc.createElement_x_x_x_x_x('data');
for i=1:m
for j=1:n
data.a(xdoc.createTextNode(sprintf('%d',kk(i,j))));
data.a(xdoc.createTextNode(sprintf('%s','
')));
end
end
type.a(data);
%write OM
[m,n]=size(om);
type=xdoc.createElement_x_x_x_x_x('om');
type.setAttribute('type_id','opencv-matrix')
xroot.a(type);
rows=xdoc.createElement_x_x_x_x_x('rows');
rows.a(xdoc.createTextNode(sprintf('%d',m)));
type.a(rows);
cols=xdoc.createElement_x_x_x_x_x('cols');
cols.a(xdoc.createTextNode(sprintf('%d',n)));
type.a(cols);
dt=xdoc.createElement_x_x_x_x_x('dt');
dt.a(xdoc.createTextNode(sprintf('%s','d')));
type.a(dt);
data=xdoc.createElement_x_x_x_x_x('data');
for i=1:m
for j=1:n
data.a(xdoc.createTextNode(sprintf('%d',om(i,j))));
data.a(xdoc.createTextNode(sprintf('%s','
')));
end
end
type.a(data);
%write T
[m,n]=size(t);
type=xdoc.createElement_x_x_x_x_x('t');
type.setAttribute('type_id','opencv-matrix')
xroot.a(type);
rows=xdoc.createElement_x_x_x_x_x('rows');
rows.a(xdoc.createTextNode(sprintf('%d',m)));
type.a(rows);
cols=xdoc.createElement_x_x_x_x_x('cols');
cols.a(xdoc.createTextNode(sprintf('%d',n)));
type.a(cols);
dt=xdoc.createElement_x_x_x_x_x('dt');
dt.a(xdoc.createTextNode(sprintf('%s','d')));
type.a(dt);
data=xdoc.createElement_x_x_x_x_x('data');
for i=1:m
for j=1:n
data.a(xdoc.createTextNode(sprintf('%d',t(i,j))));
data.a(xdoc.createTextNode(sprintf('%s','
')));
end
end
type.a(data);
str=strcat(name,'.xml');
xmlwrite(str,xdoc);
end
--------------4.C++读取代码--------------