source: trunk/src/binread_rdv.m @ 965

Last change on this file since 965 was 924, checked in by g7moreau, 8 years ago
  • Update Copyright Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
File size: 3.0 KB
Line 
1%=======================================================================
2% Copyright 2008-2016, LEGI UMR 5519 / CNRS UGA G-INP, Grenoble, France
3%   http://www.legi.grenoble-inp.fr
4%   Joel.Sommeria - Joel.Sommeria (A) legi.cnrs.fr
5%
6%     This file is part of the toolbox UVMAT.
7%
8%     UVMAT is free software; you can redistribute it and/or modify
9%     it under the terms of the GNU General Public License as published
10%     by the Free Software Foundation; either version 2 of the license,
11%     or (at your option) any later version.
12%
13%     UVMAT is distributed in the hope that it will be useful,
14%     but WITHOUT ANY WARRANTY; without even the implied warranty of
15%     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16%     GNU General Public License (see LICENSE.txt) for more details.
17%=======================================================================
18
19function [imgs,timestamps,nb_frames]=binread_rdv(filename,frame_idx)
20% BINREAD_RDV Permet de lire les fichiers bin générés par Hiris à partir du
21% fichier seq associé.
22%   [IMGS,TIMESTAMPS,NB_FRAMES] = BINREAD_RDV(FILENAME,FRAME_IDX) lit
23%   l'image d'indice FRAME_IDX de la séquence FILENAME.
24%
25%   Entrées
26%   -------
27%   FILENAME  : Nom du fichier séquence (.seq).
28%   FRAME_IDX : Indice de l'image à lire. Si FRAME_IDX vaut -1 alors la
29%   séquence est entièrement lue. Si FRAME_IDX est un tableau d'indices
30%   alors toutes les images d'incides correspondant sont lues. Si FRAME_IDX
31%   est un tableau vide alors aucune image n'est lue mais le nombre
32%   d'images et tous les timestamps sont renvoyés. Les indices commencent à
33%   1 et se termines à NB_FRAMES.
34%
35%   Sorties
36%   -------
37%   IMGS        : Images de sortie.
38%   TIMESTAMPS  : Timestaps des images lues.
39%   NB_FRAMES   : Nombres d'images dans la séquence.
40
41
42
43if nargin<2
44   frame_idx=-1;
45end
46
47s=ini2struct(filename);
48
49w=str2double(s.sequenceSettings.width);
50h=str2double(s.sequenceSettings.height);
51bpp=str2double(s.sequenceSettings.bytesperpixel);
52bin_file=s.sequenceSettings.binfile;
53nb_frames=str2double(s.sequenceSettings.numberoffiles);
54
55[p,f]=fileparts(filename);
56
57%bin_dir=s.sequenceSettings.bindirectory;
58%if isempty(bin_dir)
59   bin_dir=p;
60%end
61
62sqb_file=fullfile(p,[f '.sqb']);
63m = memmapfile(sqb_file,'Format', { 'uint32' [1 1] 'offset'; ...
64   'uint32' [1 1] 'garbage1';...
65   'double' [1 1] 'timestamp';...
66   'uint32' [1 1] 'file_idx';...
67   'uint32' [1 1] 'garbage2' },'Repeat',nb_frames);
68
69data=m.Data;
70off=[data.offset];
71timestamps=[data.timestamp];
72file_idx=[data.file_idx];
73
74if frame_idx==-1
75   frame_idx=1:nb_frames;
76end
77
78classname=sprintf('uint%d',bpp*8);
79imgs=zeros([h,w,length(frame_idx)],classname);
80
81classname=['*' classname];
82
83for i=1:length(frame_idx)
84   ii=frame_idx(i);
85   f=fullfile(bin_dir,sprintf('%s%.5d.bin',bin_file,file_idx(ii)));
86   fid=fopen(f,'rb');
87   fseek(fid,off(ii),-1);   
88   imgs(:,:,i)=reshape(fread(fid,w*h,classname),w,h)';
89   fclose(fid);
90end
91
92if ~isempty(frame_idx)
93   timestamps=timestamps(frame_idx);
94end
Note: See TracBrowser for help on using the repository browser.