-
Notifications
You must be signed in to change notification settings - Fork 5
/
installHelpersOnWindows.m
182 lines (140 loc) · 5.17 KB
/
installHelpersOnWindows.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
function installHelpersOnWindows(opencvflag,opencvinstallpath,flycaptureflag,flycapturelibpath)
% for installing and compiling the c-functions on windows systems.
% Expects working openCV and mexopencv installation. Please
% consult readme.md for installation instructions. Does not compile the
% flyCapture SDK.
cd src
if nargin<1
opencvflag = true;
end
if nargin<2 || ~exist(opencvinstallpath)
opencvinstallpath = '';
end
if nargin<3
flycaptureflag = true;
end
if nargin<4 || ~exist(flycapturelibpath)
flycapturelibpath = '';
end
% check for mexopencv
if opencvflag
try
evalc('cv.getBuildInformation');
catch
error('mexopencv not in path')
end
if isempty(opencvinstallpath)
f = regexp(cv.getBuildInformation,'Install path:\s*(?<path>[^\s]+\>)','names');
if isempty(f)
error('Cannot determine opencvinstallpath. Please specify');
else
opencvinstallpath = f(1).path;
end
end
[a] = fileparts(which('cv.getBuildInformation'));
mexopencvincludepath = [a '\..\include'];
mexopencvlibpath = [a '\..\lib'];
% find library
if strfind(computer('arch'),'64')
opencvlibpath = [opencvinstallpath '\x64'];
else
opencvlibpath = [opencvinstallpath '\x86'];
end
% next compiler name
d = dir(opencvlibpath);
idx = [];
for i = 1:length(d)
if d(i).isdir && d(i).name(1)~= '.'
idx = [idx i];
end
end
if length(idx)==1
opencvlibpath = [opencvlibpath '\' d(idx).name '\lib'];
else
error('Cannot establish opencv libpath');
end
dlibs = dir([opencvlibpath '\opencv*.lib']);
fprintf('Using OpenCV Libs installed at "%s"\n',opencvlibpath);
fprintf('Using MexOpenCV Libs installed at "%s"\n',mexopencvlibpath);
% check for FlyCapture
if flycaptureflag
if isempty(flycapturelibpath)
% assume standard location
flycapturelibpath = 'C:\Program Files\Point Grey Research\FlyCapture2\lib64';
end
if ~exist([flycapturelibpath,filesep,'FlyCapture2.lib'])
fprintf('**Please provide path to "FlyCapture2.lib". Compiling without PtGray camera support...\n');
flycaptureflag = false;
else
fprintf('Using Flycapture libs in "%s"\n',flycapturelibpath);
end
end
opencvincludepath = [opencvinstallpath '\include'];
% compile into video capture path
mexargs = {};
mexargs{end+1} = '-largeArrayDims';
mexargs{end+1} = '-cxx';
mexargs{end+1} = 'CXXFLAGS=''-std=c++11 -lstdc++ -fPIC''';
mexargs{end+1} = ['-I"' mexopencvincludepath,'"',];
mexargs{end+1} = ['-I"' opencvincludepath,'"'];
mexargs{end+1} = ['-L"', opencvlibpath,'"'];
if flycaptureflag
mexargs{end+1} = ['-L',flycapturelibpath];
mexargs{end+1} = '-lFlyCapture2';
mexargs{end+1} = ['-I"',flycapturelibpath, '\..\include"'];
mexargs{end+1} = '-DFLYCAPTURE';
end
for i = 1:length(dlibs)
[~,b,~] = fileparts(dlibs(i).name);
mexargs{end+1} = ['-l' b];
end
mexargs{end+1} = [mexopencvlibpath '\MxArray.obj'];
% videoCapture
mex(mexargs{:}, 'xyVideoCapture_.cpp',...
'-outdir', '..\+xy\+core\@VideoCapture\private');
% VideoSaverObj
mex('-c',mexargs{:},'SaveVideoClassBase.cpp',...
'-outdir','..\+xy\+core\@VideoHandlerMex\private');
mexargs{end+1} = '..\+xy\+core\@VideoHandlerMex\private\SaveVideoClassBase.obj';
if flycaptureflag
% VideoSaverObj
mex('-c',mexargs{:},'SaveVideoClass.cpp',...
'-outdir','..\+xy\+core\@VideoHandlerMex\private');
mexargs{end+1} = '..\+xy\+core\@VideoHandlerMex\private\SaveVideoClass.obj';
end
% VideoHandler
mex('-c',mexargs{:}, 'VideoHandler.cpp',...
'-outdir', '..\+xy\+core\@VideoHandlerMex\private');
% videoReader
mexargs{end+1} = '..\+xy\+core\@VideoHandlerMex\private\VideoHandler.obj';
mex(mexargs{:}, 'xyVideoHandler_.cpp',...
'-outdir', '..\+xy\+core\@VideoHandlerMex\private');
%if flycaptureflag
% copyfile([flycapturelibpath '\FlyCapture2.lib'],'..\+xy\+core\@VideoHandlerMex\private\FlyCapture2.lib')
%end
else
error('Please make sure that mexopencv toolbox is installed and in the path')
end
if ~ispc()
error('This file is only intended for Windows. Use ''make'' for other systems')
end
fnames = {};
targets = {};
HELPER = '..\+xy\+helper\';
fnames{end+1} = 'backtrace_.c';
targets{end+1} = '..\+xy\+core\@DAGraph\private\';
fnames{end+1} = 'getCurrentTracks_.c';
targets{end+1} = '..\+xy\@Tracker\private\';
fnames{end+1} = 'pdist2CenterLine.c';
targets{end+1} = HELPER;
fnames{end+1} = 'pdist2Euclidean.c';
targets{end+1} = HELPER;
fnames{end+1} = 'strucarr2strucmat.c';
targets{end+1} = HELPER;
for i = 1:length(fnames)
mex('-largeArrayDims',fnames{i},'-outdir',targets{i});
end
% compile CXX
mex -largeArrayDims -cxx CXXFLAGS='-std=c++11 -lstdc++' assignDetectionsToTracks.cpp -outdir ..\+xy\+helper\
cd ..
fprintf('\nFINISHED!\nRun >> xy.Tracker.runSimpleTest() to test the tracking system.\n\n')