[790] | 1 | function [A,FileInfo,timestamps,errormsg]=read_rdvision(filename,frame_idx)
|
---|
[796] | 2 | % BINREAD_RDV Permet de lire les fichiers bin gᅵnᅵrᅵs par Hiris ᅵ partir du
|
---|
| 3 | % fichier seq associᅵ.
|
---|
[785] | 4 | % [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
|
---|
[796] | 5 | % l'image d'indice FRAME_IDX de la sï¿œquence FILENAME.
|
---|
[785] | 6 | %
|
---|
[796] | 7 | % Entrï¿œes
|
---|
[785] | 8 | % -------
|
---|
[796] | 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
|
---|
[785] | 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
|
---|
[796] | 14 | % d'images et tous les timestamps sont renvoyᅵs. Les indices commencent ᅵ
|
---|
| 15 | % 1 et se termines ᅵ NB_FRAMES.
|
---|
[785] | 16 | %
|
---|
| 17 | % Sorties
|
---|
| 18 | % -------
|
---|
| 19 | % IMGS : Images de sortie.
|
---|
| 20 | % TIMESTAMPS : Timestaps des images lues.
|
---|
[796] | 21 | % NB_FRAMES : Nombres d'images dans la sï¿œquence.
|
---|
[785] | 22 |
|
---|
[790] | 23 | errormsg='';
|
---|
[785] | 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=[];
|
---|
[790] | 29 | [PathDir,RootFile,Ext]=fileparts(filename);
|
---|
| 30 | RootPath=fileparts(PathDir);
|
---|
| 31 | switch Ext
|
---|
| 32 | case '.seq'
|
---|
| 33 | filename_seq=filename;
|
---|
| 34 | filename_sqb=fullfile(PathDir,[RootFile '.sqb']);
|
---|
| 35 | case '.sqb'
|
---|
| 36 | filename_seq=fullfile(PathDir,[RootFile '.seq']);
|
---|
| 37 | filename_sqb=filename;
|
---|
| 38 | otherwise
|
---|
| 39 | errormsg='input file extension must be .seq or .sqb';
|
---|
| 40 | end
|
---|
| 41 | if ~exist(filename_seq,'file')
|
---|
| 42 | errormsg=[filename_seq ' does not exist'];
|
---|
| 43 | return
|
---|
| 44 | end
|
---|
| 45 | s=ini2struct(filename_seq);
|
---|
[785] | 46 | FileInfo=s.sequenceSettings;
|
---|
[790] | 47 | if isfield(s.sequenceSettings,'numberoffiles')
|
---|
| 48 | FileInfo.NumberOfFrames=str2double(s.sequenceSettings.numberoffiles);
|
---|
| 49 | FileInfo.FrameRate=str2double(s.sequenceSettings.framepersecond);
|
---|
| 50 | FileInfo.ColorType='grayscale';
|
---|
| 51 | else
|
---|
| 52 | FileInfo.FileType='';
|
---|
| 53 | return
|
---|
| 54 | end
|
---|
| 55 | FileInfo.FileType='rdvision'; % file used to store info from image acquisition systems of rdvision
|
---|
| 56 | nbfield=numel(fieldnames(FileInfo));
|
---|
| 57 | FileInfo=orderfields(FileInfo,[nbfield nbfield-1 nbfield-2 (1:nbfield-3)]); %reorder the fields of fileInfo for clarity
|
---|
[785] | 58 |
|
---|
| 59 | % read the images the input frame_idxis not empty
|
---|
| 60 | if ~isempty(frame_idx)
|
---|
| 61 | w=str2double(FileInfo.width);
|
---|
| 62 | h=str2double(FileInfo.height);
|
---|
| 63 | bpp=str2double(FileInfo.bytesperpixel);
|
---|
| 64 | bin_file=FileInfo.binfile;
|
---|
[796] | 65 | % bin_file='Dalsa1_';
|
---|
[785] | 66 | nb_frames=str2double(FileInfo.numberoffiles);
|
---|
[797] | 67 | %%%% reading the .sqb file
|
---|
[790] | 68 | m = memmapfile(filename_sqb,'Format', { 'uint32' [1 1] 'offset'; ...
|
---|
[785] | 69 | 'uint32' [1 1] 'garbage1';...
|
---|
| 70 | 'double' [1 1] 'timestamp';...
|
---|
| 71 | 'uint32' [1 1] 'file_idx';...
|
---|
[797] | 72 | 'uint32' [1 1] 'garbage2' },'Repeat',nb_frames);
|
---|
[785] | 73 | data=m.Data;
|
---|
[797] | 74 | %%%%%%%BRICOLAGE in case of unreadable .sqb file
|
---|
| 75 | % ind=[60 63:152];%indices of bin files
|
---|
| 76 | % lengthimage=w*h*bpp;% lengthof an image record on the binary file
|
---|
[796] | 77 | % for ii=1:32*numel(ind)
|
---|
[797] | 78 | % data(ii).offset=mod(ii-1,32)*2*lengthimage+lengthimage;%Dalsa_2
|
---|
| 79 | % %data(ii).offset=mod(ii-1,32)*2*lengthimage;%Dalsa_1
|
---|
[796] | 80 | % data(ii).file_idx=ind(ceil(ii/32));
|
---|
[797] | 81 | % data(ii).timestamp=0.2*(ii-1);
|
---|
[796] | 82 | % end
|
---|
[797] | 83 | %%%%%%%
|
---|
[785] | 84 | timestamps=[data.timestamp];
|
---|
[796] | 85 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
[785] | 86 | if frame_idx==-1
|
---|
| 87 | frame_idx=1:nb_frames;
|
---|
| 88 | end
|
---|
| 89 |
|
---|
| 90 | classname=sprintf('uint%d',bpp*8);
|
---|
| 91 | A=zeros([h,w,length(frame_idx)],classname);
|
---|
| 92 |
|
---|
| 93 | classname=['*' classname];
|
---|
| 94 |
|
---|
| 95 | for i=1:length(frame_idx)
|
---|
| 96 | ii=frame_idx(i);
|
---|
[794] | 97 | if ~isempty(FileInfo.binrepertoire)
|
---|
| 98 | binrepertoire=FileInfo.binrepertoire;
|
---|
| 99 | else %used when binrepertoire empty, strange feature of rdvision
|
---|
| 100 | binrepertoire=regexprep(FileInfo.bindirectory,'\\$','');%tranform Windows notation to Linux
|
---|
| 101 | binrepertoire=regexprep(binrepertoire,'\','/');
|
---|
| 102 | [tild,binrepertoire,DirExt]=fileparts(binrepertoire);
|
---|
| 103 | binrepertoire=[binrepertoire DirExt];
|
---|
| 104 | end
|
---|
[796] | 105 | % binrepertoire='2014-07-04T10.48.46'% case FJORD5a %%%%%%%%%%%%%%%%%%%%%%%%%
|
---|
[794] | 106 | binfile=fullfile(RootPath,binrepertoire,sprintf('%s%.5d.bin',bin_file,data(ii).file_idx));
|
---|
[785] | 107 | fid=fopen(binfile,'rb');
|
---|
| 108 | fseek(fid,data(ii).offset,-1);
|
---|
| 109 | A(:,:,i)=reshape(fread(fid,w*h,classname),w,h)';
|
---|
| 110 | fclose(fid);
|
---|
| 111 | end
|
---|
| 112 |
|
---|
| 113 | if ~isempty(frame_idx)
|
---|
| 114 | timestamps=timestamps(frame_idx);
|
---|
| 115 | end
|
---|
| 116 | end
|
---|
| 117 |
|
---|
| 118 | function Result = ini2struct(FileName)
|
---|
| 119 | %==========================================================================
|
---|
| 120 | % Author: Andriy Nych ( nych.andriy@gmail.com )
|
---|
| 121 | % Version: 733341.4155741782200
|
---|
| 122 | %==========================================================================
|
---|
| 123 | %
|
---|
| 124 | % INI = ini2struct(FileName)
|
---|
| 125 | %
|
---|
| 126 | % This function parses INI file FileName and returns it as a structure with
|
---|
| 127 | % section names and keys as fields.
|
---|
| 128 | %
|
---|
| 129 | % Sections from INI file are returned as fields of INI structure.
|
---|
| 130 | % Each fiels (section of INI file) in turn is structure.
|
---|
| 131 | % It's fields are variables from the corresponding section of the INI file.
|
---|
| 132 | %
|
---|
| 133 | % If INI file contains "oprhan" variables at the beginning, they will be
|
---|
| 134 | % added as fields to INI structure.
|
---|
| 135 | %
|
---|
| 136 | % Lines starting with ';' and '#' are ignored (comments).
|
---|
| 137 | %
|
---|
| 138 | % See example below for more information.
|
---|
| 139 | %
|
---|
| 140 | % Usually, INI files allow to put spaces and numbers in section names
|
---|
| 141 | % without restrictions as long as section name is between '[' and ']'.
|
---|
| 142 | % It makes people crazy to convert them to valid Matlab variables.
|
---|
| 143 | % For this purpose Matlab provides GENVARNAME function, which does
|
---|
| 144 | % "Construct a valid MATLAB variable name from a given candidate".
|
---|
| 145 | % See 'help genvarname' for more information.
|
---|
| 146 | %
|
---|
| 147 | % The INI2STRUCT function uses the GENVARNAME to convert strange INI
|
---|
| 148 | % file string into valid Matlab field names.
|
---|
| 149 | %
|
---|
| 150 | % [ test.ini ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 151 | %
|
---|
| 152 | % SectionlessVar1=Oops
|
---|
| 153 | % SectionlessVar2=I did it again ;o)
|
---|
| 154 | % [Application]
|
---|
| 155 | % Title = Cool program
|
---|
| 156 | % LastDir = c:\Far\Far\Away
|
---|
| 157 | % NumberOFSections = 2
|
---|
| 158 | % [1st section]
|
---|
| 159 | % param1 = val1
|
---|
| 160 | % Param 2 = Val 2
|
---|
| 161 | % [Section #2]
|
---|
| 162 | % param1 = val1
|
---|
| 163 | % Param 2 = Val 2
|
---|
| 164 | %
|
---|
| 165 | % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 166 | %
|
---|
| 167 | % The function converts this INI file it to the following structure:
|
---|
| 168 | %
|
---|
| 169 | % [ MatLab session (R2006b) ]~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 170 | % >> INI = ini2struct('test.ini');
|
---|
| 171 | % >> disp(INI)
|
---|
| 172 | % sectionlessvar1: 'Oops'
|
---|
| 173 | % sectionlessvar2: 'I did it again ;o)'
|
---|
| 174 | % application: [1x1 struct]
|
---|
| 175 | % x1stSection: [1x1 struct]
|
---|
| 176 | % section0x232: [1x1 struct]
|
---|
| 177 | %
|
---|
| 178 | % >> disp(INI.application)
|
---|
| 179 | % title: 'Cool program'
|
---|
| 180 | % lastdir: 'c:\Far\Far\Away'
|
---|
| 181 | % numberofsections: '2'
|
---|
| 182 | %
|
---|
| 183 | % >> disp(INI.x1stSection)
|
---|
| 184 | % param1: 'val1'
|
---|
| 185 | % param2: 'Val 2'
|
---|
| 186 | %
|
---|
| 187 | % >> disp(INI.section0x232)
|
---|
| 188 | % param1: 'val1'
|
---|
| 189 | % param2: 'Val 2'
|
---|
| 190 | %
|
---|
| 191 | % ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
---|
| 192 | %
|
---|
| 193 | % NOTE.
|
---|
| 194 | % WhatToDoWithMyVeryCoolSectionAndVariableNamesInIniFileMyVeryCoolProgramWrites?
|
---|
| 195 | % GENVARNAME also does the following:
|
---|
| 196 | % "Any string that exceeds NAMELENGTHMAX is truncated". (doc genvarname)
|
---|
| 197 | % Period.
|
---|
| 198 | %
|
---|
| 199 | % =========================================================================
|
---|
| 200 | Result = []; % we have to return something
|
---|
| 201 | CurrMainField = ''; % it will be used later
|
---|
| 202 | f = fopen(FileName,'r'); % open file
|
---|
| 203 | while ~feof(f) % and read until it ends
|
---|
| 204 | s = strtrim(fgetl(f)); % Remove any leading/trailing spaces
|
---|
| 205 | if isempty(s)
|
---|
| 206 | continue;
|
---|
| 207 | end;
|
---|
| 208 | if (s(1)==';') % ';' start comment lines
|
---|
| 209 | continue;
|
---|
| 210 | end;
|
---|
| 211 | if (s(1)=='#') % '#' start comment lines
|
---|
| 212 | continue;
|
---|
| 213 | end;
|
---|
| 214 | if ( s(1)=='[' ) && (s(end)==']' )
|
---|
| 215 | % We found section
|
---|
| 216 | CurrMainField = genvarname(lower(s(2:end-1)));
|
---|
| 217 | Result.(CurrMainField) = []; % Create field in Result
|
---|
| 218 | else
|
---|
| 219 | % ??? This is not a section start
|
---|
| 220 | [par,val] = strtok(s, '=');
|
---|
| 221 | val = CleanValue(val);
|
---|
| 222 | if ~isempty(CurrMainField)
|
---|
| 223 | % But we found section before and have to fill it
|
---|
| 224 | Result.(CurrMainField).(lower(genvarname(par))) = val;
|
---|
| 225 | else
|
---|
| 226 | % No sections found before. Orphan value
|
---|
| 227 | Result.(lower(genvarname(par))) = val;
|
---|
| 228 | end
|
---|
| 229 | end
|
---|
| 230 | end
|
---|
| 231 | fclose(f);
|
---|
| 232 | return;
|
---|
| 233 |
|
---|
| 234 | function res = CleanValue(s)
|
---|
| 235 | res = strtrim(s);
|
---|
| 236 | if strcmpi(res(1),'=')
|
---|
| 237 | res(1)=[];
|
---|
| 238 | end
|
---|
| 239 | res = strtrim(res);
|
---|
| 240 | return;
|
---|