Home > samsung-code > simple_demo4.m

simple_demo4

PURPOSE ^

SIMPLE_DEMO4 detects and shows objects on a single image using a specific classifier (linear/structures SVM).

SYNOPSIS ^

function simple_demo4( image_or_filename, model_type, force_init )

DESCRIPTION ^

 SIMPLE_DEMO4 detects and shows objects on a single image using a specific classifier (linear/structures SVM). 
   The detection results without and with GP-based FTS are shown in two
   figures, respectively.
   Remark: the detection model is automatically loaded and initialized.

 Usage: 

   simple_demo4( image_or_filename, model_type, force_init )

 Input:

   image_or_filename: can be either an image matrix loaded by imread(filename ...)
       or the path of an image file

   model_type: can be a string naming the classifier model type:
       'struct' - (linear) structured SVM, 
                  use the models in ./models_svm_linear
       'linear' - ordinary linear SVM
                  use the models in ./models_svm_struct
   force_init: can be either 0 or 1
       0 - the detection model is only loaded and initialized when it is
           used for the first time
       1 - the detection model is force reloaded (useful when the old model 
           is replaced by a new model, and you do not want to restart MATLAB)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function simple_demo4( image_or_filename, model_type, force_init )
0002 % SIMPLE_DEMO4 detects and shows objects on a single image using a specific classifier (linear/structures SVM).
0003 %   The detection results without and with GP-based FTS are shown in two
0004 %   figures, respectively.
0005 %   Remark: the detection model is automatically loaded and initialized.
0006 %
0007 % Usage:
0008 %
0009 %   simple_demo4( image_or_filename, model_type, force_init )
0010 %
0011 % Input:
0012 %
0013 %   image_or_filename: can be either an image matrix loaded by imread(filename ...)
0014 %       or the path of an image file
0015 %
0016 %   model_type: can be a string naming the classifier model type:
0017 %       'struct' - (linear) structured SVM,
0018 %                  use the models in ./models_svm_linear
0019 %       'linear' - ordinary linear SVM
0020 %                  use the models in ./models_svm_struct
0021 %   force_init: can be either 0 or 1
0022 %       0 - the detection model is only loaded and initialized when it is
0023 %           used for the first time
0024 %       1 - the detection model is force reloaded (useful when the old model
0025 %           is replaced by a new model, and you do not want to restart MATLAB)
0026 %
0027 
0028 if ischar(image_or_filename)
0029     I = imread( image_or_filename );
0030 else
0031     I = image_or_filename;
0032 end
0033 
0034 persistent det_model
0035 if isempty(det_model) || ...
0036         (exist('force_init','var') && force_init) || ...
0037         (exist('model_type','var') && ~strcmp(det_model.type_flags, model_type) )
0038     if ~exist( 'model_type', 'var' ) || isempty(model_type)
0039         model_type = 'struct';
0040     end
0041 
0042     det_model = detInit( [], [], ['models_svm_' model_type] );
0043     det_model.type_flags = model_type;
0044 end
0045 
0046 % detection without GP refinement
0047 fprintf( 'Run for the case WITHOUT GP\n' );
0048 [Bs,Ss] = detSingle( I, det_model, 0 );
0049 figure
0050 detShowBBoxes( I, Bs, Ss, det_model, 0 ); title( 'Finetuned model without GP searching' ); 
0051 set(gcf,'Color','white');
0052 
0053 % detection with GP refinement
0054 fprintf( 'Run for the case WITH GP\n' );
0055 [Bs,Ss] = detSingle( I, det_model, 1 );
0056 figure
0057 detShowBBoxes( I, Bs, Ss, det_model, 0 ); title( 'Finetuned model WITH GP searching' ); 
0058 set(gcf,'Color','white');
0059 
0060 end

Generated on Thu 18-Dec-2014 22:27:44 by m2html © 2005