The run mat to XML in windows, the model (MAT) trained by VOC-release4.01 DPM to model (XML) that can be loaded by opencv latentsvm)

Source: Internet
Author: User

The converted single component person model has good detection results, while the three-component person model in voc2007 2009 has very poor detection results. It may be because opencv does not support mixed model loading. (I only care about the person detection, so I only tested the effect of model conversion of person)

% Jelly 2013-08-12

% Convert *. Mat format model in the source example in % discriminatively trained deformable part models "voc-release4.01" % to opencv's latentsvm detect input format *. xml

Function mat2xmlmodel_401 (matmodel, xmlfile)

Matmodel = 'inria/inriaperson_final '; xmlfile = 'inria/inriaperson_final.xml ';

Load (matmodel); FID = fopen (xmlfile, 'w ');

Fprintf (FID, '<model> \ n'); % get the number of components ncom = length (model. rules {model. start}); fprintf (FID, '\ t <! -- Number of components --> \ n'); fprintf (FID, '\ t <numcomponents> % d </numcomponents> \ n', ncom); % obtains the feature dimension, the fixed value is 31 dimensions. Nfeature = 31; fprintf (FID, '\ t <! -- Number of features --> \ n'); fprintf (FID, '\ t <p> % d </P> \ n', nfeature); % score Threshold = model. threshfprintf (FID, '\ t <! -- Score threshold --> \ n'); fprintf (FID, '\ t <scorethreshold> %. 16f </scorethreshold> \ n', model. thresh); layer = 1; % obtain its root filter, part filter, and deformation filterfor ICOM = 1: ncom fprintf (FID, '\ t <component> \ n'); fprintf (FID,' \ t <! -- Root filter description --> \ n'); fprintf (FID, '\ t <rootfilter> \ n'); % attention: X, Y swap RHS = model. rules {model. start} (ICOM ). RHS; % assume the root filter is first on the RHS of the Start rules if model. symbols (RHS (1 )). type = 'T' % handle case where there's no deformation model for the root Root = model. symbols (RHS (1 )). filter; else % handle case where there is a deformation model for the roo T root = model. symbols (model. rules {RHS (1)} (Layer ). RHS ). filter; end filternum = root; sizex = model. filters (filternum ). size (2); sizey = model. filters (filternum ). size (1); fprintf (FID, '\ t <! -- Dimensions --> \ n'); fprintf (FID, '\ t <sizex> % d </sizex> \ n', sizex); fprintf (FID, '\ t <sizey> % d </sizey> \ n', sizey); fprintf (FID,' \ t <! -- Weights (binary representation) --> \ n'); fprintf (FID, '\ t <weights>'); For Iy = 1: sizey for IX = 1: sizex % original mat has 32 which is larger than nfeature = 31 by 1 fwrite (FID, model. filters (filternum ). W (Iy, IX, 1: nfeature), 'double'); % need verify end fprintf (FID, '\ t </weights> \ n'); fprintf (FID,' \ t <! -- Linear term in Score Function --> \ n'); fprintf (FID, '\ t <linearterm> %. 16f </linearterm> \ n ',... % need verify model. rules {model. start} (ICOM ). offset. w); fprintf (FID, '\ t </rootfilter> \ n'); fprintf (FID,' \ t <! -- Part filters description --> \ n'); fprintf (FID, '\ t <partfilters> \ n'); % obtains the number of part filters in each component, and obtain the parameter npart = length (model. rules {model. start} (ICOM ). RHS)-1; fprintf (FID, '\ t <numpartfilters> % d </numpartfilters> \ n', npart ); % get the relevant parameters of each part [dx, Dy, DS] and penalty [dx dy dxx dyy] For ipart = 2: npart + 1 fprintf (FID, '\ t <! -- Part filter? Description --> \ n'); fprintf (FID, '\ t <partfilter> \ n'); irule = model. rules {model. start} (ICOM ). RHS (ipart); filternum = model. symbols (model. rules {irule }. RHS ). filter; sizex = model. filters (filternum ). size (2); sizey = model. filters (filternum ). size (1); fprintf (FID, '\ t <sizex> % d </sizex> \ n', sizex); fprintf (FID, '\ t <sizey> % d </sizey> \ n', sizey); fprintf (FID,' \ t <! -- Weights (binary representation) --> \ n'); fprintf (FID, '\ t <weights>'); For Iy = 1: sizey for IX = 1: sizex % original mat has 32 which is larger than nfeature = 31 by 1 fwrite (FID, model. filters (filternum ). W (Iy, IX, 1: nfeature), 'double'); % need verify end fprintf (FID, '\ t </weights> \ n'); fprintf (FID,' \ t <! -- Part filter offset --> \ n'); fprintf (FID, '\ t <v> \ n'); fprintf (FID, '\ t <VX> % d </VX> \ n', model. rules {model. start} (ICOM ). anchor {ipart} (1) + 1); % [dx, Dy, DS] fprintf (FID, '\ t <Vy> % d </Vy> \ n', model. rules {model. start} (ICOM ). anchor {ipart} (2) + 1); fprintf (FID, '\ t </V> \ n'); fprintf (FID, '\ t <! -- Quadratic penalty function coefficients --> \ n'); fprintf (FID, '\ t <penalty> \ n'); fprintf (FID, '\ t <DX> %. 16f </dx> \ n', model. rules {irule }. def. W (2); fprintf (FID, '\ t <dy> %. 16f </dy> \ n', model. rules {irule }. def. W (4); fprintf (FID, '\ t <dxx> %. 16f </dxx> \ n', model. rules {irule }. def. W (1); fprintf (FID, '\ t <dyy> %. 16f </dyy> \ n', model. rules {irule }. def. W (3); fprintf (FID, '\ t </penalty> \ n'); fprintf (FID, '\ t </partfilter> \ n'); End fprintf (FID,' \ t </partfilters> \ n'); fprintf (FID, '\ t </component> \ n'); endfprintf (FID,' </model> \ n'); fclose (FID );

end

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.