[785] | 1 | function [A,FileInfo,timestamps]=read_rdvision(filename,frame_idx)
|
---|
| 2 | % BINREAD_RDV Permet de lire les fichiers bin générés par Hiris à partir du
|
---|
| 3 | % fichier seq associé.
|
---|
| 4 | % [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
|
---|
| 5 | % l'image d'indice FRAME_IDX de la séquence FILENAME.
|
---|
| 6 | %
|
---|
| 7 | % Entrées
|
---|
| 8 | % -------
|
---|
| 9 | % FILENAME : Nom du fichier séquence (.seq).
|
---|
| 10 | % FRAME_IDX : Indice de l'image à lire. Si FRAME_IDX vaut -1 alors la
|
---|
| 11 | % séquence est entièrement lue. Si FRAME_IDX est un tableau d'indices
|
---|
| 12 | % alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
|
---|
| 13 | % est un tableau vide alors aucune image n'est lue mais le nombre
|
---|
| 14 | % d'images et tous les timestamps sont renvoyés. Les indices commencent à
|
---|
| 15 | % 1 et se termines à NB_FRAMES.
|
---|
| 16 | %
|
---|
| 17 | % Sorties
|
---|
| 18 | % -------
|
---|
| 19 | % IMGS : Images de sortie.
|
---|
| 20 | % TIMESTAMPS : Timestaps des images lues.
|
---|
| 21 | % NB_FRAMES : Nombres d'images dans la séquence.
|
---|
| 22 |
|
---|
| 23 |
|
---|
| 24 | if nargin<2% no frame indices specified
|
---|
| 25 | frame_idx=-1;% all the images in the series are read
|
---|
| 26 | end
|
---|
| 27 | A=[];
|
---|
| 28 | timestamps=[];
|
---|
| 29 | s=ini2struct(filename);
|
---|
| 30 | FileInfo=s.sequenceSettings;
|
---|
| 31 |
|
---|
| 32 | % read the images the input frame_idxis not empty
|
---|
| 33 | if ~isempty(frame_idx)
|
---|
| 34 | w=str2double(FileInfo.width);
|
---|
| 35 | h=str2double(FileInfo.height);
|
---|
| 36 | bpp=str2double(FileInfo.bytesperpixel);
|
---|
| 37 | bin_file=FileInfo.binfile;
|
---|
| 38 | nb_frames=str2double(FileInfo.numberoffiles);
|
---|
| 39 |
|
---|
| 40 | [bin_dir,f]=fileparts(filename);
|
---|
| 41 |
|
---|
| 42 | sqb_file=fullfile(bin_dir,[f '.sqb']);
|
---|
| 43 | m = memmapfile(sqb_file,'Format', { 'uint32' [1 1] 'offset'; ...
|
---|
| 44 | 'uint32' [1 1] 'garbage1';...
|
---|
| 45 | 'double' [1 1] 'timestamp';...
|
---|
| 46 | 'uint32' [1 1] 'file_idx';...
|
---|
| 47 | 'uint32' [1 1] 'garbage2' },'Repeat',nb_frames);
|
---|
| 48 |
|
---|
| 49 | data=m.Data;
|
---|
| 50 | timestamps=[data.timestamp];
|
---|
| 51 |
|
---|
| 52 | if frame_idx==-1
|
---|
| 53 | frame_idx=1:nb_frames;
|
---|
| 54 | end
|
---|
| 55 |
|
---|
| 56 | classname=sprintf('uint%d',bpp*8);
|
---|
| 57 | A=zeros([h,w,length(frame_idx)],classname);
|
---|
| 58 |
|
---|
| 59 | classname=['*' classname];
|
---|
| 60 |
|
---|
| 61 | for i=1:length(frame_idx)
|
---|
| 62 | ii=frame_idx(i);
|
---|
| 63 | binfile=fullfile(bin_dir,sprintf('%s%.5d.bin',bin_file,data(ii).file_idx));
|
---|
| 64 | fid=fopen(binfile,'rb');
|
---|
| 65 | fseek(fid,data(ii).offset,-1);
|
---|
| 66 | A(:,:,i)=reshape(fread(fid,w*h,classname),w,h)';
|
---|
| 67 | fclose(fid);
|
---|
| 68 | end
|
---|
| 69 |
|
---|
| 70 | if ~isempty(frame_idx)
|
---|
| 71 | timestamps=timestamps(frame_idx);
|
---|
| 72 | end
|
---|
| 73 | end
|
---|
| 74 |
|
---|
| 75 | function Result = ini2struct(FileName)
|
---|
| 76 | %==========================================================================
|
---|
| 77 | % Author: Andriy Nych ( nych.andriy@gmail.com )
|
---|
| 78 | % Version: 733341.4155741782200
|
---|
| 79 | %==========================================================================
|
---|
| 80 | %
|
---|
| 81 | % INI = ini2struct(FileName)
|
---|
| 82 | %
|
---|
| 83 | % This function parses INI file FileName and returns it as a structure with
|
---|
| 84 | % section names and keys as fields.
|
---|
| 85 | %
|
---|
| 86 | % Sections from INI file are returned as fields of INI structure.
|
---|
| 87 | % Each fiels (section of INI file) in turn is structure.
|
---|
| 88 | % It's fields are variables from the corresponding section of the INI file.
|
---|
| 89 | %
|
---|
| 90 | % If INI file contains "oprhan" variables at the beginning, they will be
|
---|
| 91 | % added as fields to INI structure.
|
---|
| 92 | %
|
---|
| 93 | % Lines starting with ';' and '#' are ignored (comments).
|
---|
| 94 | %
|
---|
| 95 | % See example below for more information.
|
---|
| 96 | %
|
---|
| 97 | % Usually, INI files allow to put spaces and numbers in section names
|
---|
| 98 | % without restrictions as long as section name is between '[' and ']'.
|
---|
| 99 | % It makes people crazy to convert them to valid Matlab variables.
|
---|
| 100 | % For this purpose Matlab provides GENVARNAME function, which does
|
---|
| 101 | % "Construct a valid MATLAB variable name from a given candidate".
|
---|
| 102 | % See 'help genvarname' for more information.
|
---|
| 103 | %
|
---|
| 104 | % The INI2STRUCT function uses the GENVARNAME to convert strange INI
|
---|
| 105 | % file string into valid Matlab field names.
|
---|
| 106 | %
|
---|
| 107 | % [ test.ini ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 108 | %
|
---|
| 109 | % SectionlessVar1=Oops
|
---|
| 110 | % SectionlessVar2=I did it again ;o)
|
---|
| 111 | % [Application]
|
---|
| 112 | % Title = Cool program
|
---|
| 113 | % LastDir = c:\Far\Far\Away
|
---|
| 114 | % NumberOFSections = 2
|
---|
| 115 | % [1st section]
|
---|
| 116 | % param1 = val1
|
---|
| 117 | % Param 2 = Val 2
|
---|
| 118 | % [Section #2]
|
---|
| 119 | % param1 = val1
|
---|
| 120 | % Param 2 = Val 2
|
---|
| 121 | %
|
---|
| 122 | % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 123 | %
|
---|
| 124 | % The function converts this INI file it to the following structure:
|
---|
| 125 | %
|
---|
| 126 | % [ MatLab session (R2006b) ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 127 | % >> INI = ini2struct('test.ini');
|
---|
| 128 | % >> disp(INI)
|
---|
| 129 | % sectionlessvar1: 'Oops'
|
---|
| 130 | % sectionlessvar2: 'I did it again ;o)'
|
---|
| 131 | % application: [1x1 struct]
|
---|
| 132 | % x1stSection: [1x1 struct]
|
---|
| 133 | % section0x232: [1x1 struct]
|
---|
| 134 | %
|
---|
| 135 | % >> disp(INI.application)
|
---|
| 136 | % title: 'Cool program'
|
---|
| 137 | % lastdir: 'c:\Far\Far\Away'
|
---|
| 138 | % numberofsections: '2'
|
---|
| 139 | %
|
---|
| 140 | % >> disp(INI.x1stSection)
|
---|
| 141 | % param1: 'val1'
|
---|
| 142 | % param2: 'Val 2'
|
---|
| 143 | %
|
---|
| 144 | % >> disp(INI.section0x232)
|
---|
| 145 | % param1: 'val1'
|
---|
| 146 | % param2: 'Val 2'
|
---|
| 147 | %
|
---|
| 148 | % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 149 | %
|
---|
| 150 | % NOTE.
|
---|
| 151 | % WhatToDoWithMyVeryCoolSectionAndVariableNamesInIniFileMyVeryCoolProgramWrites?
|
---|
| 152 | % GENVARNAME also does the following:
|
---|
| 153 | % "Any string that exceeds NAMELENGTHMAX is truncated". (doc genvarname)
|
---|
| 154 | % Period.
|
---|
| 155 | %
|
---|
| 156 | % =========================================================================
|
---|
| 157 | Result = []; % we have to return something
|
---|
| 158 | CurrMainField = ''; % it will be used later
|
---|
| 159 | f = fopen(FileName,'r'); % open file
|
---|
| 160 | while ~feof(f) % and read until it ends
|
---|
| 161 | s = strtrim(fgetl(f)); % Remove any leading/trailing spaces
|
---|
| 162 | if isempty(s)
|
---|
| 163 | continue;
|
---|
| 164 | end;
|
---|
| 165 | if (s(1)==';') % ';' start comment lines
|
---|
| 166 | continue;
|
---|
| 167 | end;
|
---|
| 168 | if (s(1)=='#') % '#' start comment lines
|
---|
| 169 | continue;
|
---|
| 170 | end;
|
---|
| 171 | if ( s(1)=='[' ) && (s(end)==']' )
|
---|
| 172 | % We found section
|
---|
| 173 | CurrMainField = genvarname(lower(s(2:end-1)));
|
---|
| 174 | Result.(CurrMainField) = []; % Create field in Result
|
---|
| 175 | else
|
---|
| 176 | % ??? This is not a section start
|
---|
| 177 | [par,val] = strtok(s, '=');
|
---|
| 178 | val = CleanValue(val);
|
---|
| 179 | if ~isempty(CurrMainField)
|
---|
| 180 | % But we found section before and have to fill it
|
---|
| 181 | Result.(CurrMainField).(lower(genvarname(par))) = val;
|
---|
| 182 | else
|
---|
| 183 | % No sections found before. Orphan value
|
---|
| 184 | Result.(lower(genvarname(par))) = val;
|
---|
| 185 | end
|
---|
| 186 | end
|
---|
| 187 | end
|
---|
| 188 | fclose(f);
|
---|
| 189 | return;
|
---|
| 190 |
|
---|
| 191 | function res = CleanValue(s)
|
---|
| 192 | res = strtrim(s);
|
---|
| 193 | if strcmpi(res(1),'=')
|
---|
| 194 | res(1)=[];
|
---|
| 195 | end
|
---|
| 196 | res = strtrim(res);
|
---|
| 197 | return;
|
---|