我想使用OpenCV filestorage类输出XML文件。但输出与我想要的不一样。我需要帮助以不同的格式编写数据。以下是功能代码。
void write_data(int x, int y, int w, int h, int count, int region)
{
FileStorage fs("data.xml", FileStorage::APPEND);
fs <<"frame";
fs << "{" << "number" <<count
<< "}";
fs << "box";
fs << "{" << "h" << h;
fs << "w" << w;
fs << "xc" << x;
fs << "yc" << y
<< "}";
fs.release();
cout << "Write Done." << endl;
}
输出
<?xml version="1.0"?>
<opencv_storage>
<frame>
<number>1</number></frame>
<box>
<h>52</h>
<w>52</w>
<xc>1156</xc>
<yc>336</yc></box>
<!-- resumed -->
<frame>
<number>1</number></frame>
<box>
<h>69</h>
<w>69</w>
<xc>1112</xc>
<yc>376</yc></box>
<!-- resumed -->
以下是所需的输出。对于&#34;自信&#34;的价值我想生成一个介于0.5000到1.0之间的随机数。
<frame number="1">
<objectlist>
<object confidence="0.89324">
<box h="52" w="52" xc="1156" yc="336" />
</object>
<object confidence="0.95996">
<box h="69" w="69" xc="1112" yc="376" />
</object>
</objectlist>
</frame>
<frame number="2">
<objectlist>
<object confidence="0.89324">
<box h="42" w="38" xc="521" yc="94" />
</object>
<object confidence="0.95996">
<box h="38" w="39" xc="633" yc="99" />
</object>
</objectlist>
</frame>