matlab生成xml (将SynthText数据转成XML)

本代码主要实现用MATLAB将数据转换成xml格式。以SynthText数据集为例。
若实际使用SynthText数据集时,务必注意其坐标位置的有效性。

clear;clc;

% SynthText数据保存在gt.mat中,导入后生成imnames、charBB、wordBB、tt等数据
load('gt.mat');

for i = 1:size(imnames,2)
    % 选择工作路径
    img = imread(['.../',imnames{1,i}]);  
    [H,W,depth] = size(img);

      % 取出图像名称,命名与图像同名xml文件 
    N1 = regexp(imnames{1,i},'/','split');
    N2 = char(N1(2));
    N3 = N2(1:end-4);
 
    % 新建xml文件 
    annotation = com.mathworks.xml.XMLUtils.createDocument('annotation');
    annotationRoot = annotation.getDocumentElement;  

    % 定义子节点   
    size = annotation.createElement('size');  
    annotationRoot.appendChild(size);  

你可能感兴趣的:(matlab生成xml (将SynthText数据转成XML))