-
Notifications
You must be signed in to change notification settings - Fork 8
/
read_side_scan_sonar_dvs.m
117 lines (98 loc) · 3.97 KB
/
read_side_scan_sonar_dvs.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
function [side_scan_data] = read_side_scan_sonar_dvs(file_name)
% Read Side Scan Sonar file generated by DeepVision Sonars
%
% Input-
% file_name: The name of the file that contains the sonar data in *.dvs
% file format
%
% Output-
% side_scan_data structure, with the following contents:
% side_scan_data.src, the source file name (same as input)
% side_scan_data.res: Ping resolution [m] across track
% side_scan_data.nSamples: The number of samples per ping per channel(side)
% side_scan_data.left: Left side sonar data 2D(ping ix, sample ix)
% side_scan_data.right: Right side sonar data 2D(ping ix, sample ix)
% side_scan_data.lat: Latitude in [rad]
% side_scan_data.lon: Longitude in [rad]
% side_scan_data.heading: Sonar heading in [rad]
% side_scan_data.speed: Vehicle speed in [m/s]
%
%
%
% Author: Fredrik Elmgren DeepVision [fredrik@deepvision.se]
% Date: May 11, 2016
%
% Example:
% [x] = read_side_scan_sonar_dvs('WE1.dvs')
%
%
%
%
% Project SWARMs http://www.swarms.eu/
%
% License:
%=====================================================================
% This is part of the UNDROIP toolbox, released under
% the GPL. https://github.com/rawi707/UNDROIP/blob/master/LICENSE
%
% The UNDROIP toolbox is available free and
% unsupported to those who might find it useful. We do not
% take any responsibility whatsoever for any problems that
% you have related to the use of the UNDROIP toolbox.
%
% ======================================================================
%%
tic;
% Constants
SIZE_FILE_HEADER = 4+4+4+4+1+1+2;
SIZE_PING_HEADER = 8+8+4+4;
% File handler
fileID = fopen(file_name,'rb');
if fileID == -1
fprintf('Could not open file %s \n', file_name);
side_scan_data=[]; % just to get rid of the useless warnning
return;
end
side_scan_data.src = file_name;
% file length
fseek(fileID, 0, 'eof');
file_length = ftell(fileID);
fseek(fileID, 0, 'bof');
% version
file_version = fread( fileID, 1, 'int32');
%side_scan_data.file_version = file_version;
if file_version == 1
% Read Header
side_scan_data.res = fread( fileID, 1, 'float' );
fread( fileID, 1, 'float' ); % Skip 1 float(line rate)
side_scan_data.nSamples = fread( fileID, 1, 'int32' );
side_scan_data.leftActive = fread( fileID, 1, 'int8' );
side_scan_data.rightActive = fread( fileID, 1, 'int8' );
%Read 2 padded bytes
fread( fileID, 1, 'int8' );
fread( fileID, 1, 'int8' );
if( side_scan_data.leftActive > 0 ) && ( side_scan_data.rightActive > 0 )
side_scan_data.number_of_ping = round( (file_length-SIZE_FILE_HEADER)/(2*side_scan_data.nSamples+SIZE_PING_HEADER) );
else
side_scan_data.number_of_ping = round( (file_length-SIZE_FILE_HEADER)/(side_scan_data.nSamples+SIZE_PING_HEADER) );
end
% Read Ping data
side_scan_data.left = zeros(side_scan_data.number_of_ping,side_scan_data.nSamples, 'double');
side_scan_data.right = zeros(side_scan_data.number_of_ping,side_scan_data.nSamples, 'double');
side_scan_data.lat = zeros(side_scan_data.number_of_ping,1);
side_scan_data.lon = zeros(side_scan_data.number_of_ping,1);
side_scan_data.heading = zeros(side_scan_data.number_of_ping,1);
side_scan_data.speed = zeros(side_scan_data.number_of_ping,1);
for i=1:side_scan_data.number_of_ping
% Read Ping Header Data
side_scan_data.lat(i) = fread( fileID, 1, 'double' );
side_scan_data.lon(i) = fread( fileID, 1, 'double' );
side_scan_data.speed(i) = fread( fileID, 1, 'float' );
side_scan_data.heading(i) = fread( fileID, 1, 'float32' ); % in rad
% Read Ping Received Signal Strength
side_scan_data.left(i,:) = fread( fileID, side_scan_data.nSamples, 'uint8' );
side_scan_data.right(i,:) = fread( fileID, side_scan_data.nSamples, 'uint8' );
end
end
fclose(fileID);
fprintf('Time needed to read the image is %.2f second(s) \n', toc);