我这里有个小问题,我真的希望某个Linux魔术师能帮我个忙.我有一个文件夹/assets
,里面有.jpg
和.xml
个文件--非常多.
原始的XML struct :
<annotation>
<folder></folder>
<filename>Pro_jpeg.rf.77216510eeb475f923d5bb3bdb22ee11.jpg</filename>
<path>Pro_jpeg.rf.77216510eeb475f923d5bb3bdb22ee11.jpg</path>
<source>
<database>roboflow.ai</database>
</source>
<size>
<width>416</width>
<height>416</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>cheese</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>53</xmin>
<xmax>371</xmax>
<ymin>224</ymin>
<ymax>391</ymax>
</bndbox>
</object>
</annotation>
如果你看一看,你可以看到在<bndbox>
个标签中,我已经遵循了定义的参数:xmin, xmax, ymin and ymax
-在这个序列中.这是错误的,我想用以下顺序更新我所有的.xml文件:xmin, ymin, xmax, ymax
.因此,该文件将以如下形式结束:
<annotation>
<folder></folder>
<filename>Pro_jpeg.rf.77216510eeb475f923d5bb3bdb22ee11.jpg</filename>
<path>Pro_jpeg.rf.77216510eeb475f923d5bb3bdb22ee11.jpg</path>
<source>
<database>roboflow.ai</database>
</source>
<size>
<width>416</width>
<height>416</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>cheese</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>53</xmin>
<ymin>224</ymin>
<xmax>371</xmax>
<ymax>391</ymax>
</bndbox>
</object>
</annotation>
有什么 idea 可以做到这一点吗?提前谢谢你了!
编辑(我当前拥有的内容): 所以我打开终端,导航到文件夹:CD桌面,并调用这个块.所有文件都位于桌面/cheese1文件夹中:
for file in cheese1/*.xml; do
xmlstarlet edit -L --delete "//bndbox/xmax" --insert "//bndbox/ymin" --to "//bndbox/xmin" \
--insert "//bndbox/xmax" --to "//bndbox/ymax" \
"$file"
done
什么都没有发生,所以不确定是语法错误,还是逻辑错误,还是两者兼而有之.