-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmatlab2opencv.m
41 lines (33 loc) · 945 Bytes
/
matlab2opencv.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
function matlab2opencv( variable, varname, fileName, flag)
[rows cols] = size(variable);
% Beware of Matlab's linear indexing
variable = variable';
% Write mode as default
if ( ~exist('flag','var') )
flag = 'w';
end
if ( ~exist(fileName,'file') || flag == 'w' )
% New file or write mode specified
file = fopen( fileName, 'w');
fprintf( file, '%%YAML:1.0\n');
else
% Append mode
file = fopen( fileName, 'a');
end
% Write variable header
fprintf( file, ' %s: !!opencv-matrix\n', varname);
fprintf( file, ' rows: %d\n', rows);
fprintf( file, ' cols: %d\n', cols);
fprintf( file, ' dt: f\n');
fprintf( file, ' data: [ ');
% Write variable data
for i=1:rows*cols
fprintf( file, '%d', variable(i));
if (i == rows*cols), break, end
fprintf( file, ', ');
% if mod(i+1,cols) == 0
% fprintf( file, '\n ');
% end
end
fprintf( file, ']\n');
fclose(file);