採用matlab2012a, vs2013和2013編譯器:
(1)resize.cc features.cc :
實現round函數 : inline int round(float a){return ((int)(a + 0.5f));}
同時:#define bzero(a, b) memset(a, 0, b)
基本的c++編程錯:
alphainfo *ofs = new alphainfo[len]; // c++不支援變數類型的數組大小定義
............
delete []ofs;
ofs = NULL;
(2)fv_cache: sigaction // 注釋fv_cache.cc中所有相關代碼;
fv_compile.m:
% if ispc
% error('This code is not supported on Windows.');
% end // 注釋掉 compile.m中對應語句類似處理
model.h:#define INFINITY INT_MAX
obj_fun.cc:
基本的c++錯:
double *hnrms2 = new double[M.num_components];
..........
delete []hnrms2;
hnrms2 = NULL;
double *pc = new double[M.num_components];
...................
delete []pc;
pc = NULL;
(3) gdetect
bounded_dt.cc, dt.cc:typedef int int32_t;
#define INFINITY INT_MAX
fconvsse.cc, fcon_var_dim_MT.cc:
將gdetect_dp.m中進行如下修改與注釋:
%if size(pyra.feat{level},3) == 32
% Faster SSE version (fconvsse.cc) that can only handle 32-dim features
% r = fconv(pyra.feat{level}, filters, 1, length(filters));
% else
% More general convolution code to handle non-32-dim features
% e.g., the HOG-PCA features used by the star-cascade
r = fconv_var_dim(pyra.feat{level}, filters, 1, length(filters)); // 直接調用fconv_var_dim.mex64
% end
如需用fconvsse.cc,則部分更改如下:
#include "pthread.h"
#pragma comment(lib, "pthreadVC.lib") // 支援windows下的pthread線程庫
....................
//_m_empty(); // 注釋掉,該函數清楚寄存器
float *F = (float *)_aligned_malloc(dims[0]*dims[1]*NUM_FEATURES*sizeof(float), 16); // _aligned_malloc為系統api
(4)star-cascade
cascade.cc :#define INFINITY INT_MAX
cascade_compile.m
% if ispc
% error('This code is not supported on Windows.'); // 注釋掉,判斷平台類型
% end
timer.h:
#include <time.h>
#include <ctime>
#include <windows.h>
// 定義timer結構體
class timer {
struct timeval {
long tv_sec;
long tv_usec;
};
// 定義gettimeofday函數
private:
int gettimeofday(struct timeval *tp, void *tzp) {
time_t clock;
struct tm tm;
SYSTEMTIME wtm;
GetLocalTime(&wtm);
tm.tm_year = wtm.wYear - 1900;
tm.tm_mon = wtm.wMonth - 1;
tm.tm_mday = wtm.wDay;
tm.tm_hour = wtm.wHour;
tm.tm_min = wtm.wMinute;
tm.tm_sec = wtm.wSecond;
tm. tm_isdst = -1;
clock = mktime(&tm);
tp->tv_sec = clock;
tp->tv_usec = wtm.wMilliseconds * 1000;
return (0);
}
(5) eval函數:
try
eval(mexcmd);
catch e
end
(6)utils
procid.m:
i = strfind(d, '\');
(7)compile.m:
% if ispc
% error('This code is not supported on Windows.');
% end
try ///////////////////////////////////////
if nargin < 3
% Build feature vector cache code
fv_compile(opt, verb);
% Build the star-cascade code
cascade_compile(opt, verb);
eval([mexcmd ' features/resize.cc']);
eval([mexcmd ' features/features.cc']);
eval([mexcmd ' gdetect/dt.cc']);
eval([mexcmd ' gdetect/bounded_dt.cc']);
eval([mexcmd ' gdetect/get_detection_trees.cc']);
eval([mexcmd ' gdetect/compute_overlap.cc']);
% Convolution routine
% Use one of the following depending on your setup
% (0) is fastest, (2) is slowest
% 0) multithreaded convolution using SSE
%eval([mexcmd ' gdetect/fconv.cc']);
% 1) multithreaded convolution
%eval([mexcmd ' gdetect/fconv_var_dim_MT.cc -o fconv']);
% 2) basic convolution, very compatible
% eval([mexcmd ' gdetect/fconv_var_dim.cc']);
% Convolution routine that can handle feature dimenions other than 32
% 0) multithreaded convolution
%eval([mexcmd ' gdetect/fconv_var_dim_MT.cc']);
% 1) single-threaded convolution
eval([mexcmd ' gdetect/fconv_var_dim.cc']);//////////////////////////////////////////////////////////////////////單線程,非sse版本
else
eval([mexcmd ' ' mex_file]);
end
catch e ////////////////////////////////////////////////////////////////////////////////////////
warning(e.identifier, 'dddd');
end //////////////////////////////////////////////////////////////
(8)demo.m:
%compile;
(9)pascal.m
diary(conf.training.log([cls '-' timestamp])); // 注釋掉,報錯
(10)voc_config.m
BASE_DIR = 'f:/code';
conf = cv(conf, 'pascal.dev_kit', [conf.paths.base_dir '/VOCdevkit/']); // 注意配置這幾句, VOCdevkit路徑
(11)出現系統奔潰問題:
解決方案:resize()函數改成imresize()函數
(12)出現features函數參數資料不匹配的問題
解決方案:重新編譯,運行compile,知道編譯通過
(13)出現找不到標頭檔問題:
解決方案:將#include <sys/time.h>改成#include <time.h>
(14)第五版本的模型與其它版本模型差距較大,如需轉換成VS可識別檔案,建議使用第五版本。
參考連結:地址