Tuesday, October 16, 2012

Read CVML into MATLAB

CVML (CVML- An XML-based Computer Vision Markup Language), which is commonly used in AI community as the manual label format.  which is   which is commonly used in AI community as the manual label format. Popular CAVIAR and other datasets are using this as an standard. The output files will be .xml file, which might not be easy for MATLAB researchers to use. 

CoreLibrary does have a C++ based dataset to read from and write to CVML based .xml files, however, they are still not .mat file as MATLAB users expected. 
In this blog, we will utilize an easy and straight forward way to extract the objects bounding boxes.  All the knowledge are based on blog: http://www.gnebehay.com/?p=5




The first step, please use emacs or any editor you would prefer to copy and paste the following code in a file called: 'cvml_csv.xslt'.


<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:variable name="sep" select="' '" />
<xsl:template match="/">
      <xsl:for-each select="dataset/frame">
    <xsl:for-each select="objectlist/object">
        <xsl:value-of select="../../@number"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="@id"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="box/@xc"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="box/@yc"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="box/@w"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="box/@h"/>
        <xsl:value-of select="'&#xA;'"/>
    </xsl:for-each>
      </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

2nd step: Let us assume, you CVML .xml file is called: fwbs1gt.xml. Then type in the following command in your terminal

                 xsltproc cvml_csv.xslt fwbs1gt.xml > fwbs1gt.csv

3rd step: read csv file into matlab, by typing the following command in MATLAB command windows.

                 A = dlmread('fwbs1gt.csv');

4th step: For A, there will be n rows 6 columns. The 1st columns is the frame number. 2nd is the object id within the frame. 3rd to 6th column is the bounding box information. 

Again, this blog is mainly for a record to myself. If you have confusion, please go to blog:  http://www.gnebehay.com/?p=5. The author has done a great work to introduce this whole topic. 
All credit goes to that author. 

No comments:

Post a Comment

prettify