plateform
stringclasses
1 value
repo_name
stringlengths
13
113
name
stringlengths
3
74
ext
stringclasses
1 value
path
stringlengths
12
229
size
int64
23
843k
source_encoding
stringclasses
9 values
md5
stringlengths
32
32
text
stringlengths
23
843k
github
rising-turtle/slam_matlab-master
convert_o2p.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/convert_o2p.m
7,479
utf_8
70a58785bd955704cf2b32c1bef2d43f
% Conver the odometery to the global pose % t_pose [mm] % o_pose [degree] function [pose_index, e_t_pose, e_o_pose, fpts_h, trajectory_length] = convert_o2p(data_index, dynamic_index, f_index, t_pose, o_pose, feature_points, dense_index, sparse_interval, vro_cpp, isgframe) % Generate the vertex using VRO disp('Generate the vertex using VRO.'); previous_index = -1; if size(f_index,1) > 0 vro_index = 1; if dense_index == 1 for i=1:size(f_index,1) if f_index(i,1) > previous_index %abs(f_index(i,1) - f_index(i,2)) == 1 vro_t_pose(vro_index,:) = t_pose(i,:); vro_o_pose(vro_index,:) = o_pose(i,:); pose_index(vro_index) = f_index(i,1); vro_index = vro_index + 1; previous_index = f_index(i,2)-1; % Debug here !!!! end end else % Sparse pose % Generate the vertex using VRO with the only maximum constraints %sparse_interval = 2; next_index = min(f_index(:,1)); max_index = max(f_index(:,1)); while next_index <= max_index temp_index=find(f_index(:,1) == next_index); if isempty(temp_index) next_index = next_index + 1; else %max_temp_index = max(temp_index); if length(temp_index) > sparse_interval max_temp_index = min(temp_index)+sparse_interval; else max_temp_index = max(temp_index); end vro_t_pose(vro_index,:) = t_pose(max_temp_index,:); vro_o_pose(vro_index,:) = o_pose(max_temp_index,:); pose_index(vro_index) = f_index(max_temp_index,1); vro_index = vro_index + 1; next_index = f_index(max_temp_index,2); end end end else vro_t_pose = t_pose; vro_o_pose = o_pose; end % Generate the vertex from feature points at each pose disp('Generate the vertex from feature points at each pose.'); if ~isempty(feature_points) fpts = cell(size(pose_index,2),1); %current_pose_index = 1; for i = 1:size(feature_points,1) if feature_points(i,3) == 1 current_pose_index = feature_points(i,1); else%pose_index current_pose_index = feature_points(i,2); end cell_index = find(pose_index == current_pose_index); if ~isempty(cell_index) %fpts{cell_index,1} = [fpts{cell_index,1}; current_pose_index feature_points(i,4:6)]; if ~isempty(fpts{cell_index,1}) %[duplication_index, duplication_flag] = check_duplication_imgidx(fpts{cell_index,1}, feature_points(i,4:8)); [duplication_flag] = check_duplication_feature_idx(fpts{cell_index,1}, feature_points(i,4:10)); if duplication_flag == 0 % check duplicated points fpts{cell_index,1} = [fpts{cell_index,1}; current_pose_index feature_points(i,4:10)]; end else fpts{cell_index,1} = [fpts{cell_index,1}; current_pose_index feature_points(i,4:10)]; end end end % Eliminate % fpts = eliminate_duplication(fpts); end % Calculate Homogenous Transformation in 3D disp('Calculate Homogenous Transformation in 3D.'); e_t_pose = zeros(size(vro_t_pose,1), 4); h_global = get_global_transformation(data_index, dynamic_index, isgframe); for i = 1:size(vro_t_pose,1) if vro_cpp == 1 h{i} = [euler_to_rot(vro_o_pose(i,2), vro_o_pose(i,1), vro_o_pose(i,3)) vro_t_pose(i,:)'; 0 0 0 1]; elseif strcmp(isgframe, 'gframe') h{i} = [e2R([vro_o_pose(i,2)*pi/180, vro_o_pose(i,1)*pi/180, vro_o_pose(i,3)*pi/180]) vro_t_pose(i,:)'; 0 0 0 1]; % e2R([rx,ry,rz]) [radian] else h{i} = [euler_to_rot(vro_o_pose(i,1), vro_o_pose(i,2), vro_o_pose(i,3)) vro_t_pose(i,:)'; 0 0 0 1]; % euler_to_rot(ry, rx, rz) [degree] end end disp('Convert poses w.r.t the global frame.'); fpts_h = cell(size(pose_index,2),1); for k = 2:size(e_t_pose,1) for j = k-1 : -1: 1 if j == k-1 temp_pose = h{j}*[ 0 0 0 1]'; if ~isempty(feature_points) unit_data = fpts{k,1}; for f = 1:size(unit_data,1) temp_fpts(:,f) = h{j}*[unit_data(f,2:4) 1]'; end unit_data=[]; end temp_h = h{j}; else temp_pose = h{j}*temp_pose; if ~isempty(feature_points) unit_data = fpts{k,1}; for f = 1:size(unit_data,1) temp_fpts(:,f) = h{j}* temp_fpts(:,f); end unit_data=[]; end temp_h = h{j}*temp_h; end end e_t_pose(k,:) = [h_global * temp_pose]'; if ~isempty(feature_points) unit_data_h=[]; for f = 1:size(fpts{k,1},1) unit_data_h(f,:) = [h_global* temp_fpts(:,f)]'; end %temp_data = fpts{k,1}; fpts_h{k,1}= [fpts{k,1}(:,1) unit_data_h]; end temp_h = h_global * temp_h; if strcmp(isgframe, 'gframe') temp_euler=R2e(temp_h(1:3,1:3)); e_o_pose(k,1) = temp_euler(2); e_o_pose(k,2) = temp_euler(1); e_o_pose(k,3) = temp_euler(3); else [e_o_pose(k,1) e_o_pose(k,2) e_o_pose(k,3)] = rot_to_euler(temp_h(1:3,1:3)); % ry, rx, rz end end e_t_pose(1,:) = [h_global * [0 0 0 1]']'; if ~isempty(feature_points) for f = 1:size(fpts{1,1},1) fpts_h{1,1}(f,:) = [fpts{1,1}(f,1) [h_global* [fpts{1,1}(f,2:4) 1]']']; end for i=1:size(fpts_h,1) fpts_h{i,1} = [fpts_h{i,1} fpts{i,1}(:,5:6)]; end else fpts_h={}; end temp_h = h_global; if strcmp(isgframe, 'gframe') temp_euler=R2e(temp_h(1:3,1:3)); e_o_pose(1,1) = temp_euler(2); e_o_pose(1,2) = temp_euler(1); e_o_pose(1,3) = temp_euler(3); else [e_o_pose(1,1) e_o_pose(1,2) e_o_pose(1,3)] = rot_to_euler(temp_h(1:3,1:3)); end %Compute length of VRO trajectory_length = 0; for i=1:size(vro_t_pose,1)-1 trajectory_length = trajectory_length + sqrt(sum((e_t_pose(i,:)-e_t_pose(i+1,:)).^2)); end end function [new_ftps] = eliminate_duplication(fpts) new_fpts = cell(size(fpts)); for i = 1:size(fpts,1) unit_cell = fpts{i,1}; new_unit_cell = []; for j=1:size(unit_cell,1) %[duplication_index, duplication_flag] = check_duplication(new_unit_cell, unit_cell(j,:)); [duplication_flag] = check_duplication_imgidx(new_unit_cell, unit_cell(j,:)); if duplication_flag == 0 new_unit_cell = [new_unit_cell; unit_cell(j,:)]; end end new_ftps{i,1} = new_unit_cell; end end function [duplication_flag] = check_duplication_feature_idx(data_set, data) duplication_flag = 0; %distance_threshold = 41; % [mm]; typical absolute accuracy + 3 * typical repeatibility of SR4000 = 20 + 3 * 7 = 41 imgidx_distance_threshold = 1; % 2 pixel error tolerance for i=1:size(data_set,1) imgidx_distance = sqrt(sum((data_set(i,end-3:end-2)-data(end-3:end-2)).^2)); %if imgidx_distance <= imgidx_distance_threshold duplication_index=find(data_set(:,7) == data(6)); if ~isempty(duplication_index) || imgidx_distance <= imgidx_distance_threshold duplication_flag = 1; %duplication_index = data_set(i,1); break; end end end
github
rising-turtle/slam_matlab-master
convert_pc2ply.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/convert_pc2ply.m
4,343
utf_8
ce019a6666159fe89cb31ddc38cbe20d
% Write 3D point clouds to a ply file % Conver isp to ply for meshlab % % Author : Soonhac Hong ([email protected]) % Date : 4/1/13 function convert_pc2ply(ply_headers, ply_file_name, poses, data_index, dynamic_index, isgframe) data_name_list=get_data_name_list(); %{'pitch', 'pan', 'roll','x2', 'y2', 'c1', 'c2','c3','c4','m','etas','loops2','kinect_tum','sparse_feature','motive',}; feature_ply_file_name=strrep(ply_file_name, '.ply','_feature_total.ply') feature_ct_file_name=strrep(ply_file_name, '.ply','_feature.ct') % Write headers pose_interval = 3; sample_interval = 3; %1; % for object recognition knob2&3 % image_width = 213; %320; %176; % image_height = 160; %240; %144; % for SR4K image_width = 176; % for object recognition knob2&3 image_height = 144; show_image_width = floor(image_width/sample_interval); show_image_height = floor(image_height/sample_interval); % nfeature = size(poses,1)*show_image_width*show_image_height; % element_vertex_n = sprintf('element vertex %d',nfeature); % ply_headers{4} = element_vertex_n; % for i=1:size(ply_headers,2) % fprintf(fd,'%s\n',ply_headers{i}); % end % Write data for i = 1:size(poses,1) % if vro_cpp == 1 % h{i} = [euler_to_rot(vro_o_pose(i,2), vro_o_pose(i,1), vro_o_pose(i,3)) vro_t_pose(i,:)'; 0 0 0 1]; % else if strcmp(isgframe, 'gframe') h{i} = [e2R([poses(i,4), poses(i,5), poses(i,6)]) poses(i,1:3)'; 0 0 0 1]; % e2R([rx,ry,rz]) [radian] else h{i} = [euler_to_rot(poses(i,5)*180/pi, poses(i,4)*180/pi, poses(i,6)*180/pi) poses(i,1:3)'; 0 0 0 1]; % euler_to_rot(ry, rx, rz) [degree] end end distance_threshold_max = 5; %5; %8; %5; distance_threshold_min = 0.1; %0.8; %3; %0.8; %0.8; %0.8; ply_data=[]; ply_data_index = 1; last_pose = size(poses,1) map_ct=[]; for i=1:pose_interval:last_pose i if check_stored_visual_feature(data_name_list{data_index+5}, dynamic_index, i, true, 'intensity') == 0 [img, x, y, z, c, elapsed_pre] = LoadSR_no_bpc(data_name_list{data_index+5}, 'gaussian', 0, dynamic_index, i, 1, 'int'); %[img, x, y, z, c, elapsed_pre] = load_or_datasets(data_name_list{data_index+5}, 'gaussian', 0, dynamic_index, i, 1, 'int'); else [frm, des, elapsed_sift, img, x, y, z, c, elapsed_pre] = load_visual_features(data_name_list{data_index+5}, dynamic_index, i, true, 'intensity'); end %confidence_threshold = floor(max(max(c))/2); %confidence_threshold = 0; % for object_recognition ct_start=tic; for j=1:show_image_width for k=1:show_image_height col_idx = (j-1)*sample_interval + 1; row_idx = (k-1)*sample_interval + 1; %unit_pose = [x(row_idx,col_idx), y(row_idx, col_idx), z(row_idx, col_idx)]; unit_pose = [-x(row_idx,col_idx), z(row_idx, col_idx), y(row_idx, col_idx)]; unit_pose_distance = sqrt(sum(unit_pose.^2)); %if img(row_idx, col_idx) > 50 %if img(row_idx, col_idx) > 50 && unit_pose(3) <= -0.1 %if unit_pose(3) <= -0.1 && img(row_idx, col_idx) < 200 % 50 %if c(row_idx,col_idx) >= confidence_threshold && unit_pose_distance < distance_threshold_max && unit_pose_distance > distance_threshold_min if unit_pose_distance < distance_threshold_max && unit_pose_distance > distance_threshold_min unit_pose_global = h{i}*[unit_pose, 1]'; if img(row_idx, col_idx) > 10 %&& unit_pose_global(3) <= -0.1 unit_color = [img(row_idx, col_idx),img(row_idx, col_idx),img(row_idx, col_idx)]; %fprintf(fd,'%f %f %f %d %d %d\n',unit_pose_global(1:3,1)', unit_color); ply_data(ply_data_index,:) = [unit_pose_global(1:3,1)', double(unit_color)]; ply_data_index = ply_data_index + 1; end end end end map_ct(i,1) = toc(ct_start); end % Write data nply_data = size(ply_data,1) element_vertex_n = sprintf('element vertex %d',nply_data); ply_headers{4} = element_vertex_n; fd = fopen(feature_ply_file_name, 'w'); for i=1:size(ply_headers,2) fprintf(fd,'%s\n',ply_headers{i}); end for i=1:nply_data fprintf(fd,'%f %f %f %d %d %d\n',ply_data(i,:)); end fclose(fd); %save computational time dlmwrite(feature_ct_file_name,map_ct,' '); end
github
rising-turtle/slam_matlab-master
sr4k_p2T.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/sr4k_p2T.m
637
utf_8
1e2524708ba782ef96c7348c96648dab
% Compute transfomation matrix from 6 parameters[x,y,z,rx,ry,rz] % % Author : Soonhac Hong ([email protected]) % Date : 3/15/13 % Note : This funcion is limited for only SR4000 convention. function T = sr4k_p2T(x) Rx = @(a)[1 0 0; 0 cos(a) -sin(a); 0 sin(a) cos(a)]; Ry = @(b)[cos(b) 0 sin(b); 0 1 0; -sin(b) 0 cos(b)]; Rz = @(c)[cos(c) -sin(c) 0; sin(c) cos(c) 0; 0 0 1]; Rot = @(x)Rz(x(3))*Rx(x(1))*Ry(x(2)); % SR4000 project; see euler_to_rot.m T = [Rot(x(4:6)) [x(1), x(2), x(3)]'; 0 0 0 1]; end
github
rising-turtle/slam_matlab-master
compare_ros_sba_gtsam.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/compare_ros_sba_gtsam.m
5,699
utf_8
8c320dc4d91c3dbdae4e07bb24764292
% Compare ROS-SBA and GTSAM % % Author : Soonhac Hong ([email protected]) % Date : 2/11/13 function [graph, initial] = compare_ros_sba_gtsam(file_name) import gtsam.* graphslam_addpath; addpath('D:\soonhac\Project\PNBD\SW\ASEE\slamtoolbox\slamToolbox_11_09_08\FrameTransforms\Rotations'); addpath('D:\soonhac\Project\PNBD\SW\ASEE\slamtoolbox\slamToolbox_11_09_08\DataManagement'); file_name = 'data/ba/ros_sba/sample_bundler_file.out'; %file_name = 'data/ba/ros_sba/exp1_bus_door_straight_150_Replace_pose_feature_1614_101_ros_sba.out'; %file_name = 'results/ros_sba/result.out'; %%load ROS-SBA output file [camera_poses, camera_parameters, landmark_position, landmark_projection] = load_rossba(file_name); show_camera_pose(camera_poses, true, 'no', 'no', 'off', 'k.-' ); hold on; plot3(landmark_position(:,1),landmark_position(:,2),landmark_position(:,3),'m*'); axis equal; %% Generate measured landmark points at each camera from measured image plane points landmark_relative_position=[]; for i=1:size(landmark_projection,1) camera_index = landmark_projection(i,1); f = camera_parameters(camera_index+1,1); unit_z = landmark_position(camera_index+1,3); unit_x = landmark_projection(i,3)*unit_z/f; unit_y = (-1)*landmark_projection(i,4)*unit_z/f; landmark_relative_position = [landmark_relative_position; [camera_index, landmark_projection(i,2), unit_x, unit_y, unit_z]]; end %% Compute relative pose between camera pose nCamera = size(camera_poses,1); camera_relative_pose=[]; for i=1:nCamera first_camera_index = i-1; first_camera_points_idx= find(landmark_relative_position(:,1) == first_camera_index); first_camera_points = landmark_relative_position(first_camera_points_idx,:); for j=first_camera_index+1:nCamera-1 second_camera_index = j; second_camera_points_idx= find(landmark_relative_position(:,1) == second_camera_index); second_camera_points = landmark_relative_position(second_camera_points_idx,:); [first_op_set, second_op_set] = find_correspondent_points(first_camera_points, second_camera_points); % TODO : SVD [rot, trans, sta] = find_transform_matrix(first_op_set', second_op_set'); [euler_xyz] = R2e(rot); %[phi, theta, psi] = rot_to_euler(rot); camera_relative_pose = [camera_relative_pose; [double(first_camera_index),double(second_camera_index), trans', euler_xyz']]; end end %% Generate graph and initial graph = NonlinearFactorGraph; initial = Values; for i=1:size(camera_poses,1) t= gtsam.Point3(camera_poses(i,1), camera_poses(i,2), camera_poses(i,3)); R = gtsam.Rot3.Ypr(camera_poses(i,6), camera_poses(i,5), camera_poses(i,4)); % rz,ry,rx position=gtsam.Pose3(R,t); initial.insert(i-1,position); end pose_noise_model = get_pose_noise_model(); for i=1:size(camera_relative_pose,1) i1 = camera_relative_pose(i,1); i2 = camera_relative_pose(i,2); t = gtsam.Point3(camera_relative_pose(i,3), camera_relative_pose(i,4), camera_relative_pose(i,5)); R = gtsam.Rot3.Ypr(camera_relative_pose(i,8), camera_relative_pose(i,7), camera_relative_pose(i,6)); dpose = gtsam.Pose3(R,t); graph.add(BetweenFactorPose3(i1, i2, dpose, pose_noise_model)); end %% Run pose-optimization using gtsam first = initial.at(0); figure;plot3(first.x(),first.y(),first.z(),'r*'); hold on plot3_gtsam(initial,'g-',false); drawnow; graph.add(NonlinearEqualityPose3(0, first)); optimizer = LevenbergMarquardtOptimizer(graph, initial); result = optimizer.optimizeSafely(); %plot3DTrajectory(result, 'r-', false); axis equal; plot3_gtsam(result,'r-',false); axis equal; view(3); axis equal; % Save initial pose gtsam_isp_file_name = 'data/ba/ros_sba/sample_bundler_file_initial.isp'; save_graph_isp(initial, gtsam_isp_file_name); % Save optimized pose gtsam_opt_file_name = 'results/isam/3d/sample_bundler_file.opt'; save_graph_isp(result, gtsam_opt_file_name); %%Compare ROS-SBA and GTSAM ros_sba_result_file_name = 'results/ros_sba/result.out'; %ros_sba_result_file_name = 'results/ros_sba/exp1_bus_door_straight_150_Replace_pose_feature_1614_101_ros_sba_result.out'; [opt_poses] = load_graph_isp(gtsam_opt_file_name); show_camera_pose(opt_poses, true, 'no', 'no', 'off', 'bo-'); hold on; [ros_sba_result_camera_poses, ros_sba_result_camera_parameters, ros_sba_result_landmark_position, ros_sba_result_landmark_projection] = load_rossba(ros_sba_result_file_name); show_camera_pose(ros_sba_result_camera_poses, false, 'no', 'no', 'off', 'rd-'); %hold on; plot3(ros_sba_result_landmark_position(:,1),ros_sba_result_landmark_position(:,2),ros_sba_result_landmark_position(:,3),'m*'); grid; axis equal; legend('Pose-GTSAM','SBA','Landmark'); hold off; end function [first_op_set, second_op_set] = find_correspondent_points(first_camera_points, second_camera_points) first_op_set = []; second_op_set = []; for i=1:size(first_camera_points,1) first_op_set = [first_op_set; first_camera_points(i,3:5)]; matched_index = find(second_camera_points(:,2) == first_camera_points(i,2)); second_op_set = [second_op_set; second_camera_points(matched_index,3:5)]; end end function [pose_noise_model] = get_pose_noise_model() import gtsam.* %step_factor = abs(i2-i1); step_factor = 1; %abs(i2-i1); translation_covariance = (double(step_factor)^2) * 0.5; %0.014; %[m] orientation_covariance = (double(step_factor)^2) * 1.0*pi/180; %0.6*pi/180; %[degree] -> [radian] pose_noise_model = noiseModel.Diagonal.Sigmas([translation_covariance; translation_covariance; translation_covariance; orientation_covariance; orientation_covariance; orientation_covariance]); % [m][radian] end
github
rising-turtle/slam_matlab-master
load3D_SR4000.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/load3D_SR4000.m
5,538
utf_8
34124a286a9c2a94fcc615f3382dbf75
function [graph,initial] = load3D_SR4000(pose_std_flag, sam_filename, pose_noise_model, successive,N,landmark_noise_model, pose_size, origin) % load3D reads a TORO-style 3D pose graph % cannot read noise model from file yet, uses specified model % if [successive] is tru, constructs initial estimate from odometry import gtsam.* if nargin < 4, successive=false; end fid = fopen(sam_filename); if fid < 0 error(['load2D: Cannot open file ' sam_filename]); end % scan all lines into a cell array columns=textscan(fid,'%s','delimiter','\n'); fclose(fid); % pose_std_fid = fopen(pose_std_file_name); % if fid < 0 % error(['load2D: Cannot open file ' pose_std_file_name]); % end % pose_std_columns=textscan(pose_std_fid,'%s','delimiter','\n'); % fclose(pose_std_fid); lines=columns{1}; % pose_std_lines=pose_std_columns{1}; % loop over lines and add vertices graph = NonlinearFactorGraph; initial = Values; if nargin < 8 origin=gtsam.Pose3; end initial.insert(0,origin); n=size(lines,1); %if nargin<4, N=n;end N=n; first_index_offset = 0; step_threshold = 2; node_count=0; edge_count=0; edges=[]; for i=1:n line_i=lines{i}; % pose_std_line_i=pose_std_lines{i}; if strcmp('VERTEX3',line_i(1:7)) v = textscan(line_i,'%s %d %f %f %f %f %f %f',1); i1=v{2}-first_index_offset; if (~successive && i1<N || successive && i1==0) t = gtsam.Point3(v{3}, v{4}, v{5}); R = gtsam.Rot3.Ypr(v{8}, -v{7}, v{6}); initial.insert(i1, gtsam.Pose3(R,t)); node_count=node_count+1; end elseif strcmp('EDGE3',line_i(1:5)) if pose_std_flag == 1 e = textscan(line_i,'%s %d %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f',1); else e = textscan(line_i,'%s %d %d %f %f %f %f %f %f',1); end if i==1 first_index_offset = e{2}; end i1=e{2}-first_index_offset; i2=e{3}-first_index_offset; % Filtering by steps % if abs(i1-i2) > step_threshold % continue; % end % if i1>=165 % disp('debug'); % end if i1<N && i2<N && i1<pose_size && i2<pose_size if ~successive || abs(i2-i1)==1 t = gtsam.Point3(e{4}, e{5}, e{6}); R = gtsam.Rot3.Ypr(e{9}, e{8}, e{7}); dpose = gtsam.Pose3(R,t); if pose_std_flag == 1 pose_std = [e{10}; e{11}; e{12}; e{13}; e{14}; e{15}]; %pose_std_mean = [e{16}; e{17}; e{18}; e{19}; e{20}; e{21}]; %pose_std_sigma =[e{22}; e{23}; e{24}; e{25}; e{26}; e{27}]; pose_noise_model = noiseModel.Diagonal.Sigmas(pose_std); %pose_noise_model = get_pose_noise_model(i2,i1); else pose_noise_model = get_pose_noise_model(i2,i1); end %if abs(i2-i1) == 1 || check_pose_std(pose_std, pose_std_mean, pose_std_sigma) == 1 graph.add(BetweenFactorPose3(i1, i2, dpose, pose_noise_model)); edge_count = edge_count + 1; edges=[edges; [i1 i2]]; %end if successive if i2>i1 % if i1 == 520 % disp('debug here!'); % end initial.insert(i2,initial.at(i1).compose(dpose)); else initial.insert(i1,initial.at(i2).compose(dpose.inverse)); end end end end % elseif strcmp('POINT3',line_i(1:6)) % e = textscan(line_i,'%s %d %d %f %f %f',1); % i1=e{2}; % i2=e{3}+1; % if i1<N && i2<N % t = gtsam.Point3(e{4}/1000, e{5}/1000, e{6}/1000); % debug : [mm] -> [m] % R = gtsam.Rot3.Ypr(0, 0, 0); % dpose = gtsam.Pose3(R,t); % keys = KeyVector(initial.keys); % if ~successive % %graph.add(BetweenFactorPoint3(i1, i2, t, landmark_noise_model)); % graph.add(BetweenFactorPose3(i1, i2, dpose, pose_noise_model)); % elseif keys.size <= i2 % initial.insert(i2,initial.at(i1).compose(dpose)); % end % end end end %Analysis Edges if ~isempty(edges) min_node=min(min(edges)); max_node=max(max(edges)); edge_matrix=zeros(max_node+1,max_node+1); for i=1:size(edges,1) edge_matrix(edges(i,1)+1,edges(i,2)+1)=1; end figure;imagesc(edge_matrix); end node_count edge_count end function valid_flag = check_pose_std(pose_std, pose_std_mean, pose_std_sigma) valid_flag = 1; for i=1:6 if pose_std(i) > (pose_std_mean(i) + 3*pose_std_sigma(i)) valid_flag = 0; end end end function [pose_noise_model] = get_pose_noise_model(i2,i1) import gtsam.* step_factor = abs(i2-i1); %translation_covariance = (double(step_factor)^2) * 0.014; %0.014; %[m] %orientation_covariance = (double(step_factor)^2) * 0.6*pi/180; %0.6*pi/180; %[degree] -> [radian] translation_covariance = 1; %Identity matrix orientation_covariance = 1; %Identity matrix pose_noise_model = noiseModel.Diagonal.Sigmas([translation_covariance; translation_covariance; translation_covariance; orientation_covariance; orientation_covariance; orientation_covariance]); % [m][radian] end
github
rising-turtle/slam_matlab-master
load_vro.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/load_vro.m
67,147
utf_8
d8a61122f53e3a82ebf7987b0712c7f2
% Conver the results of VRO to the vertex and edges for g2o % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function [f_index t_pose o_pose feature_points, pose_std, icp_ct] = load_vro(data_index, dynamic_data_index, nFrame, feature_flag, vro_cpp, vro_name, pose_std_flag, isgframe, min_matched_points, with_lc_flag) angle_interval = 3; % degree translation_interval = 305; % mm translation_interval_2 = 100; %mm %Compensated by pan/tilt kinematics c1_movement={[-3 6 101],[-12 9 304],[-6 12 501]}; % [yaw pitch x] [degree mm mm] c2_movement={[-6 3 196],[-9 12 386],[-12 6 593]}; % [yaw pitch y] [degree mm mm] c3_movement={[3 12 99],[6 9 198],[9 6 297],[12,3,395]}; % [yaw pitch x] [degree mm mm] c4_movement={[-3 9 290]};% [yaw pitch y] [degree mm mm] % trnaslation_interval_2_correction = 1.5; %mm %nFrame = 540; %240; %240; %60; r2d=180.0/pi; cut_off = 0; nFrame_list= [83 35 86 36 26 16 157 60 161 42 25 175 42 28 500 700 1000 140]; inc_min = 1; %data_index = 10; %1='pitch',2='pan',3='roll', 4='x2' 5='y2', 6='c1', 7='c2', 8 ='c3', 9 ='c4', 10='m' gt_file = 0; % Existence of ground truth; 0 = None, 1 = Exist data_name = get_data_name_list();%{'pitch','pan','roll','x2','y2','c1','c2', 'c3', 'c4','m','etas','loops','kinect_tum','loops2','amir_vro','sparse_feature','swing','swing2','motive','object_recognition'}; filter_list={'gaussian'}; %,'median' image_name = {'intensity'}; %,'fuse'}; %,'depth','fuse_std'}; %image_name = {'depth'}; consensus_name={'ransac'}; %'ransac','ggc_10p'}; %,'gc_30p','gc_40p'}; %,'gc_min'}; fe_selection_name = {'sift','surf','sift/surf'}; fe_selection = 4; % fe_name = {'sift','sift_ransac_stdcrt','sift_ransac_stdctr_stdev'};%,'surf_ransac_limit_14000_11'}; % feature extractor name % fe_name ={'surf','surf_ransac_stdcrt','surf_ransac_stdcrt_stdev_linear'}; %'surf_ransac_20000', % fe_name ={'sift','surf','sift_ransac_20000','surf_ransac_20000'}; % fe_name ={'sift_ransac_stdcrt','sift_ransac_stdctr_stdev','surf_ransac_stdcrt','surf_ransac_stdcrt_stdev_linear'}; % 'sift_int_ransac_stdcrt_gc_num','sift_int_ransac_stdcrt_gc_num_em_llthreshold_001' % 'sift_int_ransac_3points_stdcrt_iter_etime''sift_int_ransac_stdcrt_confidence_etime_median','sift_int_ransac_stdcrt_gc_num_em_error_class_etime' % 'sift_int_ransac_stdcrt_iter_etime_total','sift_int_ransac_stdcrt_gc_num_em_error_class_etime_total' % 'sift_int_ransac_stdcrt_iter_tictoc_total' % 'sift_int_ransac_stdcrt_iter_tictoc_total_constraints' %fe_name_set ={{'sift_int_ransac_stdcrt_gc_num_aa_tictoc_total_constraints_confidence'},{'surf_int_ransac_stdcrt','surfcpp_int'},{'sift_int_ransac_stdcrt','surf_int_ransac_stdcrt'}}; %,'surf_int','surf_int_ransac_stdcrt','sift_int_ransac_stdcrt','sift_int_ransac_350'}; %{'sift_ransac_350','sift_int_ransac_350'}; %{'sift_ransac_stdcrt', 'sift_int_ransac_stdcrt'}; %{'sift','sift_int'}; %'sift_ransac_stdcrt','sift_ransac_stable'}; %,'sift_ransac_stdcrt','sift_ransac_350'}; %,'sift_ransac_350' %,'surf_int_ransac_stdcrt','surf_int_ransac_200'}; %{'surf_ransac_200','surf_int_ransac_200'};%{'surf_ransac_stdcrt','surf_int_ransac_stdcrt'}; %{'surf','surf_int'}; %'surf_ransac_stdcrt','sift_ransac_stable'}; %,'surf_ransac_stdcrt','surf_ransac_200'}; %,,'surf_ransac_stdcrt' %fe_name = fe_name_set{fe_selection}; %if %nFrame == 5468 %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_constraints'; %long_format = 0; if data_index == 11 % etas switch vro_name case 'vro' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_f_fast_fast_dist2_30step_nobpc'; case 'vro_icp_ch' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_f_tol01_fast_fast_dist2_loadicp_30step_nobpc'; end long_format = 0; elseif data_index == 12 % loops fe_name = 'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_featureidxfix_fast_fast'; long_format = 0; elseif data_index == 13 % kinect_tum %fe_name = 'sift_int_ransac_stdcrt_gc_num_aa_tictoc_total_constraints_confidence_indexplus1'; %'sift_int_ransac_stdcrt_iter_tictoc_total_constraints_confidence'; if vro_cpp == 1 fe_name = 'SIFT_SIFT'; long_format = 0; else fe_name = 'sift_int_ransac_stdcrt_gc_num_aa_tictoc_total_constraints_confidence_indexplus1'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1'; %'sift_int_ransac_stdcrt_gc_num_aa_tictoc_total_constraints_confidence_indexplus1'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1'; long_format = 1; end elseif data_index == 14 % loops2 switch vro_name case 'vro' if dynamic_data_index == 1 || dynamic_data_index == 3 || dynamic_data_index == 6 if strcmp(isgframe, 'gframe') fe_name = 'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_featureidxfix_fast_fast_gframe'; else %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc'; fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_f_fast_fast_dist2_30step_nobpc'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min13'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_featureidxfix_fast_fast'; %; %'sift_i_r_s_i_t_t_c_i_a_cf_cov_featureidxfix_fast_fast'; % %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_featureidxfix_fast'; %; %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_maxstep_featureidx'; end else %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc'; fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_f_fast_fast_dist2_30step_nobpc'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min13'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist3'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_featureidxfix_fast_fast'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_maxstep_featureidxfix'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_maxstep_featureidxfix'; %%'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf'; % %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq'; %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_maxstep_featureidx'; %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_maxstep_featureidxfix'; end case 'vro_icp' %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp6_featureidxfix_10step'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_noransac_icp6'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_icp6_indexplus1_adapthisteq_cf'; if dynamic_data_index == 12 fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp6_featureidxfix_maxstep_fast_fast_dist2_loadicp'; else fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp6_featureidxfix'; end case 'vro_icp_ch' if dynamic_data_index == 1 || dynamic_data_index == 5 fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_f_tol01_fast_fast_dist2_loadicp_30step_nobpc'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol01_maxstep_fast_fast_dist2_min19'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol01_maxstep_fast_fast_dist'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep_fast_fast'; %'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep_fast_fast_original';% %'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_ransac_cf05_icp9_batch_featureidxfix_tol01_maxstep_original'; % % % % % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep'; %fe_name = 'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_ransac_cf05_icp9_batch_featureidxfix_tol01_maxstep'; elseif dynamic_data_index == 12 fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol01_maxstep_fast_fast_dist2_loadicp'; else fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_f_tol01_fast_fast_dist2_loadicp_30step_nobpc'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol01_maxstep_fast_fast_dist'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep_fast_fast'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep'; %'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep_fast_fast'; %;%'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_ransac_cf05_icp9_batch_featureidxfix_tol01_10step';% 'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_ransac_cf05_icp9_batch_featureidxfix_tol01_10step'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp9_featureidxfix_maxstep'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp9_featureidxfix_tol01'; %'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_noransac_icp9'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_icp9_indexplus1_adapthisteq_cf'; end case 'icp' end long_format = 0; elseif data_index == 16 % sparse_feature switch vro_name case 'vro' % if dynamic_data_index == 1 || dynamic_data_index == 3 || dynamic_data_index == 5 || dynamic_data_index == 9 || dynamic_data_index == 11 % if strcmp(isgframe, 'gframe') % fe_name = 'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_featureidxfix_fast_fast_gframe'; % single step size % else % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_10step'; % %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_featureidxfix_fast'; % % end % elseif dynamic_data_index == 6 % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_10step'; % else % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min13'; % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist3'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist'; % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_featureidxfix_fast_fast'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_maxstep_featureidxfix'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_maxstep_featureidxfix'; %%'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf'; % %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq'; % %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_maxstep_featureidx'; % %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_maxstep_featureidxfix'; % end fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_f_fast_fast_dist2_30step_nobpc'; case 'vro_icp' if dynamic_data_index == 6 || dynamic_data_index == 5 || dynamic_data_index == 9 || dynamic_data_index == 11 fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp6_featureidxfix_maxstep_fast_fast_dist2_loadicp_10step'; else %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp6_featureidxfix'; % single step size fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp6_featureidxfix_10step'; %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp6_featureidxfix_10step'; %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp6_featureidxfix_10step'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_noransac_icp6'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_icp6_indexplus1_adapthisteq_cf'; %fe_name = 'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp6_featureidxfix'; end case 'vro_icp_ch' % if dynamic_data_index == 1 || dynamic_data_index == 3 % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol03_maxstep_fast_fast_dist2_loadicp_10step'; % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_featureidxfix_tol01_10step'; % fe_name = 'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_ransac_cf05_icp9_batch_featureidxfix_tol01_10step'; % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_featureidxfix_tol01'; % single step size % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol01_maxstep_fast_fast_dist2_min19'; % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol01_maxstep_fast_fast_dist'; % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep_fast_fast'; %'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep_fast_fast_original';% %'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_ransac_cf05_icp9_batch_featureidxfix_tol01_maxstep_original'; % % % % % % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep'; % %fe_name = 'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_ransac_cf05_icp9_batch_featureidxfix_tol01_maxstep'; % elseif dynamic_data_index == 8 % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol03_maxstep_fast_fast_dist2_loadicp_10step'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_f_tol01_fast_fast_dist2_loadicp_10step_wicp6'; % elseif dynamic_data_index == 11 % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_f_tol01_fast_fast_dist2_loadicp_10step'; % %708_frame_abs_intensity_sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_f_tol01_fast_fast_dist2_loadicp_10step % else % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol02_maxstep_fast_fast_dist'; % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep_fast_fast'; % %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep'; %'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01_maxstep_fast_fast'; %;%'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_ransac_cf05_icp9_batch_featureidxfix_tol01_10step';% 'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_ransac_cf05_icp9_batch_featureidxfix_tol01_10step'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp9_featureidxfix_maxstep'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_ransac_cf05_icp9_featureidxfix_tol01'; %'sift_i_r_s_i_t_t_c_i_a_cf_cov_ransac_cf05_icp9_featureidxfix_tol01'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_noransac_icp9'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_icp9_indexplus1_adapthisteq_cf'; % end fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_f_tol01_fast_fast_dist2_loadicp_30step_nobpc'; case 'icp' end long_format = 0; elseif data_index == 17 % swing %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_featureidxfix_fast_fast'; switch vro_name case 'vro' %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_f_fast_fast_dist2_30step_nobpc'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2'; fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc_svde6'; % if dynamic_data_index == 1 || dynamic_data_index == 2 % % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min40' % fe_name = 'sift_i_r_s_i_t_t_c_i_adapthisteq_cf_cov_featureidxfix_fast_fast'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min19'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist_min40'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist_lc_min40'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min19_lc'; % else % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min40_histeq_lc'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min40_histeq_server'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min40_lc'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min40' % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_min13'; % fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist'; % end case 'vro_icp' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp6_featureidxfix_maxstep_fast_fast_dist2'; case 'vro_icp_ch' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol04_maxstep_fast_fast_dist2'; end long_format = 0; elseif data_index == 18 % swing2 %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_featureidxfix_fast_fast'; switch vro_name case 'vro' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2'; case 'vro_icp' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp6_featureidxfix_maxstep_fast_fast_dist2_loadicp'; case 'vro_icp_ch' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol01_maxstep_fast_fast_dist2_loadicp'; end long_format = 0; elseif data_index == 19 % motive %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_featureidxfix_fast_fast'; switch vro_name case 'vro' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc'; %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc_10m'; case 'vro_icp' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp6_featureidxfix_maxstep_fast_fast_dist2_loadicp'; case 'vro_icp_ch' %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol01_maxstep_fast_fast_dist2_loadicp'; fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_f_tol01_fast_fast_dist2_loadicp_30step_nobpc'; end long_format = 0; elseif data_index == 20 % object_recognition %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_featureidxfix_fast_fast'; switch vro_name case 'vro' %fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc_20st'; fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc'; case 'vro_icp' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp6_featureidxfix_maxstep_fast_fast_dist2_loadicp'; case 'vro_icp_ch' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_featureidxfix_tol01_maxstep_fast_fast_dist2_loadicp'; end long_format = 0; elseif data_index == 21 % map %fe_name = 'sift_i_r_s_i_t_t_c_i_a_cf_cov_featureidxfix_fast_fast'; switch vro_name case 'vro' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc'; case 'vro_icp' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp6_featureidxfix_maxstep_fast_fast_dist2_loadicp'; case 'vro_icp_ch' fe_name = 'sift_i_r_s_i_t_t_c_i_a_c_c_r_cf05_icp9_batch_f_tol01_fast_fast_dist2_loadicp_30step_nobpc'; end long_format = 0; elseif data_index == 15 % amir_vro switch vro_name case 'vro' fe_name = 'amir_vro'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf'; % %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq'; case 'vro_icp' fe_name = 'amir_vro_icp6'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_noransac_icp6'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_icp6_indexplus1_adapthisteq_cf'; case 'vro_icp_ch' fe_name = 'amir_vro_icp9'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_indexplus1_adapthisteq_cf_cov_noransac_icp9'; %'sift_int_ransac_stdcrt_iter_tictoc_total_confidence_icp9_indexplus1_adapthisteq_cf'; case 'icp' end long_format = 0; % elseif nFrame == 659 % fe_name = 'sift_int_ransac_stdcrt_gc_num_aa_tictoc_total_constraints_confidence_icp5_intensity'; % long_format = 1; %1; % 1 = geometric constraints; 0=Others % elseif nFrame == 427 % fe_name = 'sift_int_ransac_stdcrt_gc_num_aa_tictoc_total_constraints_confidence_indexplus1'; % long_format =1; % elseif nFrame == 118 || nFrame == 108 % fe_name = 'sift_int_ransac_stdcrt_gc_num_aa_tictoc_total_constraints_confidence_indexplus1_minlength'; % long_format =1; % elseif nFrame == 249 % fe_name = 'int_tictoc_total_confidence_icp7_intensity'; % long_format =0; else fe_name = 'sift_int_ransac_stdcrt_gc_num_aa_tictoc_total_constraints_confidence'; %'sift_int_ransac_stdcrt_gc_num_aa_tictoc_total_constraints_confidence_icp6_indexplus1'; % %; % %; % % % % % long_format = 1; %1; % 1 = geometric constraints; 0=Others end legend_name_set={{'SIFT'},{'SURF Gaussian ', 'SURF cpp'},{'SIFT Gaussian', 'SURF Gaussian'}}; %,'SIFT 400ms'}; %{'SIFT 400ms', 'SIFT INT 400ms'}; %{'SIFT STC','SIFT INT STC'}; %{'SIFT 700','SIFT INT 700'}; %'SIFT STC','SIFT STEV'}; %,'SIFT STC','SIFT 400ms'}; %,'SIFT 400ms' 'surf ransac 20000', 'surf ransac stdcrt'{'sift','sift ransac std crt','sift inlier driven'};%,'surf inlier driven'}; %consensus_name; %fe_name; %image_name; %filter_list; %, 'SURF STC', 'SURF 400ms'}; %{'SURF 400ms', 'SURF INT 400ms'}; %{'SURF STC', 'SURF INT STC'}; %{'SURF', 'SURF INT'}; %'SURF STC','SURF STDEV'}; %,'SURF STC','SURF 400ms'}; % ,,'SURF STC' number_long_format = 2; % Number of long format is_frame_index = 1; % 0 : frame index does not exist, 1: frame index exists switch data_name{data_index} case {'pitch', 'pitch2'} maxData = 28; % 11 inc_max = 9; %6; %9; %11; % 3 * 11 = 33 << 34 degree of FOV interval = angle_interval; unit='degree'; movement_name = 'Pitch'; case 'pan' maxData = 29; inc_max = 11; %14; % 3 * 14 = 42 << 43 degree of FOV interval = angle_interval; unit='degree'; movement_name = 'Yaw'; case 'roll' maxData = 9; inc_max = 6; interval = angle_interval; unit='degree'; movement_name = 'Roll'; case 'x' maxData = 13; inc_max = 2; %3; %maxData-1; interval = translation_interval; unit='mm'; movement_name = 'X'; case 'y' maxData = 11; inc_max = 2; %maxData-3; %maxData-1; interval = translation_interval; unit='mm'; movement_name = 'Y'; case 'x2' maxData = 6; inc_max = 5; %maxData-1; unit='mm'; interval = translation_interval_2; movement_name = 'X'; case 'y2' maxData = 9; inc_max = 6; %maxData-1; unit='mm'; interval = translation_interval_2; movement_name = 'Y'; case 'c1' maxData = 4; inc_max = 1; unit='degree degree mm'; dir_name = {'y-3_p6_x100','y-6_p12_x500','y-12_p9_x300'}; interval = c1_movement; movement_name = 'Yaw,Pitch and X'; case 'c2' maxData = 4; inc_max = maxData-1; unit='degree degree mm'; dir_name = {'y-6_p3_y200','y-9_p12_y400','y-12_p6_y600'}; interval = c2_movement; movement_name = 'Yaw,Pitch and Y'; case 'c3' maxData = 5; inc_max = maxData-1; unit='degree degree mm'; dir_name = {'y3_p12_x100','y6_p9_x200','y9_p6_x300','y12_p3_x400'}; interval = c3_movement; movement_name = 'Yaw,Pitch and X'; case 'c4' maxData = 2;convert_vro_g2o(data_index, dis) inc_max = maxData-1; unit='degree degree mm'; dir_name = {'y-3_p9_y300'}; interval = c4_movement; movement_name = 'Yaw,Pitch and Y'; case 'm' inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name={'pitch_3degree','pitch_9degree','pan_3degree','pan_9degree','pan_30degree','pan_60degree','roll_3degree','roll_9degree','x_30mm','x_150mm','x_300mm','y_30mm','y_150mm','y_300mm','square_500','square_700','square_swing','square_1000','test'}; interval = 0; movement_name = 'pitch'; %velocity = [3 9 3 9 3 9 1 5 10 1 5 10] start_frame = [11 8 11 8 8 6 11 11 11 8 6 21 8 8 40 40 50 101]; finish_frame = [70 25 70 25 16 11 135 50 150 35 21 150 35 22 316 376 397 130]; %316 %nFrame = finish_frame(dynamic_data_index) - start_frame(dynamic_data_index) - 1; %nFrame = 829; %270; case 'etas' inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name={'3th_straight','3th_swing','4th_straight','4th_swing','5th_straight','5th_swing'}; interval = 0; case 'loops' inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name={'bus','bus_3','bus_door_straight_150','bus_straight_150','data_square_small_100','eit_data_150','exp1','exp2','exp3','exp4','exp5','lab_80_dynamic_1','lab_80_swing_1','lab_it_80','lab_lookforward_4','s2','second_floor_150_not_square','second_floor_150_square','second_floor_small_80_swing','third_floor_it_150'}; interval = 0; case {'loops2','amir_vro'} inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name= get_loops2_filename(); %{'exp4','bus_','bus_3','bus_door_straight_150'}; interval = 0; case {'sparse_feature'} inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name= get_sparse_feature_filename(); %{'exp4','bus_','bus_3','bus_door_straight_150'}; interval = 0; case {'swing'} inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name= get_dir_name(data_name{data_index}); %{'exp4','bus_','bus_3','bus_door_straight_150'}; interval = 0; case {'swing2'} inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name= get_dir_name(data_name{data_index}); %{'exp4','bus_','bus_3','bus_door_straight_150'}; interval = 0; case {'motive'} inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name= get_dir_name(data_name{data_index}); %{'exp4','bus_','bus_3','bus_door_straight_150'}; interval = 0; case {'object_recognition'} inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name= get_dir_name(data_name{data_index}); %{'exp4','bus_','bus_3','bus_door_straight_150'}; interval = 0; case {'map'} inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; dir_name= get_dir_name(data_name{data_index}); %{'exp4','bus_','bus_3','bus_door_straight_150'}; interval = 0; case 'kinect_tum' inc_max = 1; inc_min = inc_max; %nFrame = nFrame_list(dynamic_data_index) - 1; unit = 'degree'; %dir_name = {'x_500qc','pitch_10degree','pitch_3degree','pan_3degree','pan_10degree','x_1mm','x_10mm','x_5mm'}; if vro_cpp == 1 dir_name=get_kinect_tum_dir_name_vro_cpp(); else dir_name=get_kinect_tum_dir_name(); end interval = 0; otherwise disp('Data name is unknown.'); return; end abs_error=cell(inc_max*length(image_name)*length(filter_list)*length(consensus_name),1); % o_y_label = {'Relative Angle [degree]', 'Standard Deviation [degree]','Error with Standard Deviation [degree]'}; % t_y_label = {'Relative translation [mm]', 'Standard Deviation [mm]','Error with Standard Deviation [mm]'}; %Read the result file. file_index = 1; for img_index = 1:length(image_name) for filter_index=1:length(filter_list) for fe_index=1:1 for con_index=1:length(consensus_name) for inc = inc_min: inc_max % if inc == 1 && fe_index ==2 % nFrame = 10; %322; %530; %19; % elseif inc == 2 && fe_index ==2 % nFrame = 130; %540; % elseif inc == 3 && fe_index ==2 % nFrame = 540; % elseif inc == 4 && fe_index ==2 % nFrame = 38; %540; % end % elseif inc == 6 && fe_index ==2 % nFrame = 247; % end switch image_name{img_index} case 'intensity' switch filter_list{filter_index} case 'none' switch consensus_name case 'ransac' if data_index == 3 || nFrame == 1000 % new file name format error_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); %error_std_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d_std.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); else switch fe_name{fe_index} case {'sift','surf'} %old file name format error_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s.dat',data_name{data_index},inc*interval,unit,nFrame,fe_name{fe_index}); %error_std_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_std.dat',data_name{data_index},inc*interval,unit,nFrame,fe_name{fe_index}); case {'surf_nolimit','surf_ransac_limit_14000_11','sift_ransac_limit_14000_14','sift_ransac_std_crt','sift_ransac_stdcrt','sift_ransac_20000','sift_ransac_stdcrt_15p','sift_ransac_stdctr_stdev','surf_ransac_20000', 'surf_ransac_stdcrt','surf_ransac_stdctr_stdev','surf_ransac_stdcrt_stdev_linear','sift_ransac_450','surf_ransac_350','surf_ransac_300','sift_ransac_350','surf_ransac_200','sift_ransac_stable','sift_int','sift_int_ransac_stdcrt','sift_int_ransac_350','surf_int','surf_int_ransac_stdcrt','surf_int_ransac_200','surfcpp_int','surf_int_ransac_stdcrt_12','surf_int_ransac_stdcrt_t2','sift_int_ransac_stdcrt_gc_msdtc','sift_int_ransac_stdcrt_gc_num'} % new file name format error_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); %error_convert_vro_g2o(data_index, dis)std_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d_std.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); end end case {'gc','gc_30p','gc_20p','gc_40p','ggc_10p'} % switch error_std_index % case 1 error_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d_%s.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); %,consensus_name{con_index}); % case 2 %error_std_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d_%s_std.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); %,consensus_name{con_index}); end case {'median','gaussian','median5','gaussian5'} switch data_name{data_index} case {'c1', 'c2', 'c3', 'c4'} error_file_name = sprintf('result/%s/%s/%d_frame_abs_%s_%s_%s_%d.dat',data_name{data_index},dir_name{inc},nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); %error_std_file_nconvert_vro_g2o(data_index, dis)ame = sprintf('result/%s/%s/%d_frame_abs_%s_%s_%s_%d_std.dat',data_name{data_index},dir_name{inc},nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); case {'m','etas','loops','kinect_tum','loops2','amir_vro','sparse_feature','swing','swing2','motive','object_recognition','map'} if vro_cpp == 1 error_file_name = sprintf('D:/soonhac/Project/PNBD/SW/ubuntu_backup/vro_result/%s/vro_cpp_%d_%s.dat',dir_name{dynamic_data_index},nFrame,fe_name); elseif with_lc_flag == 1 % typical LC % error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_lc.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_lc.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_lc.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_lc_2nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_lc_2nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_lc_2nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_lc_2nghbr_20th.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_lc_2nghbr_20th.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_lc_2nghbr_20th.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % % error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_lc_3nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_lc_3nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_lc_3nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_lc_2nghbr_long_term.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_lc_2nghbr_long_term.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_lc_2nghbr_long_term.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % min_match_points_file_name = sprintf('../Localization/result/%s/%s/min_match_points_%d_with_lc.mat',data_name{data_index},dir_name{dynamic_data_index}, min_matched_points); elseif with_lc_flag == 2 % typical LC with neighbors error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_lc_wn.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_lc_wn.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_lc_wn.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); min_match_points_file_name = sprintf('../Localization/result/%s/%s/min_match_points_%d_with_lc_wn.mat',data_name{data_index},dir_name{dynamic_data_index}, min_matched_points); elseif with_lc_flag == 3 % fast LC % error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_fast4_lc.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_fast4_lc.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_fast4_lc.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_fast4_lc_2nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_fast4_lc_2nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_fast4_lc_2nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_fast4_lc_2nghbr_20th.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_fast4_lc_2nghbr_20th.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_fast4_lc_2nghbr_20th.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); min_match_points_file_name = sprintf('../Localization/result/%s/%s/min_match_points_%d_with_fast4_lc.mat',data_name{data_index},dir_name{dynamic_data_index}, min_matched_points); elseif with_lc_flag == 4 % long-term LC error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_with_lc_2nghbr_long_term.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_with_lc_2nghbr_long_term.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_with_lc_2nghbr_long_term.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); min_match_points_file_name = sprintf('../Localization/result/%s/%s/min_match_points_%d_with_lc.mat',data_name{data_index},dir_name{dynamic_data_index}, min_matched_points); else error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_cull_2.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_cull_2_feature_points.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_cull_2_pose_std.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); min_match_points_file_name = sprintf('../Localization/result/%s/%s/min_match_points_%d.mat',data_name{data_index},dir_name{dynamic_data_index}, min_matched_points); % error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_2nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_2nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_2nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % % % % error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_3nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points_3nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std_3nghbr.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); % min_match_points_file_name = sprintf('../Localization/result/%s/%s/min_match_points_%d.mat',data_name{data_index},dir_name{dynamic_data_index}, min_matched_points); % if strcmp(data_name{data_index}, 'm') == 1 && gt_file == 1 time_stamp_name = sprintf('../data/dynamic/%s/d1_timestamp.dat',dir_name{dynamic_data_index}); gt_name = sprintf('../data/dynamic/%s/d1_gt.dat',dir_name{dynamic_data_index}); end end otherwise if vro_cpp == 1 error_file_name = sprintf('D:/soonhac/Project/PNBD/SW/ubuntu_backup/vro_result/%s/%d_%s/vro_cpp_%d_%s.dat',data_name{data_index},inc*interval,unit,nFrame,fe_name{fe_index}); else error_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); %error_std_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d_std.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); end end end case 'depth' % switch error_std_index % case 1 %error_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); % case 2 %error_std_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d_std.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); % end error_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); feature_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_feature_points.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); pose_std_file_name = sprintf('../Localization/result/%s/%s/%d_frame_abs_%s_%s_%s_%d_pose_std.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name,filter_list{filter_index},cut_off); min_match_points_file_name = sprintf('../Localization/result/%s/%s/min_match_points_%d.mat',data_name{data_index},dir_name{dynamic_data_index}, min_matched_points); if strcmp(data_name{data_index}, 'm') == 1 && gt_file == 1 time_stamp_name = sprintf('../data/dynamic/%s/d1_timestamp.dat',dir_name{dynamic_data_index}); gt_name = sprintf('../data/dynamic/%s/d1_gt.dat',dir_name{dynamic_data_index}); end case {'fuse','fuse_std'} switch data_name{data_index} case {'m'} error_file_name = sprintf('result/%s/%s/%d_frame_abs_%s_%s_%s_%d.dat',data_name{data_index},dir_name{dynamic_data_index},nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); time_stamp_name = sprintf('../data/dynamic/%s/d1_timestamp.dat',dir_name{dynamic_data_index}); gt_name = sprintf('../data/dynamic/%s/d1_gt.dat',dir_name{dynamic_data_index}); otherwise error_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); % case 2 %error_std_file_name = sprintf('result/%s/%d_%s/%d_frame_abs_%s_%s_%s_%d_std.dat',data_name{data_index},inc*interval,unit,nFrame,image_name{img_index},fe_name{fe_index},filter_list{filter_index},cut_off); end otherwise disp('Data name is unknown.'); return; end % abs_error((img_index-1)*inc_max*length(filter_list)*length(fe_index)+(filter_index-1)*inc_max*length(fe_name)+(fe_index-1)*inc_max+inc,1) = {load(error_file_name)}; abs_error(file_index,1) = {load(error_file_name)}; if feature_flag == 1 && fileExists(feature_file_name) feature_points_cell(file_index,1) = {load(feature_file_name)}; %feature_flag = 1; else feature_points_cell(file_index,1) = {[]}; feature_flag = 0; end if pose_std_flag == 1 pose_std_cell(file_index,1) = {load(pose_std_file_name)}; else pose_std_cell(file_index,1) = {[]}; end if strcmp(data_name{data_index}, 'm') == 1 && gt_file == 1 %abs_error_std(file_index,1) = {load(error_std_file_name)}; %else time_stamp(file_index,1) = {load(time_stamp_name)}; gt(file_index,1) = {load(gt_name)}; end file_index = file_index + 1; end end end end end %plot orientation error kinect_depth_file_num=[]; t_error=[]; o_error=[]; f_index=[]; icp_ct=[]; valid_count = 0; index_max = inc_max * length(image_name) * length(filter_list) * length(consensus_name) for inc = 1: index_max unit_abs_error = abs_error{inc,1}; if pose_std_flag == 1 unit_pose_std = pose_std_cell{inc,1}; end % Filter by number of matched points % if is_frame_index == 0 % if long_format == 0 % match_index = 17; % else % match_index = 18; % end % else % if vro_cpp == 1 % match_index = 19; % else % if long_format == 0 % match_index = 18; % else % match_index = 20; % end % end % end % % e = unit_abs_error(:,match_index) < min_matched_points; % temp_size = size(unit_abs_error,1); % unit_abs_error(e,:)=[]; % eliminated_size = temp_size - size(unit_abs_error,1) % if pose_std_flag == 1 % unit_pose_std(e,:)=[]; % end %size(unit_abs_error) if is_frame_index == 0 if long_format == 0 error_index = 17; else error_index = 19; end else if vro_cpp == 1 error_index = 20; else if long_format == 0 error_index = 19; else error_index = 21; end end end % Apply only dataset 1 in etas % if strcmp(data_name{data_index}, 'etas') == 1 % unit_abs_error(:,1:2) = unit_abs_error(:,1:2) - 9; % end % Analyze nMatch %analyze_nMatch(unit_abs_error, error_index); if strcmp(data_name{data_index}, 'amir_vro') == 0 % Delete invalid data e = unit_abs_error(:,error_index) ~= 0; unit_abs_error(e,:)=[]; if pose_std_flag == 1 unit_pose_std(e,:)=[]; end if strcmp(vro_name, 'vro') == 1 e = unit_abs_error(:,error_index-1) < min_matched_points; %save index of matched points; number of which is less than min_matched_points temp_f_index = unit_abs_error(e,1:2); save(min_match_points_file_name, 'e','temp_f_index'); unit_abs_error(e,:)=[]; if pose_std_flag == 1 unit_pose_std(e,:)=[]; end else % load(min_match_points_file_name); % apply index from VRO % vro_idx=[]; % for k=1:size(temp_f_index,1) % temp_vro_idx = find(unit_abs_error(:,1) == temp_f_index(k,1) & unit_abs_error(:,2) == temp_f_index(k,2)); % if ~isempty(temp_vro_idx) % vro_idx = [vro_idx; temp_vro_idx]; % end % end % unit_abs_error(vro_idx,:)=[]; e = unit_abs_error(:,error_index-1) < min_matched_points; unit_abs_error(e,:)=[]; if pose_std_flag == 1 % unit_pose_std(vro_idx,:)=[]; unit_pose_std(e,:)=[]; end end end % eliminate specific data temporary % temp_idx = find(unit_abs_error(:,1) == 48 & unit_abs_error(:,2) == 59) % unit_abs_error(temp_idx,:) = []; % unit_pose_std(temp_idx,:) =[]; % % temp_idx = find(unit_abs_error(:,1) == 80 & unit_abs_error(:,2) == 98) % unit_abs_error(temp_idx,:) = []; % unit_pose_std(temp_idx,:) =[]; % % temp_idx = find(unit_abs_error(:,1) == 94 & unit_abs_error(:,2) == 125) % unit_abs_error(temp_idx,:) = []; % unit_pose_std(temp_idx,:) =[]; % % temp_idx = find(unit_abs_error(:,1) == 132 & unit_abs_error(:,2) == 165) % unit_abs_error(temp_idx,:) = []; % unit_pose_std(temp_idx,:) =[]; % % temp_idx = find(unit_abs_error(:,1) == 278 & unit_abs_error(:,2) == 286) % unit_abs_error(temp_idx,:) = []; % unit_pose_std(temp_idx,:) =[]; if is_frame_index == 0 o_error = [o_error; unit_abs_error(:,1:3)]; t_error = [t_error; unit_abs_error(:,4:6)]; else if vro_cpp == 1 f_index = [f_index; unit_abs_error(:,1:2)]; kinect_depth_file_num = [kinect_depth_file_num; unit_abs_error(:,3) ]; o_error = [o_error; unit_abs_error(:,7:9)]; % [rx ry rz] [radian] t_error = [t_error; unit_abs_error(:,4:6)]; % [meter] else f_index = [f_index; unit_abs_error(:,1:2)]; o_error = [o_error; unit_abs_error(:,3:5)]; % [ry rx rz] t_error = [t_error; unit_abs_error(:,6:8)]; if strcmp(data_name{data_index}, 'amir_vro') == 0 icp_ct = [icp_ct; unit_abs_error(:,1:2) unit_abs_error(:,9:16)]; end end end if pose_std_flag == 1 pose_std = unit_pose_std(:,3:8); %[ry rx rz tx ty tz] else pose_std = []; end valid_count = valid_count + 1; %end end feature_points = feature_points_cell{1,1}; %Adjust the measurement unit in standard deviation % t_error_std = t_error_std * 1000; % meter -> milimeter % o_error_std = o_error_std * 180 / pi; % radian -> degree % Adjust the measurement unit t_error = t_error * 1000; % meter -> milimeter o_error = o_error * 180 / pi; % radian -> degree t_pose = t_error; % [mm] o_pose = o_error; % [degree] %% Analysis motion estimation by step sizes % for i=1:1 %7 % % step_idx = (f_index(:,2) - f_index(:,1)) == i; % t_error_step = t_error(step_idx,:); % % o_error_step = t_error(step_idx,:); % % figure(1);plot(t_error_step(:,1),'*');title('X'); % figure(2);plot(t_error_step(:,2),'*');title('Y'); % % figure(3);plot(t_error_step(:,3),'*');title('Z'); % % figure(4);plot(o_error_step(:,1),'*');title('Ry'); % % figure(5);plot(o_error_step(:,2),'*');title('Rx'); % % figure(6);plot(o_error_step(:,3),'*');title('Rz'); % % %load time % f_index_tmp = f_index(step_idx,1); % for k=1:size(f_index_tmp,1) % [img, x, y, z, c, rtime, time_stamp(k)] = LoadSR_no_bpc_time(data_name{data_index}, 'gaussian', 0, dynamic_data_index, f_index_tmp(k,1), 1, 'int'); % end % time_interval = diff(time_stamp); % speed = t_error_step(2:end,2)./time_interval'; % % %figure(3);plot(time_stamp,'d');title('Time Stamp'); % figure(3);plot(speed);title('Speed'); % %mean_speed = mean(speed(100:end-100)) % for loops 2 % %median_speed = median(speed(100:end-100)) % for loops 2 % mean_speed = mean(speed(30:end-30)) % median_speed = median(speed(30:end-30)) % % % Save speed % [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name{data_index}, dynamic_data_index); % save(sprintf('%s_speed.mat',prefix),'t_error_step','time_stamp','time_interval','speed'); % end %% Delete data which has smaller amount than convariance % t_thresh = 14; % 14 mm % o_thresh = 0.48; % 0.48 degree % e = abs(t_error(:,1)) < t_thresh & abs(t_error(:,2)) < t_thresh & abs(t_error(:,3)) < t_thresh & abs(o_error(:,1)) < o_thresh & abs(o_error(:,2)) < o_thresh & abs(o_error(:,3)) < o_thresh; % % f_index(e,:) = []; % o_error(e,:) = []; % t_error(e,:) = []; % Replace the measurement which is less than noise threshold with zero % t_thresh =7; %14; %14; %14; % 14 mm % o_thresh = 0.24; %0.12; %0.24; %0.24; % 0.48 degree % for i=1:size(t_pose,1) % for j=1:size(t_pose,2) % if abs(t_pose(i,j)) < t_thresh % t_pose(i,j) = 0; % end % if abs(o_pose(i,j)) < o_thresh % o_pose(i,j) = 0; % end % end % end % % e = abs(t_error(:,1)) == 0 & abs(t_error(:,2)) == 0 & abs(t_error(:,3)) == 0; % % f_index(e,:) = []; % o_pose(e,:) = []; % t_pose(e,:) = []; % figure; % plot(icp_ct,'.'); % ylabel('Computatoinal Time [sec]') % set(gca,'FontSize',12,'FontWeight','bold'); % h_ylabel = get(gca,'YLabel'); % set(h_ylabel,'FontSize',12,'FontWeight','bold'); % icp_ct_mean = mean(icp_ct) % icp_ct_median = median(icp_ct) % icp_ct_max = max(icp_ct) % icp_ct_min = min(icp_ct) if feature_flag == 1 feature_points(:,4:6) = feature_points(:,4:6) * 1000; % [m] -> [mm] end end function analyze_nMatch(unit_abs_error, error_index) %nMatch = unit_abs_error(:,error_index-1); hist_center = 10:20:200; % for visual features %hist_center = 1:3:30; % hist(nMatch,hist_center); % % nMatch_hist = hist(nMatch,hist_center); step_size = unit_abs_error(:,2) - unit_abs_error(:,1); step_size_uniq = unique(step_size); %mean_nMatch=[]; figure; for s=1:6 idx = find(step_size == s); nMatch = unit_abs_error(idx,error_index-1); subplot(3,2,s);hist(nMatch,hist_center);title(sprintf('Step Size %d',s)); ylim([0 600]); %mean_nMatch = [mean_nMatch; mean(nMatch)]; end % mean_nMatch' end
github
rising-turtle/slam_matlab-master
convert_vro_isam.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/convert_vro_isam.m
27,716
utf_8
b164bdf3514139a7606b2c86e2ff7c2f
% Conver the results of VRO to the vertex and edges for isam % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function [vro_size, e_t_pose_size, feature_points_visual] = convert_vro_isam(data_index, dynamic_index, nFrame, file_name, dir_name, feature_pose_name, feature_flag, index_interval, cmp_option, dense_index, sparse_interval, vro_cpp, constraint_max_interval, vro_name, pose_std_flag, isgframe, pixel_culling_size, min_matched_points, with_lc_flag, dis) if nargin < 20 dis = 0; end % Load the result of VRO [f_index, t_pose, o_pose, feature_points, pose_std, icp_ct] = load_vro(data_index,dynamic_index, nFrame, 1, vro_cpp, vro_name, pose_std_flag, isgframe, min_matched_points, with_lc_flag); % t_pose[mm], o_pose[degree], feature_points [mm] feature_points_visual = feature_points; if feature_flag == 0 feature_points=[]; end if isempty(feature_points) feature_flag = 0; end vro_size = size(t_pose,1) % Interploation for missing constraints if feature_flag == 0 [f_index, t_pose, o_pose, feature_points, pose_std] = compensate_vro(f_index, t_pose, o_pose, feature_points, pose_std, pose_std_flag, cmp_option); else feature_points = sampling_feature_points(feature_points, pixel_culling_size); %check_camera_projection(feature_points,isgframe); [f_index, t_pose, o_pose, feature_points(:,1:2), pose_std] = compensate_vro(f_index, t_pose, o_pose, feature_points(:,1:2), pose_std, pose_std_flag, cmp_option); % Generate global index of feature points feature_points = generate_feature_index(feature_points); end % Conver the odometry to the global poses % e_t_pose [mm] e_o_pose [radian] [pose_index e_t_pose e_o_pose e_fpts trajectory_length] = convert_o2p(data_index, dynamic_index, f_index, t_pose, o_pose, feature_points, dense_index, sparse_interval, vro_cpp, isgframe); %[pose_index e_t_pose e_o_pose e_fpts] = convert_o2p_adaptive(data_index, dynamic_index, f_index, t_pose, o_pose, feature_points, dense_index, sparse_interval); % e_t_pose [mm] e_o_pose [radian] %check_camera_projection2(e_t_pose, e_o_pose, e_fpts, isgframe); e_t_pose_size = size(e_t_pose,1) first_pose = e_t_pose(1,:) last_pose = e_t_pose(end,:) distance_first_last = sqrt(sum((first_pose(1:3) - last_pose(1:3)).^2)) trajectory_length length_percentage_error = distance_first_last * 100 / trajectory_length % Generate an index of feature points on the global poses if feature_flag == 1 [g_fpts g_fpts_edges] = convert_fpts2g(pose_index, e_fpts); end %check_camera_projection2(e_t_pose, e_o_pose, g_fpts_edges, isgframe); % plot pose if dis == 1 plot_trajectory(e_t_pose, dynamic_index); end % Write Vertexcies and Edges % if feature_flag == 1 % feature_pose_name = 'pose_feature'; % else % feature_pose_name = 'pose'; % end data_name_list = {'ODOMETRY','LANDMARK','EDGE3','VERTEX_SE3'}; fpts_name_list ={'POINT2','POINT3'}; if pose_std_flag == 1 if feature_flag == 1 file_name_final = sprintf('%s%s_%s_%s_%d_%d_fpt_%d_%s_cov.sam',file_name, dir_name, cmp_option, feature_pose_name, vro_size, e_t_pose_size, pixel_culling_size, vro_name); else file_name_final = sprintf('%s%s_%s_%s_%d_%d_%s_cov.sam',file_name, dir_name, cmp_option, feature_pose_name, vro_size, e_t_pose_size, vro_name); end else if feature_flag == 1 file_name_final = sprintf('%s%s_%s_%s_%d_%d_fpt_%d_%s.sam',file_name, dir_name, cmp_option, feature_pose_name, vro_size, e_t_pose_size, pixel_culling_size, vro_name); else file_name_final = sprintf('%s%s_%s_%s_%d_%d_%s.sam',file_name, dir_name, cmp_option, feature_pose_name, vro_size, e_t_pose_size, vro_name); end end file_name_pose = sprintf('%s%s_%s_%s_%d_%d_%s.isp',file_name, dir_name, cmp_option, feature_pose_name, vro_size, e_t_pose_size, vro_name); icp_ct_file_name_final = sprintf('%s%s_%s_%s_%d_%d_%s_icp.ct',file_name, dir_name, cmp_option, feature_pose_name, vro_size, e_t_pose_size, vro_name); pose_std_file_name_final = sprintf('%s%s_%s_%s_%d_%d_%s_pose.std',file_name, dir_name, cmp_option, feature_pose_name, vro_size, e_t_pose_size, vro_name); t_cov = 0.034; % [m] in SR4000 %t_cov = 0.5; o_cov = 0.5 * pi / 180; % [rad] in SR4000 %o_cov = 3 * pi / 180; cov_mat = zeros(6,6); for i=1:size(cov_mat,1) if i > 3 cov_mat(i,i) = o_cov; else cov_mat(i,i) = t_cov; end end info_mat = cov_mat^-1; sqrt_info_mat = sqrt(info_mat); e_t_pose = e_t_pose/1000; % [mm] -> [m] t_pose = t_pose / 1000; %[mm] -> [m] o_pose = o_pose * pi / 180; % [degree] -> [radian] if feature_flag == 1 g_fpts(:,2:4) = g_fpts(:,2:4)/1000; %[mm] -[m] g_fpts_edges(:,3:5) = g_fpts_edges(:,3:5)/1000; %[mm] -> [m] end %Convert the euler angles to quaterion %disp('Convert the euler angles to quaterion.'); %for i=1:size(o_pose,1) % temp_rot = euler_to_rot(o_pose(i,1),o_pose(i,2),o_pose(i,3)); % o_pose_quat(i,:) = R2q(temp_rot); %o_pose_quat(i,:) = e2q([o_pose(i,2),o_pose(i,1),o_pose(i,3)]); %end f_index(:,2) = f_index(:,2) ; %+ index_interval; %TODO: Generalize !!! isp_fd = fopen(file_name_pose, 'w'); for i=1:size(e_t_pose,1) fprintf(isp_fd,'%s %d %f %f %f %f %f %f\n', data_name_list{4}, pose_index(i)-1, e_t_pose(i,1), e_t_pose(i,2), e_t_pose(i,3), e_o_pose(i,2), e_o_pose(i,1), e_o_pose(i,3)); end fclose(isp_fd); % Analysis pose_std if pose_std_flag == 1 [median_pose_std, std_pose_std, unique_pose_step, step1_pose_std_total, step1_pose_std] = analyze_pose_std(f_index, pose_std, 0); sigma_level = 1.0; %0.9; %1.0; %0.5; %1.0; %0.9; %1.0; %step1_o_std = std_pose_std(1,1:3).*180./pi %std_diff = abs(std_pose_std(5,1:3) - std_pose_std(10,1:3))./std_pose_std(10,1:3); %write pose_std into a file pose_std_fd = fopen(pose_std_file_name_final,'w'); for i=1:size(f_index,1) fprintf(pose_std_fd,'%d %d %f %f %f %f %f %f\n', f_index(i,:)-1, pose_std(i,:)); end fclose(pose_std_fd); end isam_fd = fopen(file_name_final,'w'); additional_constraints_cnt = 0; o_constraints=[]; for i=1:size(f_index,1)-1 %fprintf(isam_fd,'%s %d %d %f %f %f %f %f %f %f %f %f\n', data_name_list{3}, f_index(i,1)-1, f_index(i,2)-1, t_pose(i,1), t_pose(i,2), o_pose(i,3), t_covariance, 0, 0, t_covariance, 0, o_covariance); if abs(f_index(i,1) - f_index(i,2)) <= constraint_max_interval if vro_cpp == 1 fprintf(isam_fd,'%s %d %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n', data_name_list{3}, f_index(i,1)-1, f_index(i,2)-1, t_pose(i,1:3), o_pose(i,1),o_pose(i,2),o_pose(i,3), sqrt_info_mat(1,:), sqrt_info_mat(2,2:6), sqrt_info_mat(3,3:6), sqrt_info_mat(4,4:6), sqrt_info_mat(5,5:6), sqrt_info_mat(6,6)); else if pose_std_flag == 1 %fprintf(isam_fd,'%s %d %d %f %f %f %f %f %f %f %f %f %f %f %f\n', data_name_list{3}, f_index(i,1)-1, f_index(i,2)-1, t_pose(i,1:3), o_pose(i,2),o_pose(i,1),o_pose(i,3), pose_std(i,4:6), pose_std(i,2),pose_std(i,1),pose_std(i,3)); %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability(pose_std(i,:), median_pose_std(1,:), std_pose_std(1,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_static(pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_static2(pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_static3(pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_static4(pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_static5(pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_static6(pose_std(i,:), sigma_level) == 1 if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_static7(pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_static8(pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_eigen(t_pose(i,:), o_pose(i,:), pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_step1based(pose_std(i,:), step1_pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_step1based2(pose_std(i,:), step1_pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_step1based3(pose_std(i,:), step1_pose_std(i,:), sigma_level) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_composite(pose_std(i,:), step1_pose_std(i,:), std_pose_std) == 1 %if (abs(f_index(i,1)-f_index(i,2)) == 1) || check_reliability_compound(pose_std(i,:), step1_pose_std, f_index(i,:)) == 1 %if (abs(f_index(i,1)-f_index(i,2)) <= 10) if (abs(f_index(i,1)-f_index(i,2)) > 1) additional_constraints_cnt = additional_constraints_cnt + 1; end pose_step = find(unique_pose_step == abs(f_index(i,1)-f_index(i,2))); % if pose_step > 40 % disp('debug here'); % end fprintf(isam_fd,'%s %d %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n', data_name_list{3}, f_index(i,1)-1, f_index(i,2)-1, t_pose(i,1:3), o_pose(i,2),o_pose(i,1),o_pose(i,3), pose_std(i,4:6), pose_std(i,2),pose_std(i,1),pose_std(i,3), median_pose_std(pose_step,4:6), median_pose_std(pose_step,2),median_pose_std(pose_step,1),median_pose_std(pose_step,3), std_pose_std(pose_step,4:6), std_pose_std(pose_step,2),std_pose_std(pose_step,1),std_pose_std(pose_step,3)); o_constraints =[o_constraints; o_pose(i,2),o_pose(i,1),o_pose(i,3)]; end else fprintf(isam_fd,'%s %d %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n', data_name_list{3}, f_index(i,1)-1, f_index(i,2)-1, t_pose(i,1:3), o_pose(i,2),o_pose(i,1),o_pose(i,3), sqrt_info_mat(1,:), sqrt_info_mat(2,2:6), sqrt_info_mat(3,3:6), sqrt_info_mat(4,4:6), sqrt_info_mat(5,5:6), sqrt_info_mat(6,6)); end end end end additional_constraints_cnt % Compute sum of relative orietation variation o_constraints_unit = sum(sum(abs(o_constraints)))/(3*size(o_constraints,1)); o_constraints_unit = o_constraints_unit*180/pi if feature_flag == 1 for i=1:size(g_fpts,1) fprintf(isam_fd,'%s %d %f %f %f\n', data_name_list{2}, g_fpts(i,1)-1, g_fpts(i,2:4)); end for i=1:size(g_fpts_edges,1) %fprintf(isam_fd,'%s %d %d %f %f %f %f %f %f %f %f %f\n', fpts_name_list{2}, g_fpts_edges(i,1)-1, g_fpts_edges(i,2)-1, g_fpts_edges(i,3:5), sqrt_info_mat(1,1:3), sqrt_info_mat(2,2:3), sqrt_info_mat(3,3)); fprintf(isam_fd,'%s %d %d %f %f %f %f %f\n', fpts_name_list{2}, g_fpts_edges(i,1)-1, g_fpts_edges(i,2)-1, g_fpts_edges(i,3:5), g_fpts_edges(i,7:8)); end end fclose(isam_fd); % new_isam_fd = fopen(new_file_name_final,'w'); % for i=1:vro_size % fprintf(isam_fd,'%s %d %d %f %f %f %f %f %f %f %f %f\n', data_name_list{1}, new_f_index(i,1)-1, new_f_index(i,2)-1, new_t_pose(i,1), new_t_pose(i,2), new_o_pose(i,3), t_covariance, 0, 0, t_covariance, 0, o_covariance); % fprintf(isam_fd,'%s %d %d %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f %f\n', data_name_list{3}, f_index(i,1)-1, f_index(i,2)-1, new_t_pose(i,1:3), new_o_pose(i,:), sqrt_info_mat(1,:), sqrt_info_mat(2,2:6), sqrt_info_mat(3,3:6), sqrt_info_mat(4,4:6), sqrt_info_mat(5,5:6), sqrt_info_mat(6,6)); % end % fclose(new_isam_fd); % Save icp ct icp_ct_fd = fopen(icp_ct_file_name_final,'w'); for i=1:size(icp_ct,1) fprintf(icp_ct_fd,'%d %d %f %f %f %f %f %f %f %f\n', icp_ct(i,:)); end fclose(icp_ct_fd); end function [reliability_flag] = check_reliability_compound(pose_std, step1_pose_std, f_index) reliability_flag = 1; compound_std=sum(step1_pose_std(f_index(1):f_index(2)-1,:)); for i=1:6 if pose_std(i) > compound_std(i) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability(pose_std, median_pose_std, std_pose_std, sigma_level) reliability_flag = 1; for i=1:6 if pose_std(i) > (median_pose_std(i) + sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_static(pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.014; %[m] orientation_sigma = 0.24*pi/180; %[radian] std_pose_std = [orientation_sigma,orientation_sigma,orientation_sigma,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 if pose_std(i) > (sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_static2(pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.014; %[m] orientation_sigma = 0.57*pi/180; %[radian] std_pose_std = [orientation_sigma,orientation_sigma,orientation_sigma,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 if pose_std(i) > (sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_static3(pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.014; %0.014; %[m] orientation_sigma_rx = 0.10*pi/180; %0.12*pi/180;%0.57*pi/180; %[radian] orientation_sigma_ry = 0.10*pi/180; %0.12*pi/180;%0.11*pi/180; %[radian] orientation_sigma_rz = 0.10*pi/180; %0.12*pi/180;%0.30*pi/180; %[radian] std_pose_std = [orientation_sigma_ry,orientation_sigma_rx,orientation_sigma_rz,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 if pose_std(i) > (sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_static4(pose_std, sigma_level) reliability_flag = 1; translation_sigma = 1.1*0.014; %[m] orientation_sigma_rx = 1.12*0.24*pi/180;%0.57*pi/180; %[radian] orientation_sigma_ry = 1.12*0.24*pi/180;%0.11*pi/180; %[radian] orientation_sigma_rz = 1.12*0.24*pi/180;%0.30*pi/180; %[radian] std_pose_std = [orientation_sigma_ry,orientation_sigma_rx,orientation_sigma_rz,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 if pose_std(i) > (sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_static5(pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.007; %14; %[m] orientation_sigma_rx = 0.16*pi/180;%0.57*pi/180; %[radian] orientation_sigma_ry = 0.16*pi/180;%0.11*pi/180; %[radian] orientation_sigma_rz = 0.16*pi/180;%0.30*pi/180; %[radian] std_pose_std = [orientation_sigma_ry,orientation_sigma_rx,orientation_sigma_rz,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 if pose_std(i) > (sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_static6(pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.007; %14; %[m] orientation_sigma_rx = 0.12*pi/180;%0.57*pi/180; %[radian] orientation_sigma_ry = 0.12*pi/180;%0.11*pi/180; %[radian] orientation_sigma_rz = 0.12*pi/180;%0.30*pi/180; %[radian] std_pose_std = [orientation_sigma_ry,orientation_sigma_rx,orientation_sigma_rz,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 if pose_std(i) > (sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_static7(pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.056; %14; %[m] orientation_sigma_rx = 0.96*pi/180;%0.57*pi/180; %[radian] orientation_sigma_ry = 0.96*pi/180;%0.11*pi/180; %[radian] orientation_sigma_rz = 0.96*pi/180;%0.30*pi/180; %[radian] std_pose_std = [orientation_sigma_ry,orientation_sigma_rx,orientation_sigma_rz,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 if pose_std(i) > (sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_static8(pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.028; %14; %[m] orientation_sigma_rx = 0.48*pi/180;%0.57*pi/180; %[radian] orientation_sigma_ry = 0.48*pi/180;%0.11*pi/180; %[radian] orientation_sigma_rz = 0.48*pi/180;%0.30*pi/180; %[radian] std_pose_std = [orientation_sigma_ry,orientation_sigma_rx,orientation_sigma_rz,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 if pose_std(i) > (sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_step1based(pose_std, step1_pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.014; %[m] orientation_sigma = 0.12*pi/180;%0.57*pi/180; %[radian] std_pose_std = [orientation_sigma,orientation_sigma,orientation_sigma,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 if pose_std(i) > std_pose_std(i) && pose_std(i) > (sigma_level * step1_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_step1based2(pose_std, step1_pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.014; %[m] orientation_sigma = 0.12*pi/180;%0.57*pi/180; %[radian] std_pose_std = [orientation_sigma,orientation_sigma,orientation_sigma,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 %if pose_std(i) > std_pose_std(i) && pose_std(i) > (sigma_level * step1_pose_std(i)) if pose_std(i) > (sigma_level * step1_pose_std(i)) reliability_flag = 0; break; end end end function [reliability_flag] = check_reliability_step1based3(pose_std, step1_pose_std, sigma_level) reliability_flag = 0; translation_sigma = 0.014; %[m] orientation_sigma = 0.12*pi/180;%0.57*pi/180; %[radian] std_pose_std = [orientation_sigma,orientation_sigma,orientation_sigma,translation_sigma,translation_sigma,translation_sigma]; for i=1:6 %if pose_std(i) > std_pose_std(i) && pose_std(i) > (sigma_level * step1_pose_std(i)) if pose_std(i) < (sigma_level * step1_pose_std(i)) reliability_flag = 1; break; end end end function [reliability_flag] = check_reliability_composite(pose_std, step1_pose_std, std_pose_std) [step1_max_orientation, max_idx]= max(std_pose_std(1,1:3)); step10_step5_ratio = abs(std_pose_std(10,max_idx)-std_pose_std(5,max_idx))/std_pose_std(10,max_idx); step10_step5_ratio_rz = abs(std_pose_std(10,3)-std_pose_std(5,3))/std_pose_std(10,3); if step1_max_orientation*180/pi < 0.1 || (step1_max_orientation*180/pi > 0.7 && step10_step5_ratio < 0.35 && step10_step5_ratio_rz < 0.55) reliability_flag = check_reliability_static3(pose_std, 0.9); else reliability_flag = check_reliability_step1based(pose_std, step1_pose_std, 1.0); end end function [reliability_flag] = check_reliability_eigen(t_pose, o_pose, pose_std, sigma_level) reliability_flag = 1; translation_sigma = 0.014; %[m] orientation_sigma_rx = 0.12*pi/180;%0.57*pi/180; %[radian] orientation_sigma_ry = 0.12*pi/180;%0.11*pi/180; %[radian] orientation_sigma_rz = 0.12*pi/180;%0.30*pi/180; %[radian] std_pose_std = [orientation_sigma_ry,orientation_sigma_rx,orientation_sigma_rz,translation_sigma,translation_sigma,translation_sigma]; %find dominant movement t_eigen_thresh = 0.020; %[m] o_eigen_thresh = 1*pi/180; eigen_index =zeros(6,1); for i=1:6 if i>=4 %translation if t_pose(i-3) > t_eigen_thresh eigen_index(i) = 1; end else if o_pose(i) > o_eigen_thresh eigen_index(i) = 1; end end end for i=1:6 if eigen_index(i) == 1 && pose_std(i) > (sigma_level * std_pose_std(i)) reliability_flag = 0; break; end end end function check_camera_projection(feature_points, isgframe) cam = initialize_cam(); features_info=[]; ros_sba_T = sr4k_p2T([0,0,0,pi/2,0,0]); camera_index_list=unique(feature_points(:,1)); for i=1:size(camera_index_list,1) camera_index = camera_index_list(i); data_index_list = find((feature_points(:,1) == camera_index & feature_points(:,3) == 1) | (feature_points(:,2) == camera_index & feature_points(:,3) == 2)); unit_data = feature_points(data_index_list,:); estimated_uv = []; for j=1:size(unit_data,1) % if i==40 % disp('debug'); % end if strcmp(isgframe, 'gframe') temp_p = [unit_data(j,4:6) 1]'; else temp_p = ros_sba_T * [unit_data(j,4:6) 1]'; end estimated_uv(j,:) = hi_cartesian_test(temp_p(1:3), [0;0;0], eye(3), cam, features_info )'; end figure; plot(estimated_uv(:,1), estimated_uv(:,2),'b+'); hold on; plot(unit_data(:,7),unit_data(:,8),'ro'); legend('Estimated','Measured'); hold off; projection_error = sqrt(sum((estimated_uv - unit_data(:,7:8)).^2,2)); projection_error_mean_std(i,:) = [mean(projection_error), std(projection_error)]; end figure; errorbar(projection_error_mean_std(:,1), projection_error_mean_std(:,2),'b'); end function check_camera_projection2(e_t_pose, e_o_pose, e_fpts, isgframe) cam = initialize_cam(); features_info=[]; ros_sba_T = sr4k_p2T([0,0,0,pi/2,0,0]); % camera_index_list=unique(feature_points(:,1)); for i=1:size(e_t_pose,1) % camera_index = camera_index_list(i); % data_index_list = find((feature_points(:,1) == camera_index & feature_points(:,3) == 1) | (feature_points(:,2) == camera_index & feature_points(:,3) == 2)); % unit_data = feature_points(data_index_list,:); temp_t = e_t_pose(i,1:3)'; if strcmp(isgframe, 'gframe') temp_R = e2R([e_o_pose(i,2),e_o_pose(i,1),e_o_pose(i,3)]'); else temp_R = euler_to_rot(e_o_pose(i,1)*180/pi,e_o_pose(i,2)*180/pi,e_o_pose(i,3)*180/pi); end %temp_R = eye(3); % T = [temp_R, temp_t; 0 0 0 1]; % T = ros_sba_T*T; % Convert Bundler frame to SBA frame. % temp_t = T(1:3,4); % temp_R = T(1:3,1:3); if iscell(e_fpts) unit_data = e_fpts{i}; else data_index_list = find(e_fpts(:,1) == i); unit_data = e_fpts(data_index_list,2:end); end estimated_uv = []; for j=1:size(unit_data,1) % if i==40 % disp('debug'); % end %temp_p = ros_sba_T * [unit_data(j,2:4) 1]'; temp_p = [unit_data(j,2:4) 1]'; %estimated_uv(j,:) = hi_cartesian_test(temp_p(1:3), [0;0;0], eye(3), cam, features_info )'; if strcmp(isgframe, 'gframe') estimated_uv(j,:) = hi_cartesian_test(temp_p(1:3), temp_t, temp_R, cam, features_info)'; else estimated_uv(j,:) = vro_camera_projection(temp_p(1:3), temp_t, temp_R, cam, features_info, ros_sba_T)'; end end figure; plot(estimated_uv(:,1), estimated_uv(:,2),'b+'); hold on; plot(unit_data(:,6),unit_data(:,7),'ro'); legend('Estimated','Measured'); hold off; projection_error = sqrt(sum((estimated_uv - unit_data(:,6:7)).^2,2)); projection_error_mean_std(i,:) = [mean(projection_error), std(projection_error)]; end figure; errorbar(projection_error_mean_std(:,1), projection_error_mean_std(:,2),'b'); end function plot_trajectory(e_pose, dynamic_index) e_pose = e_pose/1000; figure; if dynamic_index == 18 cube2m = 0.3048; % 1cube = 12 inch = 0.3048 m gt_x=[]; gt_y=[]; [px,py] = plot_arc([1*cube2m;5*cube2m],[0;5*cube2m],[1*cube2m;6*cube2m]); gt_x =[gt_x px]; gt_y =[gt_y py]; [px,py] = plot_arc([12*cube2m;5*cube2m],[12*cube2m;6*cube2m],[13*cube2m;5*cube2m]); gt_x =[gt_x px]; gt_y =[gt_y py]; [px,py] = plot_arc([12*cube2m;0],[13*cube2m;0],[12*cube2m;-1*cube2m]); gt_x =[gt_x px]; gt_y =[gt_y py]; [px,py] =plot_arc([1*cube2m;0],[1*cube2m;-1*cube2m],[0;0]); gt_x =[gt_x px gt_x(1)]; gt_y =[gt_y py gt_y(1)]; %gt_x = [0 0 1*inch2m 12*inch2m 13*inch2m 13*inch2m 12*inch2m 1*inch2m 0 ]; %gt_y = [0 5*inch2m 6*inch2m 6*inch2m 5*inch2m 0 -1*inch2m -1*inch2m 0]; % plot([0;0],[0;5*inch2m],'r-','LineWidth',2); % plot([1*inch2m;12*inch2m],[6*inch2m;6*inch2m],'r-','LineWidth',2); % plot([13*inch2m;13*inch2m],[5*inch2m;0],'r-','LineWidth',2); % plot([12*inch2m;1*inch2m],[-1*inch2m;-1*inch2m],'r-','LineWidth',2); elseif dynamic_index >= 15 && dynamic_index <= 17 gt_x = [0 0 2.135 2.135 0]; gt_y = [0 1.220 1.220 0 0]; else inch2m = 0.0254; % 1 inch = 0.0254 m gt_x = [0 0 150 910 965 965 910 50 0 0]; gt_y = [0 24 172.5 172.5 122.5 -122.5 -162.5 -162.5 -24 0]; gt_x = [gt_x 0 0 60 60+138 60+138+40 60+138+40 60+138 60 0 0]; gt_y = [gt_y 0 24 38.5+40 38.5+40 38.5 -38.5 -38.5-40 -38.5-40 -24 0]; gt_x = gt_x * inch2m; gt_y = gt_y * inch2m; end plot(e_pose(:,1),e_pose(:,2),'b-'); %hold on; %plot(gt_x,gt_y,'r-','LineWidth',2); xlabel('X [m]'); ylabel('Y [m]'); grid; %h_xlabel = get(gca,'XLabel'); %set(h_xlabel,'FontSize',12,'FontWeight','bold'); %h_ylabel = get(gca,'YLabel'); %set(h_ylabel,'FontSize',12,'FontWeight','bold'); legend('Estimated Pose','Estimated Truth'); %legend('Estimated Pose'); %xlim([-0.5 4.5]); %ylim([-18 6]); axis equal; hold off; figure; if dynamic_index == 18 inch2m = 0.3048; % 1cube = 12 inch = 0.3048 m gt_x=[]; gt_y=[]; [px,py] = plot_arc([1*inch2m;5*inch2m],[0;5*inch2m],[1*inch2m;6*inch2m]); gt_x =[gt_x px]; gt_y =[gt_y py]; [px,py] = plot_arc([12*inch2m;5*inch2m],[12*inch2m;6*inch2m],[13*inch2m;5*inch2m]); gt_x =[gt_x px]; gt_y =[gt_y py]; [px,py] = plot_arc([12*inch2m;0],[13*inch2m;0],[12*inch2m;-1*inch2m]); gt_x =[gt_x px]; gt_y =[gt_y py]; [px,py] =plot_arc([1*inch2m;0],[1*inch2m;-1*inch2m],[0;0]); gt_x =[gt_x px gt_x(1)]; gt_y =[gt_y py gt_y(1)]; gt_z =zeros(1, length(gt_x)); else gt_x = [0 0 2.135 2.135 0]; gt_y = [0 1.220 1.220 0 0]; gt_z = [0 0 0 0 0]; end plot3(e_pose(:,1),e_pose(:,2),e_pose(:,3),'b-'); %hold on; %plot3(gt_x,gt_y,gt_z,'r-','LineWidth',2); xlabel('X [m]'); ylabel('Y [m]'); zlabel('Z [m]'); grid; h_xlabel = get(gca,'XLabel'); set(h_xlabel,'FontSize',12,'FontWeight','bold'); h_ylabel = get(gca,'YLabel'); set(h_ylabel,'FontSize',12,'FontWeight','bold'); legend('Estimated Pose','Estimated Truth'); axis equal; end function [px, py] = plot_arc(P0,P1,P2) n = 50; % The number of points in the arc v1 = P1-P0; v2 = P2-P0; c = det([v1,v2]); % "cross product" of v1 and v2 a = linspace(0,atan2(abs(c),dot(v1,v2)),n); % Angle range v3 = [0,-c;c,0]*v1; % v3 lies in plane of v1 and v2 and is orthog. to v1 v = v1*cos(a)+((norm(v1)/norm(v3))*v3)*sin(a); % Arc, center at (0,0) px = v(1,:) + P0(1); py = v(2,:) + P0(2); %plot(v(1,:)+P0(1),v(2,:)+P0(2),'r-','LineWidth',2) % Plot arc, centered at P0 %hold on; %axis equal end
github
rising-turtle/slam_matlab-master
plot_graph_initial_result_v2.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot_graph_initial_result_v2.m
2,500
utf_8
5cd62b350668a961da282f46f29794f0
% Show plots of inital pose and optimized pose % % Author : Soonhac Hong ([email protected]) % History : % 3/27/14 : Created % function [location_file_index, location_info_history] = plot_graph_initial_result_v2(gtsam_pose_initial, gtsam_pose_result, location_flag, location_file_index, location_info_history, lcd_found) import gtsam.* % data_name_list = {'ODOMETRY','LANDMARK','EDGE3','VERTEX_SE3'}; keys = KeyVector(gtsam_pose_initial.keys); % isp_fd = fopen(file_name_pose, 'w'); initial_max_index = keys.size-1; for i=0:initial_max_index key = keys.at(i); x = gtsam_pose_initial.at(key); T = x.matrix(); [ry, rx, rz] = rot_to_euler(T(1:3,1:3)); plot_xyz_initial(i+1,:)=[x.x x.y x.z]; end keys = KeyVector(gtsam_pose_result.keys); initial_max_index = keys.size-1; for i=0:initial_max_index key = keys.at(i); x = gtsam_pose_result.at(key); T = x.matrix(); [ry, rx, rz] = rot_to_euler(T(1:3,1:3)); plot_xyz_result(i+1,:)=[x.x x.y x.z]; end location_info=[]; if location_flag == true && lcd_found == true [location_info, location_file_index] = generate_location_info_v2([], plot_xyz_result, location_file_index); end figure(1); subplot(1,2,2); plot(plot_xyz_result(:,1),plot_xyz_result(:,2),'r-', 'LineWidth', 2); hold on; plot(plot_xyz_result(1,1),plot_xyz_result(1,2),'ko', 'LineWidth', 3,'MarkerSize', 3); xlabel('X');ylabel('Y'); % for Amir's exp1 % xlim([-15 5]); % ylim([-5 15]); % text_offset=[1,0]; % for motive #34 % xlim([-5 1]); % ylim([-2 5]); % for swing #25 xlim([-4 2]); ylim([-3 7]); text_offset=[0.4,0]; % Display location information if ~isempty(location_info_history) for i=1:size(location_info_history,1) text_xy=[location_info_history{i,1}+text_offset(i,1),location_info_history{i,2}+text_offset(i,2)]; text(text_xy(1), text_xy(2),location_info_history(i,3),'Color',[0 0 1]); plot(location_info_history{i,1}, location_info_history{i,2},'bd', 'LineWidth', 2, 'MarkerSize', 5); end end if ~isempty(location_info) text_xy=[plot_xyz_result(end,1)+text_offset(location_file_index-1,1), plot_xyz_result(end,2)+text_offset(location_file_index-1,2)]; text(text_xy(1), text_xy(2),location_info, 'Color',[0 0 1]); location_info_history(location_file_index-1,:) ={plot_xyz_result(end,1),plot_xyz_result(end,2),location_info}; plot(plot_xyz_result(end,1), plot_xyz_result(end,2),'bd', 'LineWidth', 2, 'MarkerSize', 5); end hold off; grid; legend('PGO'); axis equal; drawnow; end
github
rising-turtle/slam_matlab-master
check_duplication_imgidx.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/check_duplication_imgidx.m
796
utf_8
80452a3215ab628743b40fc9496c2173
% Check single data duplication in data set by image index % Author : Soonhac Hong ([email protected]) % Date : 2/5/13 function [duplication_index, duplication_flag] = check_duplication_imgidx(data_set, data, imgidx_distance_threshold) duplication_index = 0; duplication_flag = 0; %distance_threshold = 41; % [mm]; typical absolute accuracy + 3 * typical repeatibility of SR4000 = 20 + 3 * 7 = 41 %imgidx_distance_threshold = 2; % 2 pixel error tolerance for i=1:size(data_set,1) imgidx_distance = sqrt(sum((data_set(i,end-1:end)-data(end-1:end)).^2)); if imgidx_distance <= imgidx_distance_threshold && imgidx_distance > 0 duplication_flag = 1; duplication_index = data_set(i,1); break; end end end
github
rising-turtle/slam_matlab-master
plot_graph_initial_result_v0.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot_graph_initial_result_v0.m
1,224
utf_8
792ffcfbb228623ba3e511993d46d083
% Show plots of inital pose and optimized pose % % Author : Soonhac Hong ([email protected]) % History : % 3/27/14 : Created % function plot_graph_initial_result_v0(gtsam_pose_initial, gtsam_pose_result) import gtsam.* % data_name_list = {'ODOMETRY','LANDMARK','EDGE3','VERTEX_SE3'}; keys = KeyVector(gtsam_pose_initial.keys); % isp_fd = fopen(file_name_pose, 'w'); initial_max_index = keys.size-1; for i=0:initial_max_index key = keys.at(i); x = gtsam_pose_initial.at(key); T = x.matrix(); [ry, rx, rz] = rot_to_euler(T(1:3,1:3)); plot_xyz_initial(i+1,:)=[x.x x.y x.z]; end keys = KeyVector(gtsam_pose_result.keys); initial_max_index = keys.size-1; for i=0:initial_max_index key = keys.at(i); x = gtsam_pose_result.at(key); T = x.matrix(); [ry, rx, rz] = rot_to_euler(T(1:3,1:3)); plot_xyz_result(i+1,:)=[x.x x.y x.z]; end figure(1); subplot(1,2,2); plot(plot_xyz_initial(:,1),plot_xyz_initial(:,2),'g-', 'LineWidth', 2); hold on; plot(plot_xyz_result(:,1),plot_xyz_result(:,2),'r-', 'LineWidth', 2); plot(plot_xyz_initial(1,1),plot_xyz_initial(1,2),'go', 'LineWidth', 3,'MarkerSize', 3); xlabel('X');ylabel('Y'); hold off; grid; legend('DR','PGO'); axis equal; drawnow; end
github
rising-turtle/slam_matlab-master
moreindatatip.m
.m
slam_matlab-master/ground_truth_zh/slamtoolbox/slamToolbox_11_09_08/Graphics/moreindatatip.m
3,133
utf_8
a282d8242a72fbe01e0564a1ef3c3d07
function moreindatatip % MOREINDATATIP Display index information in the data tip. % % Extends the displayed text of the datatip to get the index of the clicked % point. The extension remains until the figure is deleted. If datatip(s) % was previously present, a message prompts the user to right-click on the % figure to delete all datatips in order to switch on the capabilities of % the datatip. % % may 2006 % [email protected] dcm_obj = datacursormode(gcf); if ~isempty(findall(gca,'type','hggroup','marker','square'))% if there is datatip, please delete it info_struct = getCursorInfo(dcm_obj); xdat=get(info_struct.Target,'xdata'); ydat=get(info_struct.Target,'ydata'); zdat=get(info_struct.Target,'zdata'); if isempty(zdat),zdat=zeros(size(xdat));set(info_struct.Target,'zdata',zdat),end index=info_struct.DataIndex; ht=text(xdat(index)*1.05,ydat(index)*1.05,zdat(index)*1.05,... {'right-click on the figure';'to ''delete all datatips''';'in order to get more'},... 'backgroundcolor',[1,0,0.5],'tag','attention'); end set(dcm_obj,'enable','on','updatefcn',@myupdatefcn,'displaystyle','datatip') %-------------------------------------------------------------------------% function txt = myupdatefcn(empt,event_obj) % Change the text displayed in the datatip. Note than the actual coordinates % are displyed rather the position field of the info_struct. ht=findobj('tag','attention'); if ~isempty(ht),delete(ht),end dcm_obj = datacursormode(gcf); info_struct = getCursorInfo(dcm_obj); xdat=get(info_struct.Target,'xdata'); ydat=get(info_struct.Target,'ydata'); zdat=get(info_struct.Target,'zdata'); index=info_struct.DataIndex; if isempty(zdat) txt = {['X: ',num2str(xdat(index))],... ['Y: ',num2str(ydat(index))],... ['index: ',num2str(index)]}; else txt = {['X: ',num2str(xdat(index))],... ['Y: ',num2str(ydat(index))],... ['Z: ',num2str(zdat(index))],... ['index: ',num2str(index)]}; end % ========== End of function - Start GPL license ========== % # START GPL LICENSE %--------------------------------------------------------------------- % % This file is part of SLAMTB, a SLAM toolbox for Matlab. % % SLAMTB is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % SLAMTB is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with SLAMTB. If not, see <http://www.gnu.org/licenses/>. % %--------------------------------------------------------------------- % SLAMTB is Copyright 2007,2008,2009 % by Joan Sola, David Marquez and Jean Marie Codol @ LAAS-CNRS. % See on top of this file for its particular copyright. % # END GPL LICENSE
github
rising-turtle/slam_matlab-master
initNewLmk.m
.m
slam_matlab-master/ground_truth_zh/slamtoolbox/slamToolbox_11_09_08/InterfaceLevel/initNewLmk.m
6,870
utf_8
34d7ff329dfed725430c53a5095f1ecf
function [Lmk,Obs] = initNewLmk(Rob, Sen, Raw, Lmk, Obs, Opt) %INITNEWLMK Initialise one landmark. % [LMK, OBS] = INITNEWLMK(ROB, SEN, RAW, LMK, OBS) returns the new % set of landmarks. % % This "new set" contains the "old set" plus new elements. These new % elements are extracted from the recent observations (RAW), from the % current state estimated (ROB for robot and SEN for the sensor). % % Finally, we can have a mean and a variance-covariance estimation for % the new landmark state. % % See also GETNEWLMKCOVS % Copyright 2009 Jean Marie Codol, David Marquez @ LAAS-CNRS % 0. UPDATE ROB AND SEN INFO FROM MAP Rob = map2rob(Rob); Sen = map2sen(Sen); % Type of the lmk to initialize - with error check. switch Opt.init.initType case {'hmgPnt'} lmkSize = 4; case {'ahmPnt'} lmkSize = 7; case {'idpPnt','plkLin'} lmkSize = 6; case {'idpLin','aplLin'} lmkSize = 9; case {'hmgLin'} lmkSize = 8; case {'fhmPnt','ahmLin'} lmkSize = 11; case {'eucPnt'} error('??? Unable to initialize lmk type ''%s''. Try using ''idpPnt'' instead.',Opt.init.initType); otherwise error('??? Unknown landmark type ''%s''.', Opt.init.initType); end % get free space in the Map. r = newRange(lmkSize); % index to first free lmk lmk = newLmk(Lmk); if (numel(r) < lmkSize) % disp('!!! Map full. Unable to initialize landmark.') return end if isempty(lmk) % disp('!!! Lmk structure array full. Unable to initialize new landmark.') return; end % Feature detection switch Raw.type case {'simu'} [newId, app, meas, exp, inn] = simDetectFeat(... Opt.init.initType, ... [Lmk([Lmk.used]).id], ... Raw.data, ... Sen.par.pixCov, ... Sen.par.imSize); case {'real'} existingProj = getExistingProj(Obs); [app, meas, exp, inn] = detectFeat(... Opt.init.initType, ... Raw.data, ... Sen.par.pixCov, ... existingProj, ... Sen.imGrid); newId = getNewId(); % NYI : Not Yet Implemented %[newId, app, meas, exp, inn] = detectFeat([Lmk(usedLmks).id],Raw.data,Sen.par); % error('??? Unknown Raw type. ''real'': NYI.'); end if ~isempty(meas.y) % a feature was detected --> initialize it % fill Obs struct before continuing Obs(lmk).sen = Sen.sen; Obs(lmk).lmk = lmk; Obs(lmk).sid = Sen.id; Obs(lmk).lid = newId; Obs(lmk).stype = Sen.type; Obs(lmk).ltype = Opt.init.initType; Obs(lmk).meas = meas; Obs(lmk).exp = exp; Obs(lmk).exp.um = det(inn.Z); % uncertainty measure Obs(lmk).inn = inn; Obs(lmk).app.curr = app; Obs(lmk).app.pred = app; Obs(lmk).vis = true; Obs(lmk).measured = true; Obs(lmk).matched = true; Obs(lmk).updated = true; % retro-project feature onto 3D space [l, L_rf, L_sf, L_obs, L_n, N] = retroProjLmk(Rob,Sen,Obs(lmk),Opt); % get new Lmk, covariance and cross-variance. [P_LL,P_LX] = getNewLmkCovs( ... Sen.frameInMap, ... Rob.frame.r, ... Sen.frame.r, ... L_rf, ... L_sf, ... L_obs, ... L_n, ... meas.R, ... N) ; % add to Map and get lmk range in Map Lmk(lmk).state.r = addToMap(l,P_LL,P_LX); % Fill Lmk structure Lmk(lmk).lmk = lmk; Lmk(lmk).id = newId; Lmk(lmk).type = Opt.init.initType ; Lmk(lmk).used = true; Lmk(lmk).sig = app; Lmk(lmk).nSearch = 1; Lmk(lmk).nMatch = 1; Lmk(lmk).nInlier = 1; % Init off-filter landmark params [Lmk(lmk),Obs(lmk)] = initLmkParams(Rob,Sen,Lmk(lmk),Obs(lmk)); % fprintf('Initialized landmark ''%d''.\n',Lmk(lmk).id) end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [P_LL,P_LX] = getNewLmkCovs(SenFrameInMap, RobFrameR, SenFrameR,... L_rf, L_sf, L_obs, L_n, R, N) % GETNEWLMKCOVS return lmk co and cross-variance for initialization. % [P_LL,P_LX] = GETNEWLMKCOVS( ... % SENFRAMEINMAP, ... % ROBFRAMERANGE, ... % SENFRAMERANGE, ... % L_RF, ... % L_SF, ... % L_OBS, ... % L_N, ... % R, ... % N) % % Return the covariance 'Lmk/Lmk' (P_LL) and cross-variance 'Lmk/Map.used' % (P_LX) given : % - if the sensor frame is in map (SENFRAMEINMAP). % - the robot frame range in map (ROBFRAMERANGE). % - the sensor frame range in map (SENFRAMERANGE). % - the jacobian 'Lmk/robot frame' (L_RF). % - the jacobian 'Lmk/sensor frame' (L_SF). % - the jacobian 'Lmk/observation' (L_OBS). % - the jacobian 'Lmk/non observable part' (L_N). % - the observation covariance (R). % - the observation non observable part covariance (N). % % P_LL and P_LX can be placed for example in Map covariance like: % % P = | P P_LX' | % | P_LX P_LL | % % (c) 2009 Jean Marie Codol, David Marquez @ LAAS-CNRS global Map % Group all map Jacobians and ranges if SenFrameInMap % if the sensor frame is in the state mr = [RobFrameR;SenFrameR]; L_m = [L_rf L_sf] ; else mr = RobFrameR; L_m = L_rf ; end % co- and cross-variance of map variables (robot and eventually sensor) P_MM = Map.P(mr,mr) ; P_MX = Map.P(mr,(Map.used)) ; % landmark co- and cross-variance P_LL = ... L_m * P_MM * L_m' + ... % by map cov L_obs * R * L_obs' + ... % by observation cov (for pinHole it is a pixel) L_n * N * L_n' ; % by nom cov P_LX = L_m*P_MX ; end % ========== End of function - Start GPL license ========== % # START GPL LICENSE %--------------------------------------------------------------------- % % This file is part of SLAMTB, a SLAM toolbox for Matlab. % % SLAMTB is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % SLAMTB is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with SLAMTB. If not, see <http://www.gnu.org/licenses/>. % %--------------------------------------------------------------------- % SLAMTB is Copyright 2007,2008,2009 % by Joan Sola, David Marquez and Jean Marie Codol @ LAAS-CNRS. % See on top of this file for its particular copyright. % # END GPL LICENSE
github
rising-turtle/slam_matlab-master
chi2.m
.m
slam_matlab-master/ground_truth_zh/slamtoolbox/slamToolbox_11_09_08/Math/chi2.m
25,797
utf_8
28d82af99c6ba03eec54f93ee2d67f95
function chi2 = chi2(n,p) % CHI2 Chi square distribution % TH = CHI2(N,P) gives the critical values of the N-dimensional % Chi-squared distribuiton function for a right-tail probability area P % Copyright 2009 Joan Sola @ LAAS-CNRS. [nTab,pTab,Chi2Tab] = chi2tab(); if (n == floor(n)) % values of p if p < .001 warning('Too small probability. Assuming P=0.001') p = 0.001; elseif (p > 0.2) && (p<0.975) && (p~=0.5) warning('Poor data in table. Inaccurate results. Use P<0.2 or P>0.975.') elseif p > 0.995 warning('Too big probability. Assuming P=0.995') p = 0.995; end % values of n if (n > 1000) error('Chi2 Lookup table only up to N=1000 DOF') elseif (n > 250) && (mod(n,50)~=0) warning('Value of N-DOF not found. Innacurate results. Use N in [1:1:250,300:50:1000]') end % 2-D interpolation chi2 = interp2(pTab,nTab,Chi2Tab,p,n); else error('Dimension N must be a positive integer value in [1:1000]') end end %% Lookup tables function [DOF,PRB,TAB] = chi2tab() PRB = [0.995 0.975 0.20 0.10 0.05 0.025 0.02 0.01 0.005 0.002 0.001]; DOF = [1:250 300:50:1000]; TAB = [... 1 0.0000393 0.000982 1.642 2.706 3.841 5.024 5.412 6.635 7.879 9.550 10.828 2 0.0100 0.0506 3.219 4.605 5.991 7.378 7.824 9.210 10.597 12.429 13.816 3 0.0717 0.216 4.642 6.251 7.815 9.348 9.837 11.345 12.838 14.796 16.266 4 0.207 0.484 5.989 7.779 9.488 11.143 11.668 13.277 14.860 16.924 18.467 5 0.412 0.831 7.289 9.236 11.070 12.833 13.388 15.086 16.750 18.907 20.515 6 0.676 1.237 8.558 10.645 12.592 14.449 15.033 16.812 18.548 20.791 22.458 7 0.989 1.690 9.803 12.017 14.067 16.013 16.622 18.475 20.278 22.601 24.322 8 1.344 2.180 11.030 13.362 15.507 17.535 18.168 20.090 21.955 24.352 26.124 9 1.735 2.700 12.242 14.684 16.919 19.023 19.679 21.666 23.589 26.056 27.877 10 2.156 3.247 13.442 15.987 18.307 20.483 21.161 23.209 25.188 27.722 29.588 11 2.603 3.816 14.631 17.275 19.675 21.920 22.618 24.725 26.757 29.354 31.264 12 3.074 4.404 15.812 18.549 21.026 23.337 24.054 26.217 28.300 30.957 32.909 13 3.565 5.009 16.985 19.812 22.362 24.736 25.472 27.688 29.819 32.535 34.528 14 4.075 5.629 18.151 21.064 23.685 26.119 26.873 29.141 31.319 34.091 36.123 15 4.601 6.262 19.311 22.307 24.996 27.488 28.259 30.578 32.801 35.628 37.697 16 5.142 6.908 20.465 23.542 26.296 28.845 29.633 32.000 34.267 37.146 39.252 17 5.697 7.564 21.615 24.769 27.587 30.191 30.995 33.409 35.718 38.648 40.790 18 6.265 8.231 22.760 25.989 28.869 31.526 32.346 34.805 37.156 40.136 42.312 19 6.844 8.907 23.900 27.204 30.144 32.852 33.687 36.191 38.582 41.610 43.820 20 7.434 9.591 25.038 28.412 31.410 34.170 35.020 37.566 39.997 43.072 45.315 21 8.034 10.283 26.171 29.615 32.671 35.479 36.343 38.932 41.401 44.522 46.797 22 8.643 10.982 27.301 30.813 33.924 36.781 37.659 40.289 42.796 45.962 48.268 23 9.260 11.689 28.429 32.007 35.172 38.076 38.968 41.638 44.181 47.391 49.728 24 9.886 12.401 29.553 33.196 36.415 39.364 40.270 42.980 45.559 48.812 51.179 25 10.520 13.120 30.675 34.382 37.652 40.646 41.566 44.314 46.928 50.223 52.620 26 11.160 13.844 31.795 35.563 38.885 41.923 42.856 45.642 48.290 51.627 54.052 27 11.808 14.573 32.912 36.741 40.113 43.195 44.140 46.963 49.645 53.023 55.476 28 12.461 15.308 34.027 37.916 41.337 44.461 45.419 48.278 50.993 54.411 56.892 29 13.121 16.047 35.139 39.087 42.557 45.722 46.693 49.588 52.336 55.792 58.301 30 13.787 16.791 36.250 40.256 43.773 46.979 47.962 50.892 53.672 57.167 59.703 31 14.458 17.539 37.359 41.422 44.985 48.232 49.226 52.191 55.003 58.536 61.098 32 15.134 18.291 38.466 42.585 46.194 49.480 50.487 53.486 56.328 59.899 62.487 33 15.815 19.047 39.572 43.745 47.400 50.725 51.743 54.776 57.648 61.256 63.870 34 16.501 19.806 40.676 44.903 48.602 51.966 52.995 56.061 58.964 62.608 65.247 35 17.192 20.569 41.778 46.059 49.802 53.203 54.244 57.342 60.275 63.955 66.619 36 17.887 21.336 42.879 47.212 50.998 54.437 55.489 58.619 61.581 65.296 67.985 37 18.586 22.106 43.978 48.363 52.192 55.668 56.730 59.893 62.883 66.633 69.346 38 19.289 22.878 45.076 49.513 53.384 56.896 57.969 61.162 64.181 67.966 70.703 39 19.996 23.654 46.173 50.660 54.572 58.120 59.204 62.428 65.476 69.294 72.055 40 20.707 24.433 47.269 51.805 55.758 59.342 60.436 63.691 66.766 70.618 73.402 41 21.421 25.215 48.363 52.949 56.942 60.561 61.665 64.950 68.053 71.938 74.745 42 22.138 25.999 49.456 54.090 58.124 61.777 62.892 66.206 69.336 73.254 76.084 43 22.859 26.785 50.548 55.230 59.304 62.990 64.116 67.459 70.616 74.566 77.419 44 23.584 27.575 51.639 56.369 60.481 64.201 65.337 68.710 71.893 75.874 78.750 45 24.311 28.366 52.729 57.505 61.656 65.410 66.555 69.957 73.166 77.179 80.077 46 25.041 29.160 53.818 58.641 62.830 66.617 67.771 71.201 74.437 78.481 81.400 47 25.775 29.956 54.906 59.774 64.001 67.821 68.985 72.443 75.704 79.780 82.720 48 26.511 30.755 55.993 60.907 65.171 69.023 70.197 73.683 76.969 81.075 84.037 49 27.249 31.555 57.079 62.038 66.339 70.222 71.406 74.919 78.231 82.367 85.351 50 27.991 32.357 58.164 63.167 67.505 71.420 72.613 76.154 79.490 83.657 86.661 51 28.735 33.162 59.248 64.295 68.669 72.616 73.818 77.386 80.747 84.943 87.968 52 29.481 33.968 60.332 65.422 69.832 73.810 75.021 78.616 82.001 86.227 89.272 53 30.230 34.776 61.414 66.548 70.993 75.002 76.223 79.843 83.253 87.507 90.573 54 30.981 35.586 62.496 67.673 72.153 76.192 77.422 81.069 84.502 88.786 91.872 55 31.735 36.398 63.577 68.796 73.311 77.380 78.619 82.292 85.749 90.061 93.168 56 32.490 37.212 64.658 69.919 74.468 78.567 79.815 83.513 86.994 91.335 94.461 57 33.248 38.027 65.737 71.040 75.624 79.752 81.009 84.733 88.236 92.605 95.751 58 34.008 38.844 66.816 72.160 76.778 80.936 82.201 85.950 89.477 93.874 97.039 59 34.770 39.662 67.894 73.279 77.931 82.117 83.391 87.166 90.715 95.140 98.324 60 35.534 40.482 68.972 74.397 79.082 83.298 84.580 88.379 91.952 96.404 99.607 61 36.301 41.303 70.049 75.514 80.232 84.476 85.767 89.591 93.186 97.665 100.888 62 37.068 42.126 71.125 76.630 81.381 85.654 86.953 90.802 94.419 98.925 102.166 63 37.838 42.950 72.201 77.745 82.529 86.830 88.137 92.010 95.649 100.182 103.442 64 38.610 43.776 73.276 78.860 83.675 88.004 89.320 93.217 96.878 101.437 104.716 65 39.383 44.603 74.351 79.973 84.821 89.177 90.501 94.422 98.105 102.691 105.988 66 40.158 45.431 75.424 81.085 85.965 90.349 91.681 95.626 99.330 103.942 107.258 67 40.935 46.261 76.498 82.197 87.108 91.519 92.860 96.828 100.554 105.192 108.526 68 41.713 47.092 77.571 83.308 88.250 92.689 94.037 98.028 101.776 106.440 109.791 69 42.494 47.924 78.643 84.418 89.391 93.856 95.213 99.228 102.996 107.685 111.055 70 43.275 48.758 79.715 85.527 90.531 95.023 96.388 100.425 104.215 108.929 112.317 71 44.058 49.592 80.786 86.635 91.670 96.189 97.561 101.621 105.432 110.172 113.577 72 44.843 50.428 81.857 87.743 92.808 97.353 98.733 102.816 106.648 111.412 114.835 73 45.629 51.265 82.927 88.850 93.945 98.516 99.904 104.010 107.862 112.651 116.092 74 46.417 52.103 83.997 89.956 95.081 99.678 101.074 105.202 109.074 113.889 117.346 75 47.206 52.942 85.066 91.061 96.217 100.839 102.243 106.393 110.286 115.125 118.599 76 47.997 53.782 86.135 92.166 97.351 101.999 103.410 107.583 111.495 116.359 119.850 77 48.788 54.623 87.203 93.270 98.484 103.158 104.576 108.771 112.704 117.591 121.100 78 49.582 55.466 88.271 94.374 99.617 104.316 105.742 109.958 113.911 118.823 122.348 79 50.376 56.309 89.338 95.476 100.749 105.473 106.906 111.144 115.117 120.052 123.594 80 51.172 57.153 90.405 96.578 101.879 106.629 108.069 112.329 116.321 121.280 124.839 81 51.969 57.998 91.472 97.680 103.010 107.783 109.232 113.512 117.524 122.507 126.083 82 52.767 58.845 92.538 98.780 104.139 108.937 110.393 114.695 118.726 123.733 127.324 83 53.567 59.692 93.604 99.880 105.267 110.090 111.553 115.876 119.927 124.957 128.565 84 54.368 60.540 94.669 100.980 106.395 111.242 112.712 117.057 121.126 126.179 129.804 85 55.170 61.389 95.734 102.079 107.522 112.393 113.871 118.236 122.325 127.401 131.041 86 55.973 62.239 96.799 103.177 108.648 113.544 115.028 119.414 123.522 128.621 132.277 87 56.777 63.089 97.863 104.275 109.773 114.693 116.184 120.591 124.718 129.840 133.512 88 57.582 63.941 98.927 105.372 110.898 115.841 117.340 121.767 125.913 131.057 134.745 89 58.389 64.793 99.991 106.469 112.022 116.989 118.495 122.942 127.106 132.273 135.978 90 59.196 65.647 101.054 107.565 113.145 118.136 119.648 124.116 128.299 133.489 137.208 91 60.005 66.501 102.117 108.661 114.268 119.282 120.801 125.289 129.491 134.702 138.438 92 60.815 67.356 103.179 109.756 115.390 120.427 121.954 126.462 130.681 135.915 139.666 93 61.625 68.211 104.241 110.850 116.511 121.571 123.105 127.633 131.871 137.127 140.893 94 62.437 69.068 105.303 111.944 117.632 122.715 124.255 128.803 133.059 138.337 142.119 95 63.250 69.925 106.364 113.038 118.752 123.858 125.405 129.973 134.247 139.546 143.344 96 64.063 70.783 107.425 114.131 119.871 125.000 126.554 131.141 135.433 140.755 144.567 97 64.878 71.642 108.486 115.223 120.990 126.141 127.702 132.309 136.619 141.962 145.789 98 65.694 72.501 109.547 116.315 122.108 127.282 128.849 133.476 137.803 143.168 147.010 99 66.510 73.361 110.607 117.407 123.225 128.422 129.996 134.642 138.987 144.373 148.230 100 67.328 74.222 111.667 118.498 124.342 129.561 131.142 135.807 140.169 145.577 149.449 101 68.146 75.083 112.726 119.589 125.458 130.700 132.287 136.971 141.351 146.780 150.667 102 68.965 75.946 113.786 120.679 126.574 131.838 133.431 138.134 142.532 147.982 151.884 103 69.785 76.809 114.845 121.769 127.689 132.975 134.575 139.297 143.712 149.183 153.099 104 70.606 77.672 115.903 122.858 128.804 134.111 135.718 140.459 144.891 150.383 154.314 105 71.428 78.536 116.962 123.947 129.918 135.247 136.860 141.620 146.070 151.582 155.528 106 72.251 79.401 118.020 125.035 131.031 136.382 138.002 142.780 147.247 152.780 156.740 107 73.075 80.267 119.078 126.123 132.144 137.517 139.143 143.940 148.424 153.977 157.952 108 73.899 81.133 120.135 127.211 133.257 138.651 140.283 145.099 149.599 155.173 159.162 109 74.724 82.000 121.192 128.298 134.369 139.784 141.423 146.257 150.774 156.369 160.372 110 75.550 82.867 122.250 129.385 135.480 140.917 142.562 147.414 151.948 157.563 161.581 111 76.377 83.735 123.306 130.472 136.591 142.049 143.700 148.571 153.122 158.757 162.788 112 77.204 84.604 124.363 131.558 137.701 143.180 144.838 149.727 154.294 159.950 163.995 113 78.033 85.473 125.419 132.643 138.811 144.311 145.975 150.882 155.466 161.141 165.201 114 78.862 86.342 126.475 133.729 139.921 145.441 147.111 152.037 156.637 162.332 166.406 115 79.692 87.213 127.531 134.813 141.030 146.571 148.247 153.191 157.808 163.523 167.610 116 80.522 88.084 128.587 135.898 142.138 147.700 149.383 154.344 158.977 164.712 168.813 117 81.353 88.955 129.642 136.982 143.246 148.829 150.517 155.496 160.146 165.900 170.016 118 82.185 89.827 130.697 138.066 144.354 149.957 151.652 156.648 161.314 167.088 171.217 119 83.018 90.700 131.752 139.149 145.461 151.084 152.785 157.800 162.481 168.275 172.418 120 83.852 91.573 132.806 140.233 146.567 152.211 153.918 158.950 163.648 169.461 173.617 121 84.686 92.446 133.861 141.315 147.674 153.338 155.051 160.100 164.814 170.647 174.816 122 85.520 93.320 134.915 142.398 148.779 154.464 156.183 161.250 165.980 171.831 176.014 123 86.356 94.195 135.969 143.480 149.885 155.589 157.314 162.398 167.144 173.015 177.212 124 87.192 95.070 137.022 144.562 150.989 156.714 158.445 163.546 168.308 174.198 178.408 125 88.029 95.946 138.076 145.643 152.094 157.839 159.575 164.694 169.471 175.380 179.604 126 88.866 96.822 139.129 146.724 153.198 158.962 160.705 165.841 170.634 176.562 180.799 127 89.704 97.698 140.182 147.805 154.302 160.086 161.834 166.987 171.796 177.743 181.993 128 90.543 98.576 141.235 148.885 155.405 161.209 162.963 168.133 172.957 178.923 183.186 129 91.382 99.453 142.288 149.965 156.508 162.331 164.091 169.278 174.118 180.103 184.379 130 92.222 100.331 143.340 151.045 157.610 163.453 165.219 170.423 175.278 181.282 185.571 131 93.063 101.210 144.392 152.125 158.712 164.575 166.346 171.567 176.438 182.460 186.762 132 93.904 102.089 145.444 153.204 159.814 165.696 167.473 172.711 177.597 183.637 187.953 133 94.746 102.968 146.496 154.283 160.915 166.816 168.600 173.854 178.755 184.814 189.142 134 95.588 103.848 147.548 155.361 162.016 167.936 169.725 174.996 179.913 185.990 190.331 135 96.431 104.729 148.599 156.440 163.116 169.056 170.851 176.138 181.070 187.165 191.520 136 97.275 105.609 149.651 157.518 164.216 170.175 171.976 177.280 182.226 188.340 192.707 137 98.119 106.491 150.702 158.595 165.316 171.294 173.100 178.421 183.382 189.514 193.894 138 98.964 107.372 151.753 159.673 166.415 172.412 174.224 179.561 184.538 190.688 195.080 139 99.809 108.254 152.803 160.750 167.514 173.530 175.348 180.701 185.693 191.861 196.266 140 100.655 109.137 153.854 161.827 168.613 174.648 176.471 181.840 186.847 193.033 197.451 141 101.501 110.020 154.904 162.904 169.711 175.765 177.594 182.979 188.001 194.205 198.635 142 102.348 110.903 155.954 163.980 170.809 176.882 178.716 184.118 189.154 195.376 199.819 143 103.196 111.787 157.004 165.056 171.907 177.998 179.838 185.256 190.306 196.546 201.002 144 104.044 112.671 158.054 166.132 173.004 179.114 180.959 186.393 191.458 197.716 202.184 145 104.892 113.556 159.104 167.207 174.101 180.229 182.080 187.530 192.610 198.885 203.366 146 105.741 114.441 160.153 168.283 175.198 181.344 183.200 188.666 193.761 200.054 204.547 147 106.591 115.326 161.202 169.358 176.294 182.459 184.321 189.802 194.912 201.222 205.727 148 107.441 116.212 162.251 170.432 177.390 183.573 185.440 190.938 196.062 202.390 206.907 149 108.291 117.098 163.300 171.507 178.485 184.687 186.560 192.073 197.211 203.557 208.086 150 109.142 117.985 164.349 172.581 179.581 185.800 187.678 193.208 198.360 204.723 209.265 151 109.994 118.871 165.398 173.655 180.676 186.914 188.797 194.342 199.509 205.889 210.443 152 110.846 119.759 166.446 174.729 181.770 188.026 189.915 195.476 200.657 207.054 211.620 153 111.698 120.646 167.495 175.803 182.865 189.139 191.033 196.609 201.804 208.219 212.797 154 112.551 121.534 168.543 176.876 183.959 190.251 192.150 197.742 202.951 209.383 213.973 155 113.405 122.423 169.591 177.949 185.052 191.362 193.267 198.874 204.098 210.547 215.149 156 114.259 123.312 170.639 179.022 186.146 192.474 194.384 200.006 205.244 211.710 216.324 157 115.113 124.201 171.686 180.094 187.239 193.584 195.500 201.138 206.390 212.873 217.499 158 115.968 125.090 172.734 181.167 188.332 194.695 196.616 202.269 207.535 214.035 218.673 159 116.823 125.980 173.781 182.239 189.424 195.805 197.731 203.400 208.680 215.197 219.846 160 117.679 126.870 174.828 183.311 190.516 196.915 198.846 204.530 209.824 216.358 221.019 161 118.536 127.761 175.875 184.382 191.608 198.025 199.961 205.660 210.968 217.518 222.191 162 119.392 128.651 176.922 185.454 192.700 199.134 201.076 206.790 212.111 218.678 223.363 163 120.249 129.543 177.969 186.525 193.791 200.243 202.190 207.919 213.254 219.838 224.535 164 121.107 130.434 179.016 187.596 194.883 201.351 203.303 209.047 214.396 220.997 225.705 165 121.965 131.326 180.062 188.667 195.973 202.459 204.417 210.176 215.539 222.156 226.876 166 122.823 132.218 181.109 189.737 197.064 203.567 205.530 211.304 216.680 223.314 228.045 167 123.682 133.111 182.155 190.808 198.154 204.675 206.642 212.431 217.821 224.472 229.215 168 124.541 134.003 183.201 191.878 199.244 205.782 207.755 213.558 218.962 225.629 230.383 169 125.401 134.897 184.247 192.948 200.334 206.889 208.867 214.685 220.102 226.786 231.552 170 126.261 135.790 185.293 194.017 201.423 207.995 209.978 215.812 221.242 227.942 232.719 171 127.122 136.684 186.338 195.087 202.513 209.102 211.090 216.938 222.382 229.098 233.887 172 127.983 137.578 187.384 196.156 203.602 210.208 212.201 218.063 223.521 230.253 235.053 173 128.844 138.472 188.429 197.225 204.690 211.313 213.311 219.189 224.660 231.408 236.220 174 129.706 139.367 189.475 198.294 205.779 212.419 214.422 220.314 225.798 232.563 237.385 175 130.568 140.262 190.520 199.363 206.867 213.524 215.532 221.438 226.936 233.717 238.551 176 131.430 141.157 191.565 200.432 207.955 214.628 216.641 222.563 228.074 234.870 239.716 177 132.293 142.053 192.610 201.500 209.042 215.733 217.751 223.687 229.211 236.023 240.880 178 133.157 142.949 193.654 202.568 210.130 216.837 218.860 224.810 230.347 237.176 242.044 179 134.020 143.845 194.699 203.636 211.217 217.941 219.969 225.933 231.484 238.328 243.207 180 134.884 144.741 195.743 204.704 212.304 219.044 221.077 227.056 232.620 239.480 244.370 181 135.749 145.638 196.788 205.771 213.391 220.148 222.185 228.179 233.755 240.632 245.533 182 136.614 146.535 197.832 206.839 214.477 221.251 223.293 229.301 234.891 241.783 246.695 183 137.479 147.432 198.876 207.906 215.563 222.353 224.401 230.423 236.026 242.933 247.857 184 138.344 148.330 199.920 208.973 216.649 223.456 225.508 231.544 237.160 244.084 249.018 185 139.210 149.228 200.964 210.040 217.735 224.558 226.615 232.665 238.294 245.234 250.179 186 140.077 150.126 202.008 211.106 218.820 225.660 227.722 233.786 239.428 246.383 251.339 187 140.943 151.024 203.052 212.173 219.906 226.761 228.828 234.907 240.561 247.532 252.499 188 141.810 151.923 204.095 213.239 220.991 227.863 229.935 236.027 241.694 248.681 253.659 189 142.678 152.822 205.139 214.305 222.076 228.964 231.040 237.147 242.827 249.829 254.818 190 143.545 153.721 206.182 215.371 223.160 230.064 232.146 238.266 243.959 250.977 255.976 191 144.413 154.621 207.225 216.437 224.245 231.165 233.251 239.386 245.091 252.124 257.135 192 145.282 155.521 208.268 217.502 225.329 232.265 234.356 240.505 246.223 253.271 258.292 193 146.150 156.421 209.311 218.568 226.413 233.365 235.461 241.623 247.354 254.418 259.450 194 147.020 157.321 210.354 219.633 227.496 234.465 236.566 242.742 248.485 255.564 260.607 195 147.889 158.221 211.397 220.698 228.580 235.564 237.670 243.860 249.616 256.710 261.763 196 148.759 159.122 212.439 221.763 229.663 236.664 238.774 244.977 250.746 257.855 262.920 197 149.629 160.023 213.482 222.828 230.746 237.763 239.877 246.095 251.876 259.001 264.075 198 150.499 160.925 214.524 223.892 231.829 238.861 240.981 247.212 253.006 260.145 265.231 199 151.370 161.826 215.567 224.957 232.912 239.960 242.084 248.329 254.135 261.290 266.386 200 152.241 162.728 216.609 226.021 233.994 241.058 243.187 249.445 255.264 262.434 267.541 201 153.112 163.630 217.651 227.085 235.077 242.156 244.290 250.561 256.393 263.578 268.695 202 153.984 164.532 218.693 228.149 236.159 243.254 245.392 251.677 257.521 264.721 269.849 203 154.856 165.435 219.735 229.213 237.240 244.351 246.494 252.793 258.649 265.864 271.002 204 155.728 166.338 220.777 230.276 238.322 245.448 247.596 253.908 259.777 267.007 272.155 205 156.601 167.241 221.818 231.340 239.403 246.545 248.698 255.023 260.904 268.149 273.308 206 157.474 168.144 222.860 232.403 240.485 247.642 249.799 256.138 262.031 269.291 274.460 207 158.347 169.047 223.901 233.466 241.566 248.739 250.900 257.253 263.158 270.432 275.612 208 159.221 169.951 224.943 234.529 242.647 249.835 252.001 258.367 264.285 271.574 276.764 209 160.095 170.855 225.984 235.592 243.727 250.931 253.102 259.481 265.411 272.715 277.915 210 160.969 171.759 227.025 236.655 244.808 252.027 254.202 260.595 266.537 273.855 279.066 211 161.843 172.664 228.066 237.717 245.888 253.122 255.302 261.708 267.662 274.995 280.217 212 162.718 173.568 229.107 238.780 246.968 254.218 256.402 262.821 268.788 276.135 281.367 213 163.593 174.473 230.148 239.842 248.048 255.313 257.502 263.934 269.912 277.275 282.517 214 164.469 175.378 231.189 240.904 249.128 256.408 258.601 265.047 271.037 278.414 283.666 215 165.344 176.283 232.230 241.966 250.207 257.503 259.701 266.159 272.162 279.553 284.815 216 166.220 177.189 233.270 243.028 251.286 258.597 260.800 267.271 273.286 280.692 285.964 217 167.096 178.095 234.311 244.090 252.365 259.691 261.898 268.383 274.409 281.830 287.112 218 167.973 179.001 235.351 245.151 253.444 260.785 262.997 269.495 275.533 282.968 288.261 219 168.850 179.907 236.391 246.213 254.523 261.879 264.095 270.606 276.656 284.106 289.408 220 169.727 180.813 237.432 247.274 255.602 262.973 265.193 271.717 277.779 285.243 290.556 221 170.604 181.720 238.472 248.335 256.680 264.066 266.291 272.828 278.902 286.380 291.703 222 171.482 182.627 239.512 249.396 257.758 265.159 267.389 273.939 280.024 287.517 292.850 223 172.360 183.534 240.552 250.457 258.837 266.252 268.486 275.049 281.146 288.653 293.996 224 173.238 184.441 241.592 251.517 259.914 267.345 269.584 276.159 282.268 289.789 295.142 225 174.116 185.348 242.631 252.578 260.992 268.438 270.681 277.269 283.390 290.925 296.288 226 174.995 186.256 243.671 253.638 262.070 269.530 271.777 278.379 284.511 292.061 297.433 227 175.874 187.164 244.711 254.699 263.147 270.622 272.874 279.488 285.632 293.196 298.579 228 176.753 188.072 245.750 255.759 264.224 271.714 273.970 280.597 286.753 294.331 299.723 229 177.633 188.980 246.790 256.819 265.301 272.806 275.066 281.706 287.874 295.465 300.868 230 178.512 189.889 247.829 257.879 266.378 273.898 276.162 282.814 288.994 296.600 302.012 231 179.392 190.797 248.868 258.939 267.455 274.989 277.258 283.923 290.114 297.734 303.156 232 180.273 191.706 249.908 259.998 268.531 276.080 278.354 285.031 291.234 298.867 304.299 233 181.153 192.615 250.947 261.058 269.608 277.171 279.449 286.139 292.353 300.001 305.443 234 182.034 193.524 251.986 262.117 270.684 278.262 280.544 287.247 293.472 301.134 306.586 235 182.915 194.434 253.025 263.176 271.760 279.352 281.639 288.354 294.591 302.267 307.728 236 183.796 195.343 254.063 264.235 272.836 280.443 282.734 289.461 295.710 303.400 308.871 237 184.678 196.253 255.102 265.294 273.911 281.533 283.828 290.568 296.828 304.532 310.013 238 185.560 197.163 256.141 266.353 274.987 282.623 284.922 291.675 297.947 305.664 311.154 239 186.442 198.073 257.179 267.412 276.062 283.713 286.016 292.782 299.065 306.796 312.296 240 187.324 198.984 258.218 268.471 277.138 284.802 287.110 293.888 300.182 307.927 313.437 241 188.207 199.894 259.256 269.529 278.213 285.892 288.204 294.994 301.300 309.058 314.578 242 189.090 200.805 260.295 270.588 279.288 286.981 289.298 296.100 302.417 310.189 315.718 243 189.973 201.716 261.333 271.646 280.362 288.070 290.391 297.206 303.534 311.320 316.859 244 190.856 202.627 262.371 272.704 281.437 289.159 291.484 298.311 304.651 312.450 317.999 245 191.739 203.539 263.409 273.762 282.511 290.248 292.577 299.417 305.767 313.580 319.138 246 192.623 204.450 264.447 274.820 283.586 291.336 293.670 300.522 306.883 314.710 320.278 247 193.507 205.362 265.485 275.878 284.660 292.425 294.762 301.626 307.999 315.840 321.417 248 194.391 206.274 266.523 276.935 285.734 293.513 295.855 302.731 309.115 316.969 322.556 249 195.276 207.186 267.561 277.993 286.808 294.601 296.947 303.835 310.231 318.098 323.694 250 196.161 208.098 268.599 279.050 287.882 295.689 298.039 304.940 311.346 319.227 324.832 300 240.663 253.912 320.397 331.789 341.395 349.874 352.425 359.906 366.844 375.369 381.425 350 285.608 300.064 372.051 384.306 394.626 403.723 406.457 414.474 421.900 431.017 437.488 400 330.903 346.482 423.590 436.649 447.632 457.305 460.211 468.724 476.606 486.274 493.132 450 376.483 393.118 475.035 488.849 500.456 510.670 513.736 522.717 531.026 541.212 548.432 500 422.303 439.936 526.401 540.930 553.127 563.852 567.070 576.493 585.207 595.882 603.446 550 468.328 486.910 577.701 592.909 605.667 616.878 620.241 630.084 639.183 650.324 658.215 600 514.529 534.019 628.943 644.800 658.094 669.769 673.270 683.516 692.982 704.568 712.771 650 560.885 581.245 680.134 696.614 710.421 722.542 726.176 736.807 746.625 758.639 767.141 700 607.380 628.577 731.280 748.359 762.661 775.211 778.972 789.974 800.131 812.556 821.347 750 653.997 676.003 782.386 800.043 814.822 827.785 831.670 843.029 853.514 866.336 875.404 800 700.725 723.513 833.456 851.671 866.911 880.275 884.279 895.984 906.786 919.991 929.329 850 747.554 771.099 884.492 903.249 918.937 932.689 936.808 948.848 959.957 973.534 983.133 900 794.475 818.756 935.499 954.782 970.904 985.032 989.263 1001.630 1013.036 1026.974 1036.826 950 841.480 866.477 986.478 1006.272 1022.816 1037.311 1041.651 1054.334 1066.031 1080.320 1090.418 1000 888.564 914.257 1037.431 1057.724 1074.679 1089.531 1093.977 1106.969 1118.948 1133.579 1143.917]; % remove DOF column TAB = TAB(:,2:end); % add the P=0.5 column PRB = [PRB(1:2) 0.500 PRB(3:end)]; TAB = [TAB(:,1:2) DOF' TAB(:,3:end)]; end % ========== End of function - Start GPL license ========== % # START GPL LICENSE %--------------------------------------------------------------------- % % This file is part of SLAMTB, a SLAM toolbox for Matlab. % % SLAMTB is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % SLAMTB is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with SLAMTB. If not, see <http://www.gnu.org/licenses/>. % %--------------------------------------------------------------------- % SLAMTB is Copyright 2007,2008,2009 % by Joan Sola, David Marquez and Jean Marie Codol @ LAAS-CNRS. % See on top of this file for its particular copyright. % # END GPL LICENSE
github
rising-turtle/slam_matlab-master
vecnorm.m
.m
slam_matlab-master/ground_truth_zh/slamtoolbox/slamToolbox_11_09_08/Math/vecnorm.m
1,534
utf_8
79b38e4a6fe6b82aa4e59d153995e278
function [n, N_v] = vecnorm(v) % VECNORM Vector norm, with Jacobian % VECNORM(V) is the same as NORM(V) % % [n, N_v] = VECNORM(V) returns also the Jacobian. if nargout == 1 n = sqrt(v'*v); else n = sqrt(v'*v); N_v = v'/n; end end %% function f() %% syms v1 v2 real v = [v1;v2]; [n,N_v] = vecnorm(v); N_v - jacobian(n,v) end % ========== End of function - Start GPL license ========== % # START GPL LICENSE %--------------------------------------------------------------------- % % This file is part of SLAMTB, a SLAM toolbox for Matlab. % % SLAMTB is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % SLAMTB is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with SLAMTB. If not, see <http://www.gnu.org/licenses/>. % %--------------------------------------------------------------------- % SLAMTB is Copyright 2007, 2008, 2009, 2010 % by Joan Sola @ LAAS-CNRS. % SLAMTB is Copyright 2009 % by Joan Sola, David Marquez and Jean Marie Codol @ LAAS-CNRS. % See on top of this file for its particular copyright. % # END GPL LICENSE
github
rising-turtle/slam_matlab-master
toFrameHmg.m
.m
slam_matlab-master/ground_truth_zh/slamtoolbox/slamToolbox_11_09_08/Points/toFrameHmg.m
3,142
utf_8
3a88bb83e7b0e927258f70d4fdd76b12
function [hf,HF_f,HF_h] = toFrameHmg(F,h) % TOFRAMEHMG To-frame transformation for homogeneous coordinates % P = TOFRAMEHMG(F,PF) transforms homogeneous point P from the global % frame to local frame F. % % [p,Pf,Ppf] = ... returns the Jacobians wrt F and PF. % Copyright 2008-2011 Joan Sola @ LAAS-CNRS. [t,q,R] = splitFrame(F) ; iF = [R' -R'*t ; 0 0 0 1]; hf = iF*h; if nargout > 1 [x,y,z] = split(t); [a,b,c,d] = split(q); [hx,hy,hz,ht] = split(h); HF_f = [... [ -ht*(a^2 + b^2 - c^2 - d^2), (-2)*ht*(a*d + b*c), 2*ht*(a*c - b*d), 2*a*hx - 2*c*hz + 2*d*hy - 2*ht*(a*x - c*z + d*y), 2*b*hx + 2*c*hy + 2*d*hz - 2*ht*(b*x + c*y + d*z), 2*b*hy - 2*a*hz - 2*c*hx + 2*ht*(a*z - b*y + c*x), 2*a*hy + 2*b*hz - 2*d*hx - 2*ht*(a*y + b*z - d*x)] [ 2*ht*(a*d - b*c), -ht*(a^2 - b^2 + c^2 - d^2), (-2)*ht*(a*b + c*d), 2*a*hy + 2*b*hz - 2*d*hx - 2*ht*(a*y + b*z - d*x), 2*a*hz - 2*b*hy + 2*c*hx - 2*ht*(a*z - b*y + c*x), 2*b*hx + 2*c*hy + 2*d*hz - 2*ht*(b*x + c*y + d*z), 2*c*hz - 2*a*hx - 2*d*hy + 2*ht*(a*x - c*z + d*y)] [ (-2)*ht*(a*c + b*d), 2*ht*(a*b - c*d), -ht*(a^2 - b^2 - c^2 + d^2), 2*a*hz - 2*b*hy + 2*c*hx - 2*ht*(a*z - b*y + c*x), 2*d*hx - 2*b*hz - 2*a*hy + 2*ht*(a*y + b*z - d*x), 2*a*hx - 2*c*hz + 2*d*hy - 2*ht*(a*x - c*z + d*y), 2*b*hx + 2*c*hy + 2*d*hz - 2*ht*(b*x + c*y + d*z)] [ 0, 0, 0, 0, 0, 0, 0]]; HF_h = iF; end end %% function f() %% syms x y z a b c d hx hy hz ht real F.x=[x;y;z;a;b;c;d]; F=updateFrame(F); h = [hx;hy;hz;ht]; hf = toFrameHmg(F,h) HF_f = simplify(jacobian(hf,F.x)) HF_h = simplify(jacobian(hf,h)) [hf,HF_f,HF_h] = toFrameHmg(F,h); simplify(HF_f - jacobian(hf,F.x)) simplify(HF_h - jacobian(hf,h)) %% end % ========== End of function - Start GPL license ========== % # START GPL LICENSE %--------------------------------------------------------------------- % % This file is part of SLAMTB, a SLAM toolbox for Matlab. % % SLAMTB is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % SLAMTB is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with SLAMTB. If not, see <http://www.gnu.org/licenses/>. % %--------------------------------------------------------------------- % SLAMTB is Copyright 2007,2008,2009 % by Joan Sola, David Marquez and Jean Marie Codol @ LAAS-CNRS. % See on top of this file for its particular copyright. % # END GPL LICENSE
github
rising-turtle/slam_matlab-master
invDistortion.m
.m
slam_matlab-master/ground_truth_zh/slamtoolbox/slamToolbox_11_09_08/Observations/invDistortion.m
4,410
utf_8
01b198fd2276fbb194a08f453ffa5317
function kc = invDistortion(kd,n,cal,draw) % INVDISTORTION Radial distortion correction calibration. % % Kc = INVDISTORTION(Kd,n) computes the least squares optimal set % of n parameters of the correction radial distortion function % for a normalized camera: % % r = c(rd) = rd (1 + c2 rd^2 + ... + c2n rd^2n) % % that best approximates the inverse of the distortion function % % rd = d(r) = r (1 + d2 r^2 + d4 r^4 + ...) % % which can be of any length. % % Kc = INVDISTORTION(Kd,n,cal) accepts the intrinsic parameters % of the camera cal = [u_0, v_0, a_u, a_v]. % % The format of the distortion and correction vectors is % % Kd = [d2, d4, d6, ...] % Kc = [c2, c4, ..., c2n] % % Kc = INVDISTORTION(...,DRAW) with DRAW~=0 additionally plots the % distortion and correction mappings r_d=d(r) and r=c(r_d) % and the error (r - r_d). % % See also PINHOLE, INVPINHOLE. % Copyright 2008-2009 Joan Sola @ LAAS-CNRS. if numel(kd) == 0 kc = []; else if nargin == 2 || isempty(cal) cal = [1 1 1 1]; end % fprintf(' Obtaining correction vector from distortion vector...'); rmax2 = (cal(1)/cal(3))^2 + (cal(2)/cal(4))^2; rmax = sqrt(rmax2); % maximum radius in normalized coordinates rdmax = 1.1*rmax; % N=101 sampling points of d(r) rc = [0:.01*rdmax:rdmax]; % rc is the undistorted radius vector rd = c2d(kd,rc); % rd is the distorted radius vector % 1. non-linear least-squares method (for other than radial distortion) % comment out for testing against psudo-inverse method % x0 = zeros(1,n); % kc = lsqnonlin(@(x) fun(x,rc,rd),x0); % 2. pseudo-inverse method (indicated for radial distortion) % we solve the system A*Kc = rc-rd via Kc = pinv(A)*(rc-rd). A = []; % construction of A for Kc of length n for i = 1:n A = [A rd'.^(2*i+1)]; end B = pinv(A); kc = (rc-rd)*B'; % All transposed because we are working with row-vectors % fprintf(' OK.\n'); if nargin == 4 && draw % normalized error erc = d2c(kc,rd); % correction and distortion functions figure(9) subplot(3,1,[1 2]) plot(rc,rd,'linewidth',2) title('Distortion mapping'),xlabel('r'),ylabel('rd'),grid set(gca,'xlim',[0 rdmax]) hold on plot(erc,rd,'r--','linewidth',2) hold off % error function (in pixels) subplot(3,1,3) plot(rc,cal(3)*(rc-erc)) title('Correction error [pix]'),xlabel('r'),ylabel('error'),grid set(gca,'xlim',[0 rdmax]) % error values err_max = cal(3)*max (abs(rc-erc)); err_mean = cal(3)*mean(rc-erc); err_std = cal(3)*std (rc-erc); fprintf(1,' Errors. Max: %.2f | Mean: %.2f | Std: %.2f pixels.\n',err_max,err_mean,err_std) end end % Necessary functions % corr- to dis- conversion function rd = c2d(kd,rc) c = ones(1,length(rc)); for i=1:length(kd) c = c+kd(i)*rc.^(2*i); end rd = rc.*c; % dis- to corr- conversion function rc = d2c(kc,rd) c = ones(1,length(rd)); for i=1:length(kc) c = c+kc(i)*rd.^(2*i); end rc = rd.*c; % error function (only for non-linear least squares - normally % not necessary) function e = fun(kc,rc,rd) e = d2c(kc,rd) - rc; % ========== End of function - Start GPL license ========== % # START GPL LICENSE %--------------------------------------------------------------------- % % This file is part of SLAMTB, a SLAM toolbox for Matlab. % % SLAMTB is free software: you can redistribute it and/or modify % it under the terms of the GNU General Public License as published by % the Free Software Foundation, either version 3 of the License, or % (at your option) any later version. % % SLAMTB is distributed in the hope that it will be useful, % but WITHOUT ANY WARRANTY; without even the implied warranty of % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the % GNU General Public License for more details. % % You should have received a copy of the GNU General Public License % along with SLAMTB. If not, see <http://www.gnu.org/licenses/>. % %--------------------------------------------------------------------- % SLAMTB is Copyright 2007,2008,2009 % by Joan Sola, David Marquez and Jean Marie Codol @ LAAS-CNRS. % See on top of this file for its particular copyright. % # END GPL LICENSE
github
rising-turtle/slam_matlab-master
generate_gt_wpattern5.m
.m
slam_matlab-master/ground_truth_zh/old_files/generate_gt_wpattern5.m
16,501
utf_8
4479f8c583f233d87a85308672b6940e
% Generate ground truth from motion capture data of MOTIVE % Assumption : Motion caputre data of MOTIVE(file format : *.csv) has only double marker on SR4K % % Author : Soonhac Hong ([email protected]) % Date : 10/2/13 % Coordinate : PGO function generate_gt_wpattern5() clear all %addpath('..\GraphSLAM'); %addpath('..\Localization'); %addpath('..\slamtoolbox\slamToolbox_11_09_08\FrameTransforms\Rotations'); path_dir = 'D:\co_worker\ground_truth'; addpath(strcat(path_dir, '\GraphSLAM')); addpath(strcat(path_dir, '\Localization')); addpath(strcat(path_dir, '\slamtoolbox\slamToolbox_11_09_08\FrameTransforms\Rotations')); %% Load motion capture data %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_10June_2015\Motive_capture_data\Take 2015-06-10 04.45.44 PM.csv'; % 19 %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_12June_2015\Motive_capture_data\Take 2015-06-13 10.31.15 AM.csv'; % 19 %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_10June_2015\Motive_capture_data\Take 2015-06-10 04.45.44 PM.csv'; % 19 %data_file_name = 'C:\Users\ymzhao\Desktop\ground_truth_data\motioncapture\Session 2014-02-13\m5_2 Take 2014-02-13 02.32.29 PM.csv'; % 19 %data_file_name = 'C:\Users\ymzhao\Desktop\ground_truth_data\motioncapture\Take 2015-06-14 01.22.29 PM.csv'; % 19 %data_file_name = 'C:\Users\ymzhao\Desktop\ground_truth_data\motioncapture\Take 2015-06-15 12.08.12 AM.csv'; % 19 %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_15June_2015\IEKF_data_15June2015\Take 2015-06-15 12.04.48 AM.csv'; % $@06/15/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_18June_2015\EKF_data_18June2015\Take 2015-06-18 05.46.35 PM.csv';% diff_threshold = 0.00002 % $@06/18/2015,data 1$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_23June_2015\EKF_data_23June2015\Take 2015-06-25 11.16.27 AM.csv';% $@06/18/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_26July_2015\IEKF_data_26July2015\Take 2015-07-26 11.22.31 AM.csv'; % diff_threshold = 0.00002 $@07/26/2015,data 1$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_26July_2015\IEKF_data_26July2015\Take 2015-07-26 11.39.04 AM.csv'; % diff_threshold = 0.00002 $@07/26/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_28July_2015\IEKF_data_28July2015\Take 2015-07-29 02.09.11 PM.csv'; % data 4, diff_threshold = 0.00002 $@07/28/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_30July_2015\IEKF_data_30July2015\Take 2015-07-30 05.37.59 PM.csv'; % data 1 diff_threshold = 0.00002 $@07/30/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_30July_2015\IEKF_data_30July2015\Take 2015-07-30 05.42.15 PM.csv'; % data 2 diff_threshold = 0.00002 $@07/30/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_03August_2015\IEKF_data_03August2015\Take 2015-08-03 11.32.37 AM.csv'; % data 1, diff_threshold = 0.000025 $@08/03/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_03August_2015\IEKF_data_03August2015\Take 2015-08-03 11.36.33 AM.csv'; % data 2, diff_threshold = 0.000025 $@08/03/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_03August_2015\IEKF_data_03August2015\Take 2015-08-03 11.39.47 AM.csv'; % data 3, diff_threshold = 0.000025 $@08/03/2015,data 2$ %data_file_name = 'D:\co_worker\ground_truth\motion_capture_data\test_10_16_2015\Take 2015-08-03 11.39.47 AM.csv'; % Take 2015-10-16 04.25.55 PM.csv data_file_name = 'D:\co_worker\ground_truth\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.csv'; %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_03August_2015\IEKF_data_03August2015\Take 2015-08-03 11.43.13 AM.csv'; % data 4, diff_threshold = 0.00002 $@08/03/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_03August_2015\IEKF_data_03August2015\Take 2015-08-03 11.46.06 AM.csv'; % data 5, diff_threshold = 0.00002 $@08/03/2015,data 2$ %data_file_name = 'C:\Yiming\data_experiments\RS4000_motive_03August_2015\IEKF_data_03August2015\Take 2015-08-03 11.48.59 AM.csv'; % data 6, diff_threshold = 0.00004 $@08/03/2015,data 2$ % set up the parameters find_start_end_point=true; min_marker = 2; find_pair_method_index = 2; find_pair_method_list={'NN','TP','ICP'}; find_pair_method = find_pair_method_list{find_pair_method_index}; % open the data file fid = fopen(data_file_name); if fid < 0 error(['Cannot open file ' data_file_name]); end %% scan all lines into a cell array columns=textscan(fid,'%s','delimiter','\n'); fclose(fid); lines=columns{1}; N=size(lines,1); frame_number = N-45; % frame_number is the frame number of dataset; (45 is the number of lines of data file header) gt=[]; gt_total=[]; % figure; start_frame_index = 0; %500; %2000; %2300; %1737; finish_frame_index = intmax; %intmax; % ; %2600; %4000; %6300; %4146; for i=1:N line_i=lines{i}; line_data = textscan(line_i,'%s %d %f %f %f %f %f %f %d %s %f %f %f %d %s %f %f %f %d %s %f %f %f %d %s %f %f %f %d %s','delimiter',','); if strcmp(line_data{1}, 'frame') if ~isempty(line_data{6}) if line_data{2} > start_frame_index && line_data{2} <= finish_frame_index time_stamp = line_data{3}; marker=[]; if line_data{5} >= 5 % original %if line_data{5} >= 3 % modified @06/14/2015 for m=1:line_data{5} marker=[marker; [line_data{(m-1)*5+6},line_data{(m-1)*5+7},line_data{(m-1)*5+8}]]; end %x= mean([line_data{6}, line_data{11}, line_data{16}]); %y= mean([line_data{7}, line_data{12}, line_data{17}]); %z= mean([line_data{8}, line_data{13}, line_data{18}]); if check_marker_pattern(marker) %if check_marker_pattern_plane_fitting(marker) pos = mean(marker,1); %[x,y,z]; % [x,y,z] gt= [gt; time_stamp, pos]; gt_total = [gt_total; time_stamp, reshape(marker', 1, 15)];%original %gt_total = [gt_total; time_stamp, reshape(marker', 1, 9)];%original end % elseif line_data{5} == 2 % marker=[marker; [line_data{6},line_data{7},line_data{8}]]; % marker=[marker; [line_data{11},line_data{12},line_data{13}]]; % if check_marker_pattern(marker) % %x= mean([line_data{6}, line_data{11}]); % %y= mean([line_data{7}, line_data{12}]); % %z= mean([line_data{8}, line_data{13}]); % pos = mean(marker,1); %[x,y,z]; % [x,y,z] % gt = [gt; time_stamp, pos]; % end end % else % pos = [line_data{6}, line_data{7}, line_data{8}]; % end % gt = [gt; time_stamp, pos]; end % animation % plot3(pos(1),pos(2),pos(3),'*-');axis equal; grid; % hold on; % drawnow; end %line_data = str2num(line_data{1}); %line_data = textscan(line_i,'%f %f %f',1); end end % hold off; %% Find start point and finish point if find_start_end_point % diff_threshold = 0.000035; %0.00002 %0.000012,$@07/30/2015,data 1$; %0.00002, $@07/28/2015,data 4$; % 0.000035,$@06/18/2015,data 1$; %0.001;0.0001,0.00005, 0.00002% this value should be assigned according to the data number diff_threshold = 0.00042; % 0.00032; gt_diff = diff(gt(:,2:4),1,1); gt_diff_abs = abs(gt_diff); gt_length=size(gt_diff,1); gt_middle_index = round(gt_length/2); gt_diff_index = find((gt_diff_abs(1:gt_middle_index,1) <= diff_threshold) & (gt_diff_abs(1:gt_middle_index,2) <= diff_threshold) & (gt_diff_abs(1:gt_middle_index,3) <= diff_threshold)); start_index = gt_diff_index(end); gt_diff_index = find((gt_diff_abs(gt_middle_index:end,1) <= diff_threshold) & (gt_diff_abs(gt_middle_index:end,2) <= diff_threshold) & (gt_diff_abs(gt_middle_index:end,3) <= diff_threshold)); finish_index = gt_diff_index(1)+gt_middle_index-1; figure;plot(gt_diff); line([start_index,start_index],[0,max(max(gt_diff))],'Color','m','LineWidth',2); line([start_index,start_index],[0,min(min(gt_diff))],'Color','m','LineWidth',2); line([finish_index,finish_index],[0,max(max(gt_diff))],'Color','c','LineWidth',2); line([finish_index,finish_index],[0,min(min(gt_diff))],'Color','c','LineWidth',2); % Delete reduntant data gt = gt(start_index:finish_index,:); gt_total = gt_total(start_index:finish_index,:); end % Convert motive poses to world coordinate; added by Yimin Zhao $06/17/2015$ % X => -X, Y => Z, Z=>Y %------------------------------------------------------------------------- gt(:,2:4) = gt(:,2:4).*repmat([-1 1 1],size(gt,1),1); % modified by Yimin Zhao $06/17/2015$ gt_temp = gt; % modified by Yimin Zhao $06/17/2015$ gt(:,3) = gt_temp(:,4); % modified by Yimin Zhao $06/17/2015$ gt(:,4) = gt_temp(:,3); % modified by Yimin Zhao $06/17/2015$ gt_total(:,2:end) = gt_total(:,2:end).*repmat([-1 1 1],size(gt,1),5); % modified by Yimin Zhao $06/17/2015$ gt_total_temp=gt_total; % modified by Yimin Zhao $06/17/2015$ for k=1:5 gt_total(:,3+3*(k-1)) = gt_total_temp(:,4+3*(k-1)); gt_total(:,4+3*(k-1)) = gt_total_temp(:,3+3*(k-1)); end %-------------------------------------------------------------------------- % Set first frame is origin. gt(:,2:4) = gt(:,2:4) - repmat(gt(1,2:4), size(gt,1), 1); %gt_total(:,2:end) = gt_total(:,2:end) - repmat(gt_total(1,2:end), size(gt_total,1), 1); if strcmp(find_pair_method, 'NN') % Find pairs by nearest neighbor gt_total_pair=gt_total(1,:); for i=2:size(gt_total,1) gt_total_pair(i,1) = gt_total(i,1); min_idx_prev=[]; for j=1:5 cur = gt_total(i,2+(j-1)*3:4+(j-1)*3); diff_dist=[]; for k=1:5 pre = gt_total_pair(i-1,2+(k-1)*3:4+(k-1)*3); diff_dist = [diff_dist; norm(pre - cur)]; end diff_dist(min_idx_prev)=intmax; [~, min_idx] = min(diff_dist); min_idx_prev = [min_idx_prev; min_idx]; gt_total_pair(i,2+(min_idx-1)*3:4+(min_idx-1)*3)=cur; end end elseif strcmp(find_pair_method, 'TP') [ gt_total_pair ] = find_pair_tp( gt_total ); [ gt_total_pair(:,11:16)] = find_pair_nn( gt_total_pair(:,11:16)); elseif strcmp(find_pair_method, 'ICP') % Find pair by ICP [ gt_total_pair ] = find_pair_icp( gt_total ); else disp('Find_pair_method is not defined!'); return; end % Delete invalide data % gt_total_pair(invalid_data_index,:)=[]; % Set the origin of motion capture system at the center of five LEDs in initial positon %% added by Yimin Zhao on @13/07/2015 marker=[]; for m=1:5 marker=[marker; [gt_total_pair(1,(m-1)*3+2),gt_total_pair(1,(m-1)*3+3),gt_total_pair(1,(m-1)*3+4)]]; end % set the origin of motion capture system to the center of five LEDs in initial position origin = mean(marker,1); gt_total_pair(1,2:4) gt_total_pair(:,2:end) = gt_total_pair(:,2:end) - repmat(origin, size(gt_total_pair,1), 5); % some concern %% original of Soonhac %gt_total_pair(:,2:end) = gt_total_pair(:,2:end) - repmat(gt_total_pair(1,2:4), size(gt_total_pair,1), 5); %% generate pose gt_pose=[gt_total_pair(1,1), 0,0,0,1,0,0,0]; gt_pose_euler=[gt_total_pair(1,1), 0,0,0,0,0,0]; distance_total=[]; gt_total_pair; for i=1:size(gt_total_pair,1)-1 op_pset1 = []; op_pset2 = []; for k=1:5 op_pset1 = [op_pset1; gt_total_pair(1,2+(k-1)*3:4+(k-1)*3)]; op_pset2 = [op_pset2; gt_total_pair(i+1,2+(k-1)*3:4+(k-1)*3)]; end [rot, trans, sta] = find_transform_matrix(op_pset2', op_pset1'); if sta > 0 % q = R2q(rot); gt_pose=[gt_pose; gt_total_pair(i+1,1), trans' q']; % e = R2e(rot); gt_pose_euler=[gt_pose_euler; gt_total_pair(i+1,1), trans' e']; % check relative distance b/w markers for rigid body if i==1 for k=2:5 distance(k-1)=norm(op_pset1(k,:)-op_pset1(1,:)); end distance_total=[distance_total; distance]; end for k=2:5 distance(k-1)=norm(op_pset2(k,:)-op_pset2(1,:)); end distance_total=[distance_total; distance]; else sta; end end save('ground_pose.mat', 'gt_pose', 'frame_number'); % added by Yimin Zhao on $@06/16/2015$ %% show relative distance between marker for checking rigid body figure; plot_colors={'b.','r.','g.','m.','c.'}; for k=1:4 plot(distance_total(:,k),plot_colors{k}); hold on; end xlabel('Frame'); ylabel('Relative Distance'); grid; legend('v^1_2','v^1_3','v^1_4','v^1_5'); hold off; %% show rmse of transformation % figure; % plot(rmse); % grid; % xlabel('Frame'); % ylabel('RMSE of Transformation'); %% show gt_pose figure; plot3(gt_pose_euler(:,2),gt_pose_euler(:,3),gt_pose_euler(:,4),'.-'); hold on; plot3(gt_pose_euler(1,2),gt_pose_euler(1,3),gt_pose_euler(1,4),'g*', 'MarkerSize', 10); hold off; axis equal; grid; xlabel('X');ylabel('Y');zlabel('Z'); title('Translaton'); %% Convert Quaternion to Euler angles [roll;pitch;yaw] % for i=1:size(gt_pose,1) % gt_pose_euler(i,:) = q2e(gt_pose(i,5:8))'*180/pi(); % end figure; title_list ={'Rx','Ry','Rz'}; for i=1:3 %plot(gt_pose(:,i+4),plot_colors{i}); %subplot(3,1,i);plot(gt_pose_euler(:,i),plot_colors{i}); subplot(3,1,i);plot(gt_pose_euler(:,i+4)*180/pi(),plot_colors{i}); title(title_list{i});grid; %hold on; end %plot3(gt_pose(1,2),gt_pose(1,3),gt_pose(1,4),'g*', 'MarkerSize', 10); %hold off; %axis equal; %grid; xlabel('frame'); %ylabel('Orientation [quaternion]'); ylabel('Orientation [degree]'); %legend('Rx','Ry','Rz'); %% show ground truth figure; plot3(gt(:,2),gt(:,3),gt(:,4),'.-'); hold on; plot3(gt(1,2),gt(1,3),gt(1,4),'g*', 'MarkerSize', 10); hold off; axis equal; grid; xlabel('X');ylabel('Y');zlabel('Z'); %%[vro_poses_trajectory_error, vro_poses_trajectory_length, %%vro_poses_first_last_distance] = compute_trajectory_error(gt(:,2:4)) % %%removed by Yimin Zhao $@02/26/2015$ %% show ground truth by pairs figure; %plot_colors={'b.-','r.-','g.-','m.-','c.-'}; for i=1:5 plot3(gt_total_pair(:,2+3*(i-1)),gt_total_pair(:,3+3*(i-1)),gt_total_pair(:,4+3*(i-1)),plot_colors{i}); hold on; end plot3(gt_total_pair(1,2),gt_total_pair(1,3),gt_total_pair(1,4),'g*', 'MarkerSize', 10); hold off; axis equal; grid; xlabel('X');ylabel('Y');zlabel('Z'); title('GT pairs'); %% show ground truth figure; %plot_colors={'b.-','r.-','g.-','m.-','c.-'}; for i=1:5 plot3(gt_total(:,2+3*(i-1)),gt_total(:,3+3*(i-1)),gt_total(:,4+3*(i-1)),plot_colors{i}); hold on; end plot3(gt_total(1,2),gt_total(1,3),gt_total(1,4),'g*', 'MarkerSize', 10); hold off; axis equal; grid; xlabel('X');ylabel('Y');zlabel('Z'); %% show displacement gt_diff = diff(gt(:,2:4),5,1); %[~,gt_diff] = gradient(gt(:,2:4)); for i=1:size(gt_diff,1) displacement(i,1) = norm(gt_diff(i,:)); end figure; plot(displacement); xlabel('Frame'); ylabel('displacement [m]'); %% Save video % vidObj = VideoWriter(strrep(data_file_name, 'csv','avi')); % open(vidObj); % % figure; % for i=1:size(gt,1) % plot3(gt(i,2),gt(i,3),gt(i,4),'.-');axis equal; grid; % xlabel('X');ylabel('Y');zlabel('Z'); % hold on; % % if i ~= size(gt,1) % pause(abs(gt(i,1)-gt(i+1,1))); % end % % currFrame = getframe; % writeVideo(vidObj,currFrame); % % drawnow; % end % close(vidObj); %% Save data if find_start_end_point out_file_name=strrep(data_file_name, 'csv','dat_wp'); total_out_file_name=strrep(data_file_name, 'csv','dat_total_wp'); gt_pose_out_file_name=strrep(data_file_name, 'csv','dat_pose_wp'); else out_file_name=strrep(data_file_name, 'csv','dat_full_wp'); total_out_file_name=strrep(data_file_name, 'csv','dat_total_full_wp'); gt_pose_out_file_name=strrep(data_file_name, 'csv','dat_pose_full_wp'); end dlmwrite(out_file_name,gt,' '); % [time_stamp x y z] dlmwrite(total_out_file_name,gt_total_pair,' '); % [time_stamp [x y z]*5] dlmwrite(gt_pose_out_file_name,gt_pose,' '); % [time_stamp [x y z q1 q2 q3 q4] end
github
rising-turtle/slam_matlab-master
generate_gt_wpattern_zh.m
.m
slam_matlab-master/ground_truth_zh/old_files/generate_gt_wpattern_zh.m
6,046
utf_8
4e613acccda20ab494be4c4951fa6fb4
% Generate ground truth from motion capture data of MOTIVE, using Time to % synchorize not the movement % Assumption : Motion caputre data of MOTIVE(file format : *.csv) has at least 5 marker on SR4K % % Author : David Zhang ([email protected]) % Date : 10/23/15 function generate_gt_wpattern_zh() clear all clc clf close all path_dir = '.'; addpath(strcat(path_dir, '\GraphSLAM')); addpath(strcat(path_dir, '\Localization')); addpath(strcat(path_dir, '\slamtoolbox\slamToolbox_11_09_08\FrameTransforms\Rotations')); %% Load motion capture data data_file_name = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.csv'; %% open and load the data fid = fopen(data_file_name); if fid < 0 error(['Cannot open file ' data_file_name]); end [line_data, gt, gt_total] = scan_data (fid); % retrive data from file %% T pattern, find matched points % ---|--- 4/5 1 5/4 % | 2 % | 3 % find the T pattern in each frame, and find 5 matched points [ gt_total_pair ] = find_pair_tp( gt_total ); [ gt_total_pair(:,11:16)] = find_pair_nn( gt_total_pair(:,11:16)); %% added by Yimin Zhao on @13/07/2015 marker=[]; for m=1:5 marker=[marker; [gt_total_pair(1,(m-1)*3+2),gt_total_pair(1,(m-1)*3+3),gt_total_pair(1,(m-1)*3+4)]]; end % set the origin of motion capture system to the center of five LEDs in initial position origin = mean(marker,1); gt_total_pair(:,2:end) = gt_total_pair(:,2:end) - repmat(origin, size(gt_total_pair,1), 5); % some concern %% original of Soonhac %gt_total_pair(:,2:end) = gt_total_pair(:,2:end) - repmat(gt_total_pair(1,2:4), size(gt_total_pair,1), 5); %% generate pose [gt_pose, gt_pose_euler, distance_total] = compute_transformation(gt_total_pair); %% plot result % plot_distance(distance_total); plot_gt_pose(gt_pose_euler); % plot_Rxyz(gt_pose_euler); plot_ground_truth1(gt); % plot_gt_pairs(gt_total_pair); % plot_ground_truth2(gt_total); % plot_displacement(gt_total); %% Save result out_file_name=strrep(data_file_name, 'csv','dat_wp'); total_out_file_name=strrep(data_file_name, 'csv','dat_total_wp'); gt_pose_out_file_name=strrep(data_file_name, 'csv','dat_pose_wp'); dlmwrite(out_file_name,gt,' '); % [time_stamp x y z] dlmwrite(total_out_file_name,gt_total_pair,' '); % [time_stamp [x y z]*5] dlmwrite(gt_pose_out_file_name,gt_pose,' '); % [time_stamp [x y z q1 q2 q3 q4] end function [gt_pose, gt_pose_euler, distance_total] = compute_transformation(gt_total_pair) gt_pose=[gt_total_pair(1,1), 0,0,0,1,0,0,0]; gt_pose_euler=[gt_total_pair(1,1), 0,0,0,0,0,0]; distance_total=[]; for i=1:size(gt_total_pair,1)-1 op_pset1 = []; op_pset2 = []; for k=1:5 op_pset1 = [op_pset1; gt_total_pair(1,2+(k-1)*3:4+(k-1)*3)]; op_pset2 = [op_pset2; gt_total_pair(i+1,2+(k-1)*3:4+(k-1)*3)]; end [rot, trans, sta] = find_transform_matrix(op_pset2', op_pset1'); if sta > 0 % q = R2q(rot); gt_pose=[gt_pose; gt_total_pair(i+1,1), trans' q']; % e = R2e(rot); gt_pose_euler=[gt_pose_euler; gt_total_pair(i+1,1), trans' e']; % check relative distance b/w markers for rigid body if i==1 for k=2:5 distance(k-1)=norm(op_pset1(k,:)-op_pset1(1,:)); end distance_total=[distance_total; distance]; end for k=2:5 distance(k-1)=norm(op_pset2(k,:)-op_pset2(1,:)); end distance_total=[distance_total; distance]; else sta; end end end function plot_distance(distance_total) %% show relative distance between marker for checking rigid body figure; plot_colors={'b.','r.','g.','m.','c.'}; for k=1:4 plot(distance_total(:,k),plot_colors{k}); hold on; end xlabel('Frame'); ylabel('Relative Distance'); grid; legend('v^1_2','v^1_3','v^1_4','v^1_5'); hold off; end function plot_gt_pose(gt_pose_euler) %% show gt_pose figure; plot3(gt_pose_euler(:,2),gt_pose_euler(:,3),gt_pose_euler(:,4),'.-'); hold on; plot3(gt_pose_euler(1,2),gt_pose_euler(1,3),gt_pose_euler(1,4),'g*', 'MarkerSize', 10); hold off; axis equal; grid; xlabel('X');ylabel('Y');zlabel('Z'); title('Translaton'); end function plot_Rxyz(gt_pose_euler) plot_colors={'b.','r.','g.','m.','c.'}; figure; title_list ={'Rx','Ry','Rz'}; for i=1:3 %plot(gt_pose(:,i+4),plot_colors{i}); %subplot(3,1,i);plot(gt_pose_euler(:,i),plot_colors{i}); subplot(3,1,i);plot(gt_pose_euler(:,i+4)*180/pi(),plot_colors{i}); title(title_list{i});grid; %hold on; end xlabel('frame'); %ylabel('Orientation [quaternion]'); ylabel('Orientation [degree]'); %legend('Rx','Ry','Rz'); end function plot_ground_truth1(gt) %% show ground truth figure; plot3(gt(:,2),gt(:,3),gt(:,4),'.-'); hold on; plot3(gt(1,2),gt(1,3),gt(1,4),'g*', 'MarkerSize', 10); hold off; axis equal; grid; xlabel('X');ylabel('Y');zlabel('Z'); end function plot_gt_pairs(gt_total_pair) %% show ground truth by pairs plot_colors={'b.','r.','g.','m.','c.'}; figure; %plot_colors={'b.-','r.-','g.-','m.-','c.-'}; for i=1:5 plot3(gt_total_pair(:,2+3*(i-1)),gt_total_pair(:,3+3*(i-1)),gt_total_pair(:,4+3*(i-1)),plot_colors{i}); hold on; end plot3(gt_total_pair(1,2),gt_total_pair(1,3),gt_total_pair(1,4),'g*', 'MarkerSize', 10); hold off; axis equal; grid; xlabel('X');ylabel('Y');zlabel('Z'); title('GT pairs'); end function plot_ground_truth2(gt_total) %% show ground truth plot_colors={'b.','r.','g.','m.','c.'}; figure; %plot_colors={'b.-','r.-','g.-','m.-','c.-'}; for i=1:5 plot3(gt_total(:,2+3*(i-1)),gt_total(:,3+3*(i-1)),gt_total(:,4+3*(i-1)),plot_colors{i}); hold on; end plot3(gt_total(1,2),gt_total(1,3),gt_total(1,4),'g*', 'MarkerSize', 10); hold off; axis equal; grid; xlabel('X');ylabel('Y');zlabel('Z'); end function plot_displacement(gt) %% show displacement gt_diff = diff(gt(:,2:4),5,1); %[~,gt_diff] = gradient(gt(:,2:4)); for i=1:size(gt_diff,1) displacement(i,1) = norm(gt_diff(i,:)); end figure; plot(displacement); xlabel('Frame'); ylabel('displacement [m]'); end
github
rising-turtle/slam_matlab-master
rms_error_normal.m
.m
slam_matlab-master/ground_truth_zh/icp/rms_error_normal.m
277
utf_8
a1bfee1c1d3a829a0bb4f6882f8c5275
% Determine the RMS error between two point equally sized point clouds with % point correspondance. % ER = rms_error(p1,p2) where p1 and p2 are 3xn matrices. function ER = rms_error_normal(p1,p2,p1_normal) dsq = sum(power((p1 - p2).*p1_normal, 2),1); ER = sqrt(mean(dsq)); end
github
rising-turtle/slam_matlab-master
lsqnormest.m
.m
slam_matlab-master/ground_truth_zh/icp/lsqnormest.m
1,162
utf_8
4ea5bbbdd9266bde1adffd19ecc5f10e
% Least squares normal estimation from point clouds using PCA % % H. Hoppe, T. DeRose, T. Duchamp, J. McDonald, and W. Stuetzle. % Surface reconstruction from unorganized points. % In Proceedings of ACM Siggraph, pages 71:78, 1992. % % p should be a matrix containing the horizontally concatenated column % vectors with points. k is a scalar indicating how many neighbors the % normal estimation is based upon. % % Note that for large point sets, the function performs significantly % faster if Statistics Toolbox >= v. 7.3 is installed. % % Jakob Wilm 2010 function n = lsqnormest(p, k) m = size(p,2); n = zeros(3,m); v = ver('stats'); if str2double(v.Version) >= 7.5 neighbors = transpose(knnsearch(transpose(p), transpose(p), 'k', k+1)); else neighbors = k_nearest_neighbors(p, p, k+1); end for i = 1:m x = p(:,neighbors(2:end, i)); p_bar = 1/k * sum(x,2); P = (x - repmat(p_bar,1,k)) * transpose(x - repmat(p_bar,1,k)); %spd matrix P %P = 2*cov(x); [V,D] = eig(P); [xx, idx] = min(diag(D)); % choses the smallest eigenvalue n(:,i) = V(:,idx); % returns the corresponding eigenvector end end
github
rising-turtle/slam_matlab-master
rms_error.m
.m
slam_matlab-master/ground_truth_zh/icp/rms_error.m
247
utf_8
8ff81ab921610f97c536215259e9957a
% Determine the RMS error between two point equally sized point clouds with % point correspondance. % ER = rms_error(p1,p2) where p1 and p2 are 3xn matrices. function ER = rms_error(p1,p2) dsq = sum(power(p1 - p2, 2),1); ER = sqrt(mean(dsq)); end
github
rising-turtle/slam_matlab-master
k_nearest_neighbors.m
.m
slam_matlab-master/ground_truth_zh/icp/k_nearest_neighbors.m
870
utf_8
461d1ce66128cf3312da2e03c4d373c7
% Program to find the k - nearest neighbors (kNN) within a set of points. % Distance metric used: Euclidean distance % % Note that this function makes repetitive use of min(), which seems to be % more efficient than sort() for k < 30. function [neighborIds neighborDistances] = k_nearest_neighbors(dataMatrix, queryMatrix, k) numDataPoints = size(dataMatrix,2); numQueryPoints = size(queryMatrix,2); neighborIds = zeros(k,numQueryPoints); neighborDistances = zeros(k,numQueryPoints); D = size(dataMatrix, 1); %dimensionality of points for i=1:numQueryPoints d=zeros(1,numDataPoints); for t=1:D % this is to avoid slow repmat() d=d+(dataMatrix(t,:)-queryMatrix(t,i)).^2; end for j=1:k [s,t] = min(d); neighborIds(j,i)=t; neighborDistances(j,i)=sqrt(s); d(t) = NaN; % remove found number from d end end end
github
rising-turtle/slam_matlab-master
icp.m
.m
slam_matlab-master/ground_truth_zh/icp/icp.m
18,490
utf_8
0eafe0415df79a022b03af16bd28f313
function [TR, TT, ER, t] = icp(q,p,varargin) % Perform the Iterative Closest Point algorithm on three dimensional point % clouds. % % [TR, TT] = icp(q,p) returns the rotation matrix TR and translation % vector TT that minimizes the distances from (TR * p + TT) to q. % p is a 3xm matrix and q is a 3xn matrix. % % [TR, TT] = icp(q,p,k) forces the algorithm to make k iterations % exactly. The default is 10 iterations. % % [TR, TT, ER] = icp(q,p,k) also returns the RMS of errors for k % iterations in a (k+1)x1 vector. ER(0) is the initial error. % % [TR, TT, ER, t] = icp(q,p,k) also returns the calculation times per % iteration in a (k+1)x1 vector. t(0) is the time consumed for preprocessing. % % Additional settings may be provided in a parameter list: % % Boundary % {[]} | 1x? vector % If EdgeRejection is set, a vector can be provided that indexes into % q and specifies which points of q are on the boundary. % % EdgeRejection % {false} | true % If EdgeRejection is true, point matches to edge vertices of q are % ignored. Requires that boundary points of q are specified using % Boundary or that a triangulation matrix for q is provided. % % Extrapolation % {false} | true % If Extrapolation is true, the iteration direction will be evaluated % and extrapolated if possible using the method outlined by % Besl and McKay 1992. % % Matching % {bruteForce} | Delaunay | kDtree % Specifies how point matching should be done. % bruteForce is usually the slowest and kDtree is the fastest. % Note that the kDtree option is depends on the Statistics Toolbox % v. 7.3 or higher. % % Minimize % {point} | plane | lmaPoint % Defines whether point to point or point to plane minimization % should be performed. point is based on the SVD approach and is % usually the fastest. plane will often yield higher accuracy. It % uses linearized angles and requires surface normals for all points % in q. Calculation of surface normals requires substantial pre % proccessing. % The option lmaPoint does point to point minimization using the non % linear least squares Levenberg Marquardt algorithm. Results are % generally the same as in points, but computation time may differ. % % Normals % {[]} | n x 3 matrix % A matrix of normals for the n points in q might be provided. % Normals of q are used for point to plane minimization. % Else normals will be found through a PCA of the 4 nearest % neighbors. % % ReturnAll % {false} | true % Determines whether R and T should be returned for all iterations % or only for the last one. If this option is set to true, R will be % a 3x3x(k+1) matrix and T will be a 3x1x(k+1) matrix. % % Triangulation % {[]} | ? x 3 matrix % A triangulation matrix for the points in q can be provided, % enabling EdgeRejection. The elements should index into q, defining % point triples that act together as triangles. % % Verbose % {false} | true % Enables extrapolation output in the Command Window. % % Weight % {@(match)ones(1,m)} | Function handle % For point or plane minimization, a function handle to a weighting % function can be provided. The weighting function will be called % with one argument, a 1xm vector that specifies point pairs by % indexing into q. The weighting function should return a 1xm vector % of weights for every point pair. % % WorstRejection % {0} | scalar in ]0; 1[ % Reject a given percentage of the worst point pairs, based on their % Euclidean distance. % % Martin Kjer and Jakob Wilm, Technical University of Denmark, 2012 % Use the inputParser class to validate input arguments. inp = inputParser; inp.addRequired('q', @(x)isreal(x) && size(x,1) == 3); inp.addRequired('p', @(x)isreal(x) && size(x,1) == 3); inp.addOptional('iter', 10, @(x)x > 0 && x < 10^5); inp.addParamValue('Boundary', [], @(x)size(x,1) == 1); inp.addParamValue('EdgeRejection', false, @(x)islogical(x)); inp.addParamValue('Extrapolation', false, @(x)islogical(x)); validMatching = {'bruteForce','Delaunay','kDtree'}; inp.addParamValue('Matching', 'bruteForce', @(x)any(strcmpi(x,validMatching))); validMinimize = {'point','plane','lmapoint'}; inp.addParamValue('Minimize', 'point', @(x)any(strcmpi(x,validMinimize))); inp.addParamValue('Normals', [], @(x)isreal(x) && size(x,1) == 3); inp.addParamValue('NormalsData', [], @(x)isreal(x) && size(x,1) == 3); inp.addParamValue('ReturnAll', false, @(x)islogical(x)); inp.addParamValue('Triangulation', [], @(x)isreal(x) && size(x,2) == 3); inp.addParamValue('Verbose', false, @(x)islogical(x)); inp.addParamValue('Weight', @(x)ones(1,length(x)), @(x)isa(x,'function_handle')); inp.addParamValue('WorstRejection', 0, @(x)isscalar(x) && x > 0 && x < 1); inp.parse(q,p,varargin{:}); arg = inp.Results; clear('inp'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Actual implementation % Allocate vector for RMS of errors in every iteration. t = zeros(arg.iter+1,1); % Start timer tic; Np = size(p,2); % Transformed data point cloud pt = p; % Allocate vector for RMS of errors in every iteration. ER = zeros(arg.iter+1,1); % Initialize temporary transform vector and matrix. T = zeros(3,1); R = eye(3,3); % Initialize total transform vector(s) and rotation matric(es). TT = zeros(3,1, arg.iter+1); TR = repmat(eye(3,3), [1,1, arg.iter+1]); % If Minimize == 'plane', normals are needed if (strcmp(arg.Minimize, 'plane') && isempty(arg.Normals)) arg.Normals = lsqnormest(q,4); end % If Matching == 'Delaunay', a triangulation is needed if strcmp(arg.Matching, 'Delaunay') DT = DelaunayTri(transpose(q)); end % If Matching == 'kDtree', a kD tree should be built (req. Stat. TB >= 7.3) if strcmp(arg.Matching, 'kDtree') kdOBJ = KDTreeSearcher(transpose(q)); end % If edge vertices should be rejected, find edge vertices if arg.EdgeRejection if isempty(arg.Boundary) bdr = find_bound(q, arg.Triangulation); else bdr = arg.Boundary; end end if arg.Extrapolation % Initialize total transform vector (quaternion ; translation vec.) qq = [ones(1,arg.iter+1);zeros(6,arg.iter+1)]; % Allocate vector for direction change and change angle. dq = zeros(7,arg.iter+1); theta = zeros(1,arg.iter+1); end t(1) = toc; % Go into main iteration loop for k=1:arg.iter % Do matching switch arg.Matching case 'bruteForce' [match mindist] = match_bruteForce(q,pt); case 'Delaunay' [match mindist] = match_Delaunay(q,pt,DT); case 'kDtree' [match mindist] = match_kDtree(q,pt,kdOBJ); end % If matches to edge vertices should be rejected if arg.EdgeRejection p_idx = not(ismember(match, bdr)); q_idx = match(p_idx); mindist = mindist(p_idx); else p_idx = true(1, Np); q_idx = match; end % If worst matches should be rejected if arg.WorstRejection edge = round((1-arg.WorstRejection)*sum(p_idx)); pairs = find(p_idx); [xx, idx] = sort(mindist); p_idx(pairs(idx(edge:end))) = false; q_idx = match(p_idx); mindist = mindist(p_idx); end if k == 1 ER(k) = sqrt(sum(mindist.^2)/length(mindist)); end switch arg.Minimize case 'point' % Determine weight vector weights = arg.Weight(match); [R,T] = eq_point(q(:,q_idx),pt(:,p_idx), weights(p_idx)); case 'plane' weights = arg.Weight(match); [R,T] = eq_plane(q(:,q_idx),pt(:,p_idx),arg.Normals(:,q_idx),weights(p_idx)); case 'lmaPoint' [R,T] = eq_lmaPoint(q(:,q_idx),pt(:,p_idx)); end % Add to the total transformation TR(:,:,k+1) = R*TR(:,:,k); TT(:,:,k+1) = R*TT(:,:,k)+T; % Apply last transformation pt = TR(:,:,k+1) * p + repmat(TT(:,:,k+1), 1, Np); % Root mean of objective function ER(k+1) = rms_error(q(:,q_idx), pt(:,p_idx)); % If Extrapolation, we might be able to move quicker if arg.Extrapolation qq(:,k+1) = [rmat2quat(TR(:,:,k+1));TT(:,:,k+1)]; dq(:,k+1) = qq(:,k+1) - qq(:,k); theta(k+1) = (180/pi)*acos(dot(dq(:,k),dq(:,k+1))/(norm(dq(:,k))*norm(dq(:,k+1)))); if arg.Verbose disp(['Direction change ' num2str(theta(k+1)) ' degree in iteration ' num2str(k)]); end if k>2 && theta(k+1) < 10 && theta(k) < 10 d = [ER(k+1), ER(k), ER(k-1)]; v = [0, -norm(dq(:,k+1)), -norm(dq(:,k))-norm(dq(:,k+1))]; vmax = 25 * norm(dq(:,k+1)); dv = extrapolate(v,d,vmax); if dv ~= 0 q_mark = qq(:,k+1) + dv * dq(:,k+1)/norm(dq(:,k+1)); q_mark(1:4) = q_mark(1:4)/norm(q_mark(1:4)); qq(:,k+1) = q_mark; TR(:,:,k+1) = quat2rmat(qq(1:4,k+1)); TT(:,:,k+1) = qq(5:7,k+1); % Reapply total transformation pt = TR(:,:,k+1) * p + repmat(TT(:,:,k+1), 1, Np); % Recalculate root mean of objective function % Note this is costly and only for fun! switch arg.Matching case 'bruteForce' [xx, mindist] = match_bruteForce(q,pt); case 'Delaunay' [xx, mindist] = match_Delaunay(q,pt,DT); case 'kDtree' [xx, mindist] = match_kDtree(q,pt,kdOBJ); end ER(k+1) = sqrt(sum(mindist.^2)/length(mindist)); end end end t(k+1) = toc; end if not(arg.ReturnAll) TR = TR(:,:,end); TT = TT(:,:,end); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [match mindist] = match_bruteForce(q, p) m = size(p,2); n = size(q,2); match = zeros(1,m); mindist = zeros(1,m); for ki=1:m d=zeros(1,n); for ti=1:3 d=d+(q(ti,:)-p(ti,ki)).^2; end [mindist(ki),match(ki)]=min(d); end mindist = sqrt(mindist); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [match mindist] = match_Delaunay(q, p, DT) match = transpose(nearestNeighbor(DT, transpose(p))); mindist = sqrt(sum((p-q(:,match)).^2,1)); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [match mindist] = match_kDtree(xx, p, kdOBJ) [match mindist] = knnsearch(kdOBJ,transpose(p)); match = transpose(match); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [R,T] = eq_point(q,p,weights) m = size(p,2); n = size(q,2); % normalize weights weights = weights ./ sum(weights); % find data centroid and deviations from centroid q_bar = q * transpose(weights); q_mark = q - repmat(q_bar, 1, n); % Apply weights q_mark = q_mark .* repmat(weights, 3, 1); % find data centroid and deviations from centroid p_bar = p * transpose(weights); p_mark = p - repmat(p_bar, 1, m); % Apply weights %p_mark = p_mark .* repmat(weights, 3, 1); N = p_mark*transpose(q_mark); % taking points of q in matched order [U,xx,V] = svd(N); % singular value decomposition R = V*transpose(U); T = q_bar - R*p_bar; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [R,T] = eq_plane(q,p,n,weights) n = n .* repmat(weights,3,1); c = cross(p,n); cn = vertcat(c,n); C = cn*transpose(cn); b = - [sum(sum((p-q).*repmat(cn(1,:),3,1).*n)); sum(sum((p-q).*repmat(cn(2,:),3,1).*n)); sum(sum((p-q).*repmat(cn(3,:),3,1).*n)); sum(sum((p-q).*repmat(cn(4,:),3,1).*n)); sum(sum((p-q).*repmat(cn(5,:),3,1).*n)); sum(sum((p-q).*repmat(cn(6,:),3,1).*n))]; X = C\b; cx = cos(X(1)); cy = cos(X(2)); cz = cos(X(3)); sx = sin(X(1)); sy = sin(X(2)); sz = sin(X(3)); R = [cy*cz cz*sx*sy-cx*sz cx*cz*sy+sx*sz; cy*sz cx*cz+sx*sy*sz cx*sy*sz-cz*sx; -sy cy*sx cx*cy]; T = X(4:6); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [R,T] = eq_lmaPoint(q,p) Rx = @(a)[1 0 0; 0 cos(a) -sin(a); 0 sin(a) cos(a)]; Ry = @(b)[cos(b) 0 sin(b); 0 1 0; -sin(b) 0 cos(b)]; Rz = @(g)[cos(g) -sin(g) 0; sin(g) cos(g) 0; 0 0 1]; Rot = @(x)Rx(x(1))*Ry(x(2))*Rz(x(3)); myfun = @(x,xdata)Rot(x(1:3))*xdata+repmat(x(4:6),1,length(xdata)); options = optimset('Algorithm', 'levenberg-marquardt'); x = lsqcurvefit(myfun, zeros(6,1), p, q, [], [], options); R = Rot(x(1:3)); T = x(4:6); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Extrapolation in quaternion space. Details are found in: % % Besl, P., & McKay, N. (1992). A method for registration of 3-D shapes. % IEEE Transactions on pattern analysis and machine intelligence, 239?256. function [dv] = extrapolate(v,d,vmax) p1 = polyfit(v,d,1); % linear fit p2 = polyfit(v,d,2); % parabolic fit v1 = -p1(2)/p1(1); % linear zero crossing v2 = -p2(2)/(2*p2(1)); % polynomial top point if issorted([0 v2 v1 vmax]) || issorted([0 v2 vmax v1]) disp('Parabolic update!'); dv = v2; elseif issorted([0 v1 v2 vmax]) || issorted([0 v1 vmax v2])... || (v2 < 0 && issorted([0 v1 vmax])) disp('Line based update!'); dv = v1; elseif v1 > vmax && v2 > vmax disp('Maximum update!'); dv = vmax; else disp('No extrapolation!'); dv = 0; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Determine the RMS error between two point equally sized point clouds with % % point correspondance. % % ER = rms_error(p1,p2) where p1 and p2 are 3xn matrices. % % function ER = rms_error(p1,p2) % dsq = sum(power(p1 - p2, 2),1); % ER = sqrt(mean(dsq)); % end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Converts (orthogonal) rotation matrices R to (unit) quaternion % representations % % Input: A 3x3xn matrix of rotation matrices % Output: A 4xn matrix of n corresponding quaternions % % http://en.wikipedia.org/wiki/Rotation_matrix#Quaternion function quaternion = rmat2quat(R) Qxx = R(1,1,:); Qxy = R(1,2,:); Qxz = R(1,3,:); Qyx = R(2,1,:); Qyy = R(2,2,:); Qyz = R(2,3,:); Qzx = R(3,1,:); Qzy = R(3,2,:); Qzz = R(3,3,:); w = 0.5 * sqrt(1+Qxx+Qyy+Qzz); x = 0.5 * sign(Qzy-Qyz) .* sqrt(1+Qxx-Qyy-Qzz); y = 0.5 * sign(Qxz-Qzx) .* sqrt(1-Qxx+Qyy-Qzz); z = 0.5 * sign(Qyx-Qxy) .* sqrt(1-Qxx-Qyy+Qzz); quaternion = reshape([w;x;y;z],4,[]); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Converts (unit) quaternion representations to (orthogonal) rotation matrices R % % Input: A 4xn matrix of n quaternions % Output: A 3x3xn matrix of corresponding rotation matrices % % http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#From_a_quaternion_to_an_orthogonal_matrix function R = quat2rmat(quaternion) q0(1,1,:) = quaternion(1,:); qx(1,1,:) = quaternion(2,:); qy(1,1,:) = quaternion(3,:); qz(1,1,:) = quaternion(4,:); R = [q0.^2+qx.^2-qy.^2-qz.^2 2*qx.*qy-2*q0.*qz 2*qx.*qz+2*q0.*qy; 2*qx.*qy+2*q0.*qz q0.^2-qx.^2+qy.^2-qz.^2 2*qy.*qz-2*q0.*qx; 2*qx.*qz-2*q0.*qy 2*qy.*qz+2*q0.*qx q0.^2-qx.^2-qy.^2+qz.^2]; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Least squares normal estimation from point clouds using PCA % % H. Hoppe, T. DeRose, T. Duchamp, J. McDonald, and W. Stuetzle. % Surface reconstruction from unorganized points. % In Proceedings of ACM Siggraph, pages 71:78, 1992. % % p should be a matrix containing the horizontally concatenated column % vectors with points. k is a scalar indicating how many neighbors the % normal estimation is based upon. % % Note that for large point sets, the function performs significantly % faster if Statistics Toolbox >= v. 7.3 is installed. % % Jakob Wilm 2010 % function n = lsqnormest(p, k) % m = size(p,2); % n = zeros(3,m); % % v = ver('stats'); % if str2double(v.Version) >= 7.5 % neighbors = transpose(knnsearch(transpose(p), transpose(p), 'k', k+1)); % else % neighbors = k_nearest_neighbors(p, p, k+1); % end % % for i = 1:m % x = p(:,neighbors(2:end, i)); % p_bar = 1/k * sum(x,2); % % P = (x - repmat(p_bar,1,k)) * transpose(x - repmat(p_bar,1,k)); %spd matrix P % %P = 2*cov(x); % % [V,D] = eig(P); % % [xx, idx] = min(diag(D)); % choses the smallest eigenvalue % % n(:,i) = V(:,idx); % returns the corresponding eigenvector % end % end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Program to find the k - nearest neighbors (kNN) within a set of points. % % Distance metric used: Euclidean distance % % % % Note that this function makes repetitive use of min(), which seems to be % % more efficient than sort() for k < 30. % % function [neighborIds neighborDistances] = k_nearest_neighbors(dataMatrix, queryMatrix, k) % % numDataPoints = size(dataMatrix,2); % numQueryPoints = size(queryMatrix,2); % % neighborIds = zeros(k,numQueryPoints); % neighborDistances = zeros(k,numQueryPoints); % % D = size(dataMatrix, 1); %dimensionality of points % % for i=1:numQueryPoints % d=zeros(1,numDataPoints); % for t=1:D % this is to avoid slow repmat() % d=d+(dataMatrix(t,:)-queryMatrix(t,i)).^2; % end % for j=1:k % [s,t] = min(d); % neighborIds(j,i)=t; % neighborDistances(j,i)=sqrt(s); % d(t) = NaN; % remove found number from d % end % end % end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Boundary point determination. Given a set of 3D points and a % corresponding triangle representation, returns those point indices that % define the border/edge of the surface. function bound = find_bound(pts, poly) %Correcting polygon indices and converting datatype poly = double(poly); pts = double(pts); %Calculating freeboundary points: TR = TriRep(poly, pts(1,:)', pts(2,:)', pts(3,:)'); FF = freeBoundary(TR); %Output bound = FF(:,1); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
github
rising-turtle/slam_matlab-master
rms_error_normal.m
.m
slam_matlab-master/ground_truth_zh/icp/icp/rms_error_normal.m
277
utf_8
a1bfee1c1d3a829a0bb4f6882f8c5275
% Determine the RMS error between two point equally sized point clouds with % point correspondance. % ER = rms_error(p1,p2) where p1 and p2 are 3xn matrices. function ER = rms_error_normal(p1,p2,p1_normal) dsq = sum(power((p1 - p2).*p1_normal, 2),1); ER = sqrt(mean(dsq)); end
github
rising-turtle/slam_matlab-master
lsqnormest.m
.m
slam_matlab-master/ground_truth_zh/icp/icp/lsqnormest.m
1,162
utf_8
4ea5bbbdd9266bde1adffd19ecc5f10e
% Least squares normal estimation from point clouds using PCA % % H. Hoppe, T. DeRose, T. Duchamp, J. McDonald, and W. Stuetzle. % Surface reconstruction from unorganized points. % In Proceedings of ACM Siggraph, pages 71:78, 1992. % % p should be a matrix containing the horizontally concatenated column % vectors with points. k is a scalar indicating how many neighbors the % normal estimation is based upon. % % Note that for large point sets, the function performs significantly % faster if Statistics Toolbox >= v. 7.3 is installed. % % Jakob Wilm 2010 function n = lsqnormest(p, k) m = size(p,2); n = zeros(3,m); v = ver('stats'); if str2double(v.Version) >= 7.5 neighbors = transpose(knnsearch(transpose(p), transpose(p), 'k', k+1)); else neighbors = k_nearest_neighbors(p, p, k+1); end for i = 1:m x = p(:,neighbors(2:end, i)); p_bar = 1/k * sum(x,2); P = (x - repmat(p_bar,1,k)) * transpose(x - repmat(p_bar,1,k)); %spd matrix P %P = 2*cov(x); [V,D] = eig(P); [xx, idx] = min(diag(D)); % choses the smallest eigenvalue n(:,i) = V(:,idx); % returns the corresponding eigenvector end end
github
rising-turtle/slam_matlab-master
rms_error.m
.m
slam_matlab-master/ground_truth_zh/icp/icp/rms_error.m
247
utf_8
8ff81ab921610f97c536215259e9957a
% Determine the RMS error between two point equally sized point clouds with % point correspondance. % ER = rms_error(p1,p2) where p1 and p2 are 3xn matrices. function ER = rms_error(p1,p2) dsq = sum(power(p1 - p2, 2),1); ER = sqrt(mean(dsq)); end
github
rising-turtle/slam_matlab-master
k_nearest_neighbors.m
.m
slam_matlab-master/ground_truth_zh/icp/icp/k_nearest_neighbors.m
870
utf_8
461d1ce66128cf3312da2e03c4d373c7
% Program to find the k - nearest neighbors (kNN) within a set of points. % Distance metric used: Euclidean distance % % Note that this function makes repetitive use of min(), which seems to be % more efficient than sort() for k < 30. function [neighborIds neighborDistances] = k_nearest_neighbors(dataMatrix, queryMatrix, k) numDataPoints = size(dataMatrix,2); numQueryPoints = size(queryMatrix,2); neighborIds = zeros(k,numQueryPoints); neighborDistances = zeros(k,numQueryPoints); D = size(dataMatrix, 1); %dimensionality of points for i=1:numQueryPoints d=zeros(1,numDataPoints); for t=1:D % this is to avoid slow repmat() d=d+(dataMatrix(t,:)-queryMatrix(t,i)).^2; end for j=1:k [s,t] = min(d); neighborIds(j,i)=t; neighborDistances(j,i)=sqrt(s); d(t) = NaN; % remove found number from d end end end
github
rising-turtle/slam_matlab-master
icp.m
.m
slam_matlab-master/ground_truth_zh/icp/icp/icp.m
18,490
utf_8
0eafe0415df79a022b03af16bd28f313
function [TR, TT, ER, t] = icp(q,p,varargin) % Perform the Iterative Closest Point algorithm on three dimensional point % clouds. % % [TR, TT] = icp(q,p) returns the rotation matrix TR and translation % vector TT that minimizes the distances from (TR * p + TT) to q. % p is a 3xm matrix and q is a 3xn matrix. % % [TR, TT] = icp(q,p,k) forces the algorithm to make k iterations % exactly. The default is 10 iterations. % % [TR, TT, ER] = icp(q,p,k) also returns the RMS of errors for k % iterations in a (k+1)x1 vector. ER(0) is the initial error. % % [TR, TT, ER, t] = icp(q,p,k) also returns the calculation times per % iteration in a (k+1)x1 vector. t(0) is the time consumed for preprocessing. % % Additional settings may be provided in a parameter list: % % Boundary % {[]} | 1x? vector % If EdgeRejection is set, a vector can be provided that indexes into % q and specifies which points of q are on the boundary. % % EdgeRejection % {false} | true % If EdgeRejection is true, point matches to edge vertices of q are % ignored. Requires that boundary points of q are specified using % Boundary or that a triangulation matrix for q is provided. % % Extrapolation % {false} | true % If Extrapolation is true, the iteration direction will be evaluated % and extrapolated if possible using the method outlined by % Besl and McKay 1992. % % Matching % {bruteForce} | Delaunay | kDtree % Specifies how point matching should be done. % bruteForce is usually the slowest and kDtree is the fastest. % Note that the kDtree option is depends on the Statistics Toolbox % v. 7.3 or higher. % % Minimize % {point} | plane | lmaPoint % Defines whether point to point or point to plane minimization % should be performed. point is based on the SVD approach and is % usually the fastest. plane will often yield higher accuracy. It % uses linearized angles and requires surface normals for all points % in q. Calculation of surface normals requires substantial pre % proccessing. % The option lmaPoint does point to point minimization using the non % linear least squares Levenberg Marquardt algorithm. Results are % generally the same as in points, but computation time may differ. % % Normals % {[]} | n x 3 matrix % A matrix of normals for the n points in q might be provided. % Normals of q are used for point to plane minimization. % Else normals will be found through a PCA of the 4 nearest % neighbors. % % ReturnAll % {false} | true % Determines whether R and T should be returned for all iterations % or only for the last one. If this option is set to true, R will be % a 3x3x(k+1) matrix and T will be a 3x1x(k+1) matrix. % % Triangulation % {[]} | ? x 3 matrix % A triangulation matrix for the points in q can be provided, % enabling EdgeRejection. The elements should index into q, defining % point triples that act together as triangles. % % Verbose % {false} | true % Enables extrapolation output in the Command Window. % % Weight % {@(match)ones(1,m)} | Function handle % For point or plane minimization, a function handle to a weighting % function can be provided. The weighting function will be called % with one argument, a 1xm vector that specifies point pairs by % indexing into q. The weighting function should return a 1xm vector % of weights for every point pair. % % WorstRejection % {0} | scalar in ]0; 1[ % Reject a given percentage of the worst point pairs, based on their % Euclidean distance. % % Martin Kjer and Jakob Wilm, Technical University of Denmark, 2012 % Use the inputParser class to validate input arguments. inp = inputParser; inp.addRequired('q', @(x)isreal(x) && size(x,1) == 3); inp.addRequired('p', @(x)isreal(x) && size(x,1) == 3); inp.addOptional('iter', 10, @(x)x > 0 && x < 10^5); inp.addParamValue('Boundary', [], @(x)size(x,1) == 1); inp.addParamValue('EdgeRejection', false, @(x)islogical(x)); inp.addParamValue('Extrapolation', false, @(x)islogical(x)); validMatching = {'bruteForce','Delaunay','kDtree'}; inp.addParamValue('Matching', 'bruteForce', @(x)any(strcmpi(x,validMatching))); validMinimize = {'point','plane','lmapoint'}; inp.addParamValue('Minimize', 'point', @(x)any(strcmpi(x,validMinimize))); inp.addParamValue('Normals', [], @(x)isreal(x) && size(x,1) == 3); inp.addParamValue('NormalsData', [], @(x)isreal(x) && size(x,1) == 3); inp.addParamValue('ReturnAll', false, @(x)islogical(x)); inp.addParamValue('Triangulation', [], @(x)isreal(x) && size(x,2) == 3); inp.addParamValue('Verbose', false, @(x)islogical(x)); inp.addParamValue('Weight', @(x)ones(1,length(x)), @(x)isa(x,'function_handle')); inp.addParamValue('WorstRejection', 0, @(x)isscalar(x) && x > 0 && x < 1); inp.parse(q,p,varargin{:}); arg = inp.Results; clear('inp'); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Actual implementation % Allocate vector for RMS of errors in every iteration. t = zeros(arg.iter+1,1); % Start timer tic; Np = size(p,2); % Transformed data point cloud pt = p; % Allocate vector for RMS of errors in every iteration. ER = zeros(arg.iter+1,1); % Initialize temporary transform vector and matrix. T = zeros(3,1); R = eye(3,3); % Initialize total transform vector(s) and rotation matric(es). TT = zeros(3,1, arg.iter+1); TR = repmat(eye(3,3), [1,1, arg.iter+1]); % If Minimize == 'plane', normals are needed if (strcmp(arg.Minimize, 'plane') && isempty(arg.Normals)) arg.Normals = lsqnormest(q,4); end % If Matching == 'Delaunay', a triangulation is needed if strcmp(arg.Matching, 'Delaunay') DT = DelaunayTri(transpose(q)); end % If Matching == 'kDtree', a kD tree should be built (req. Stat. TB >= 7.3) if strcmp(arg.Matching, 'kDtree') kdOBJ = KDTreeSearcher(transpose(q)); end % If edge vertices should be rejected, find edge vertices if arg.EdgeRejection if isempty(arg.Boundary) bdr = find_bound(q, arg.Triangulation); else bdr = arg.Boundary; end end if arg.Extrapolation % Initialize total transform vector (quaternion ; translation vec.) qq = [ones(1,arg.iter+1);zeros(6,arg.iter+1)]; % Allocate vector for direction change and change angle. dq = zeros(7,arg.iter+1); theta = zeros(1,arg.iter+1); end t(1) = toc; % Go into main iteration loop for k=1:arg.iter % Do matching switch arg.Matching case 'bruteForce' [match mindist] = match_bruteForce(q,pt); case 'Delaunay' [match mindist] = match_Delaunay(q,pt,DT); case 'kDtree' [match mindist] = match_kDtree(q,pt,kdOBJ); end % If matches to edge vertices should be rejected if arg.EdgeRejection p_idx = not(ismember(match, bdr)); q_idx = match(p_idx); mindist = mindist(p_idx); else p_idx = true(1, Np); q_idx = match; end % If worst matches should be rejected if arg.WorstRejection edge = round((1-arg.WorstRejection)*sum(p_idx)); pairs = find(p_idx); [xx, idx] = sort(mindist); p_idx(pairs(idx(edge:end))) = false; q_idx = match(p_idx); mindist = mindist(p_idx); end if k == 1 ER(k) = sqrt(sum(mindist.^2)/length(mindist)); end switch arg.Minimize case 'point' % Determine weight vector weights = arg.Weight(match); [R,T] = eq_point(q(:,q_idx),pt(:,p_idx), weights(p_idx)); case 'plane' weights = arg.Weight(match); [R,T] = eq_plane(q(:,q_idx),pt(:,p_idx),arg.Normals(:,q_idx),weights(p_idx)); case 'lmaPoint' [R,T] = eq_lmaPoint(q(:,q_idx),pt(:,p_idx)); end % Add to the total transformation TR(:,:,k+1) = R*TR(:,:,k); TT(:,:,k+1) = R*TT(:,:,k)+T; % Apply last transformation pt = TR(:,:,k+1) * p + repmat(TT(:,:,k+1), 1, Np); % Root mean of objective function ER(k+1) = rms_error(q(:,q_idx), pt(:,p_idx)); % If Extrapolation, we might be able to move quicker if arg.Extrapolation qq(:,k+1) = [rmat2quat(TR(:,:,k+1));TT(:,:,k+1)]; dq(:,k+1) = qq(:,k+1) - qq(:,k); theta(k+1) = (180/pi)*acos(dot(dq(:,k),dq(:,k+1))/(norm(dq(:,k))*norm(dq(:,k+1)))); if arg.Verbose disp(['Direction change ' num2str(theta(k+1)) ' degree in iteration ' num2str(k)]); end if k>2 && theta(k+1) < 10 && theta(k) < 10 d = [ER(k+1), ER(k), ER(k-1)]; v = [0, -norm(dq(:,k+1)), -norm(dq(:,k))-norm(dq(:,k+1))]; vmax = 25 * norm(dq(:,k+1)); dv = extrapolate(v,d,vmax); if dv ~= 0 q_mark = qq(:,k+1) + dv * dq(:,k+1)/norm(dq(:,k+1)); q_mark(1:4) = q_mark(1:4)/norm(q_mark(1:4)); qq(:,k+1) = q_mark; TR(:,:,k+1) = quat2rmat(qq(1:4,k+1)); TT(:,:,k+1) = qq(5:7,k+1); % Reapply total transformation pt = TR(:,:,k+1) * p + repmat(TT(:,:,k+1), 1, Np); % Recalculate root mean of objective function % Note this is costly and only for fun! switch arg.Matching case 'bruteForce' [xx, mindist] = match_bruteForce(q,pt); case 'Delaunay' [xx, mindist] = match_Delaunay(q,pt,DT); case 'kDtree' [xx, mindist] = match_kDtree(q,pt,kdOBJ); end ER(k+1) = sqrt(sum(mindist.^2)/length(mindist)); end end end t(k+1) = toc; end if not(arg.ReturnAll) TR = TR(:,:,end); TT = TT(:,:,end); end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [match mindist] = match_bruteForce(q, p) m = size(p,2); n = size(q,2); match = zeros(1,m); mindist = zeros(1,m); for ki=1:m d=zeros(1,n); for ti=1:3 d=d+(q(ti,:)-p(ti,ki)).^2; end [mindist(ki),match(ki)]=min(d); end mindist = sqrt(mindist); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [match mindist] = match_Delaunay(q, p, DT) match = transpose(nearestNeighbor(DT, transpose(p))); mindist = sqrt(sum((p-q(:,match)).^2,1)); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [match mindist] = match_kDtree(xx, p, kdOBJ) [match mindist] = knnsearch(kdOBJ,transpose(p)); match = transpose(match); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [R,T] = eq_point(q,p,weights) m = size(p,2); n = size(q,2); % normalize weights weights = weights ./ sum(weights); % find data centroid and deviations from centroid q_bar = q * transpose(weights); q_mark = q - repmat(q_bar, 1, n); % Apply weights q_mark = q_mark .* repmat(weights, 3, 1); % find data centroid and deviations from centroid p_bar = p * transpose(weights); p_mark = p - repmat(p_bar, 1, m); % Apply weights %p_mark = p_mark .* repmat(weights, 3, 1); N = p_mark*transpose(q_mark); % taking points of q in matched order [U,xx,V] = svd(N); % singular value decomposition R = V*transpose(U); T = q_bar - R*p_bar; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [R,T] = eq_plane(q,p,n,weights) n = n .* repmat(weights,3,1); c = cross(p,n); cn = vertcat(c,n); C = cn*transpose(cn); b = - [sum(sum((p-q).*repmat(cn(1,:),3,1).*n)); sum(sum((p-q).*repmat(cn(2,:),3,1).*n)); sum(sum((p-q).*repmat(cn(3,:),3,1).*n)); sum(sum((p-q).*repmat(cn(4,:),3,1).*n)); sum(sum((p-q).*repmat(cn(5,:),3,1).*n)); sum(sum((p-q).*repmat(cn(6,:),3,1).*n))]; X = C\b; cx = cos(X(1)); cy = cos(X(2)); cz = cos(X(3)); sx = sin(X(1)); sy = sin(X(2)); sz = sin(X(3)); R = [cy*cz cz*sx*sy-cx*sz cx*cz*sy+sx*sz; cy*sz cx*cz+sx*sy*sz cx*sy*sz-cz*sx; -sy cy*sx cx*cy]; T = X(4:6); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [R,T] = eq_lmaPoint(q,p) Rx = @(a)[1 0 0; 0 cos(a) -sin(a); 0 sin(a) cos(a)]; Ry = @(b)[cos(b) 0 sin(b); 0 1 0; -sin(b) 0 cos(b)]; Rz = @(g)[cos(g) -sin(g) 0; sin(g) cos(g) 0; 0 0 1]; Rot = @(x)Rx(x(1))*Ry(x(2))*Rz(x(3)); myfun = @(x,xdata)Rot(x(1:3))*xdata+repmat(x(4:6),1,length(xdata)); options = optimset('Algorithm', 'levenberg-marquardt'); x = lsqcurvefit(myfun, zeros(6,1), p, q, [], [], options); R = Rot(x(1:3)); T = x(4:6); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Extrapolation in quaternion space. Details are found in: % % Besl, P., & McKay, N. (1992). A method for registration of 3-D shapes. % IEEE Transactions on pattern analysis and machine intelligence, 239?256. function [dv] = extrapolate(v,d,vmax) p1 = polyfit(v,d,1); % linear fit p2 = polyfit(v,d,2); % parabolic fit v1 = -p1(2)/p1(1); % linear zero crossing v2 = -p2(2)/(2*p2(1)); % polynomial top point if issorted([0 v2 v1 vmax]) || issorted([0 v2 vmax v1]) disp('Parabolic update!'); dv = v2; elseif issorted([0 v1 v2 vmax]) || issorted([0 v1 vmax v2])... || (v2 < 0 && issorted([0 v1 vmax])) disp('Line based update!'); dv = v1; elseif v1 > vmax && v2 > vmax disp('Maximum update!'); dv = vmax; else disp('No extrapolation!'); dv = 0; end end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Determine the RMS error between two point equally sized point clouds with % % point correspondance. % % ER = rms_error(p1,p2) where p1 and p2 are 3xn matrices. % % function ER = rms_error(p1,p2) % dsq = sum(power(p1 - p2, 2),1); % ER = sqrt(mean(dsq)); % end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Converts (orthogonal) rotation matrices R to (unit) quaternion % representations % % Input: A 3x3xn matrix of rotation matrices % Output: A 4xn matrix of n corresponding quaternions % % http://en.wikipedia.org/wiki/Rotation_matrix#Quaternion function quaternion = rmat2quat(R) Qxx = R(1,1,:); Qxy = R(1,2,:); Qxz = R(1,3,:); Qyx = R(2,1,:); Qyy = R(2,2,:); Qyz = R(2,3,:); Qzx = R(3,1,:); Qzy = R(3,2,:); Qzz = R(3,3,:); w = 0.5 * sqrt(1+Qxx+Qyy+Qzz); x = 0.5 * sign(Qzy-Qyz) .* sqrt(1+Qxx-Qyy-Qzz); y = 0.5 * sign(Qxz-Qzx) .* sqrt(1-Qxx+Qyy-Qzz); z = 0.5 * sign(Qyx-Qxy) .* sqrt(1-Qxx-Qyy+Qzz); quaternion = reshape([w;x;y;z],4,[]); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Converts (unit) quaternion representations to (orthogonal) rotation matrices R % % Input: A 4xn matrix of n quaternions % Output: A 3x3xn matrix of corresponding rotation matrices % % http://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation#From_a_quaternion_to_an_orthogonal_matrix function R = quat2rmat(quaternion) q0(1,1,:) = quaternion(1,:); qx(1,1,:) = quaternion(2,:); qy(1,1,:) = quaternion(3,:); qz(1,1,:) = quaternion(4,:); R = [q0.^2+qx.^2-qy.^2-qz.^2 2*qx.*qy-2*q0.*qz 2*qx.*qz+2*q0.*qy; 2*qx.*qy+2*q0.*qz q0.^2-qx.^2+qy.^2-qz.^2 2*qy.*qz-2*q0.*qx; 2*qx.*qz-2*q0.*qy 2*qy.*qz+2*q0.*qx q0.^2-qx.^2-qy.^2+qz.^2]; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Least squares normal estimation from point clouds using PCA % % H. Hoppe, T. DeRose, T. Duchamp, J. McDonald, and W. Stuetzle. % Surface reconstruction from unorganized points. % In Proceedings of ACM Siggraph, pages 71:78, 1992. % % p should be a matrix containing the horizontally concatenated column % vectors with points. k is a scalar indicating how many neighbors the % normal estimation is based upon. % % Note that for large point sets, the function performs significantly % faster if Statistics Toolbox >= v. 7.3 is installed. % % Jakob Wilm 2010 % function n = lsqnormest(p, k) % m = size(p,2); % n = zeros(3,m); % % v = ver('stats'); % if str2double(v.Version) >= 7.5 % neighbors = transpose(knnsearch(transpose(p), transpose(p), 'k', k+1)); % else % neighbors = k_nearest_neighbors(p, p, k+1); % end % % for i = 1:m % x = p(:,neighbors(2:end, i)); % p_bar = 1/k * sum(x,2); % % P = (x - repmat(p_bar,1,k)) * transpose(x - repmat(p_bar,1,k)); %spd matrix P % %P = 2*cov(x); % % [V,D] = eig(P); % % [xx, idx] = min(diag(D)); % choses the smallest eigenvalue % % n(:,i) = V(:,idx); % returns the corresponding eigenvector % end % end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Program to find the k - nearest neighbors (kNN) within a set of points. % % Distance metric used: Euclidean distance % % % % Note that this function makes repetitive use of min(), which seems to be % % more efficient than sort() for k < 30. % % function [neighborIds neighborDistances] = k_nearest_neighbors(dataMatrix, queryMatrix, k) % % numDataPoints = size(dataMatrix,2); % numQueryPoints = size(queryMatrix,2); % % neighborIds = zeros(k,numQueryPoints); % neighborDistances = zeros(k,numQueryPoints); % % D = size(dataMatrix, 1); %dimensionality of points % % for i=1:numQueryPoints % d=zeros(1,numDataPoints); % for t=1:D % this is to avoid slow repmat() % d=d+(dataMatrix(t,:)-queryMatrix(t,i)).^2; % end % for j=1:k % [s,t] = min(d); % neighborIds(j,i)=t; % neighborDistances(j,i)=sqrt(s); % d(t) = NaN; % remove found number from d % end % end % end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Boundary point determination. Given a set of 3D points and a % corresponding triangle representation, returns those point indices that % define the border/edge of the surface. function bound = find_bound(pts, poly) %Correcting polygon indices and converting datatype poly = double(poly); pts = double(pts); %Calculating freeboundary points: TR = TriRep(poly, pts(1,:)', pts(2,:)', pts(3,:)'); FF = freeBoundary(TR); %Output bound = FF(:,1); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
github
rising-turtle/slam_matlab-master
sampling_vro.m
.m
slam_matlab-master/ground_truth_zh/Localization/sampling_vro.m
1,168
utf_8
6034c6abcaf471707991c8ae56168921
% Sampling VRO with interval % % Author : Soonhac Hong ([email protected]) % Date : 12/13/13 function sampling_vro() % Load data file_name = '498_frame_abs_intensity_sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc_20st_gaussian_0.dat'; vro = load(file_name); % Sample VRO with interval interval = 15; new_vro=[]; vro_idx = 1; success_flag = 1; while vro_idx <= (max(vro(:,1))-interval) idx = find(vro(:,1)==vro_idx & vro(:,2) == (vro_idx+interval)); if ~isempty(idx) new_vro=[new_vro; vro(idx,:)]; vro_idx = vro_idx+interval; else success_flag = 0; disp('Faile to sample vro results'); break; end end % Write results if success_flag == 1 output_file_name = sprintf('result\\object_recognition\\indoor_monitor_1\\498_frame_abs_intensity_sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc_20st_gaussian_0_monitor1_s%d.dat', interval); output_fd = fopen(output_file_name,'w'); fprintf(output_fd,'%d %d %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n', new_vro'); fclose(output_fd); end end
github
rising-turtle/slam_matlab-master
load_pose_std.m
.m
slam_matlab-master/ground_truth_zh/Localization/load_pose_std.m
1,367
utf_8
329d9ca060491048ca17bf713699f70a
% Load matched points from a file % % Author : Soonhac Hong ([email protected]) % Date : 3/11/2013 function [pose_std] = load_pose_std(data_name, dm, first_cframe, second_cframe, isgframe, sequence_data) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true if strcmp(data_name, 'object_recognition') dataset_dir = strrep(prefix, '/f1',''); else dataset_dir = strrep(prefix, '/d1',''); end if strcmp(isgframe, 'gframe') file_name = sprintf('%s/pose_std_gframe/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); else file_name = sprintf('%s/pose_std/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); end else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); if strcmp(isgframe, 'gframe') file_name = sprintf('%s/pose_std_gframe/d1_%04d_d%d_%04d.mat',dataset_dir, first_cframe, dm, second_cframe); else file_name = sprintf('%s/pose_std/d1_%04d_d%d_%04d.mat',dataset_dir, first_cframe, dm, second_cframe); end end % if strcmp(isgframe, 'gframe') % file_name = sprintf('%s/matched_points_gframe/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); % else % file_name = sprintf('%s/matched_points/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); % end load(file_name); end
github
rising-turtle/slam_matlab-master
compute_pose_std.m
.m
slam_matlab-master/ground_truth_zh/Localization/compute_pose_std.m
1,000
utf_8
92a7ecfe7741a125b61cc27344fc802d
% Compute covariance of vro % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % % Reference : [cov_pose_shift,q_dpose,T_dpose] = bootstrap_cov_calc(idx1,idx2) % function [pose_std] = compute_pose_std(op_pset1,op_pset2,rot_mean, trans_mean) nData = size(op_pset1,2); sampleSize = min(40,floor(0.75*nData)); nSamplePossible = factorial(nData)/(factorial(sampleSize)*factorial(nData - sampleSize)); nSample = min(50,nSamplePossible); pose_std_total=[]; [phi_mean, theta_mean, psi_mean] = rot_to_euler(rot_mean); pose_mean = [phi_mean, theta_mean, psi_mean, trans_mean']; legitSamples = 0; for i=1:nSample idxRand = randsample(1:size(op_pset1,2),sampleSize); [rot, trans, sta] = find_transform_matrix(op_pset1(:,idxRand), op_pset2(:,idxRand)); [phi, theta, psi] = rot_to_euler(rot); pose_std_total(i,:) = [phi, theta, psi, trans']; end %pose_std = std(pose_std_total); pose_std = sqrt((sum((pose_std_total - repmat(pose_mean, nSample, 1)).^2))/(nSample-1)); end
github
rising-turtle/slam_matlab-master
plot3D_SR4000.m
.m
slam_matlab-master/ground_truth_zh/Localization/plot3D_SR4000.m
3,960
utf_8
1fa97498efe83036ca0b2f13f56ec8b3
% Each .dat file is a data frame captured from the camera. It contains five 2-D arrays each of which % represent z (Calibrated Distance), x (Calibrated xVector), y (Calibrated xVector), Amplitude, and Confidence Map. % The following code read and render the Amplitude (intensity) image. % Add showing the depth image % Author : Soonhac Hong ([email protected]) % Date : 3/8/2011 %function plot3D_SR4000(data_name,filter_name, boarder_cut_off,dir_index) function plot3D_SR4000(data_name,dir_index) addpath('..\freezeColors'); filter_name = 'gaussian'; boarder_cut_off = 0; % switch data_name % case 'pitch' % dir_name = sprintf('../data/pitch_3_interval/d%d_-%d/d%d',dir_index,43-dir_index*3,dir_index); % case 'pan' % dir_name = sprintf('../data/pan_3_interval/d%d_%d/d%d',dir_index,44-(dir_index-1)*3,dir_index); % case 'x' % dir_name = sprintf('../data/x/x%d/frm',dir_index); % case 'y' % dir_name = sprintf('../data/y/y%d/frm',dir_index); % otherwise % disp('Data cannot be found'); % return; % end %figure; scale = 1; value_type = 'int'; %figure; j = 0; %30 %[nFrame, vro_size, pose_size, vro_icp_size, pose_vro_icp_size, vro_icp_ch_size, pose_vro_icp_ch_size] = get_nframe_nvro_npose(14, dir_index); % [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dir_index); % vidObj = VideoWriter(sprintf('%s.avi', prefix)); % open(vidObj); %loops2_nFrame_list = [830 582 830 832 649 930 479 580 699 458 368 239]; previous_rtime = []; first_frame =440; last_frame = 700; interval = 1; for i=first_frame:interval:last_frame %1:1:nFrame%700:1000 i %[img, x, y, z, c, rtime] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dir_index, i, scale, value_type); %LoadSR(data_name, dir_index, i); %[img, x, y, z, c, rtime, time_stamp, prefix] = LoadSR_no_bpc_time(data_name, filter_name, boarder_cut_off, dir_index, i, scale, value_type); %[img, x, y, z, c, rtime] = LoadSR_no_bpc_time_single(data_name, filter_name, boarder_cut_off, dir_index, i, scale, value_type); [img, x, y, z, c, rtime] = LoadSR_no_bpc_time_single_binary(data_name, filter_name, boarder_cut_off, dir_index, i, scale, value_type); %[img, x, y, z, c, rtime] = LoadSR_wobpc(data_name, filter_name, boarder_cut_off, dir_index, i, scale, value_type); % fw=1; % a = load('sample/sample_sr4000_0001.dat'); % elapsed time := 0.2 sec % k=144*3+1; % img = double(a(k:k+143, :)); % z = a(1:144, :); x = a(145:288, :); y = a(289:144*3, :); % z = medfilt2(z,[fw fw]); x = medfilt2(x, [fw fw]); y = medfilt2(y, [fw fw]); %subplot(1,2,1); figure(1); %j = j + 1; %subplot(1,4,j); % subplot(2,2,1); imagesc(img); colormap(gray); axis image; set(gca,'XTick',[]); set(gca,'YTick',[]); %title('Intensity Image'); %['frame ', int2str(i)]); % if i==first_frame % title(sprintf('frame %d', i)); %'Frame %d', 2)); % else % title(sprintf('frame %d (%4.2f [msec/frame])', i, abs(time_stamp-previous_rtime(end)))); %'Frame %d', 2)); % end % % previous_rtime = [previous_rtime; time_stamp]; % currFrame = getframe; % writeVideo(vidObj,currFrame); % freezeColors; % Don't chage the previous sub plots % figure(2); % subplot(2,2,2); % imagesc(z);colormap(jet); colorbar(); % %title('Range Image'); % axis image; %colorbar() % set(gca,'XTick',[]); % set(gca,'YTick',[]); % subplot(2,2,3);imagesc(x);colormap(jet);axis image; colorbar();title('X Image'); % subplot(2,2,4);imagesc(y);colormap(jet);axis image; colorbar();title('Y Image'); % figure; % plot3(x,y,z,'b.'); % surf(x,y,z); % imagesc(c);colormap(jet); colorbar(); title('Confidence Image'); drawnow; end % close(vidObj); figure; plot(diff(previous_rtime),'.-'); ylabel('Time per frame'); xlabel('Frame'); grid; end
github
rising-turtle/slam_matlab-master
get_swing_filename.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_swing_filename.m
515
utf_8
81d7d419d6b297f2c3a4b164c679583b
% Get directory name of motive datasets % % Author : Soonhac Hong ([email protected]) % Date : 11/20/13 function motive_filename_lists=get_swing_filename() motive_filename_lists = {'forward1','forward2','forward3','forward4','forward5','forward6','forward7','forward8', 'forward9','forward10','forward11','forward12','forward13','forward14','forward15','forward16','revisiting1','revisiting2','revisiting3','revisiting4','revisiting5','revisiting6','revisiting7','revisiting8','revisiting9','revisiting10'}; end
github
rising-turtle/slam_matlab-master
save_visual_features.m
.m
slam_matlab-master/ground_truth_zh/Localization/save_visual_features.m
1,181
utf_8
ba22c81ae039ca48c4065d21de093e35
% Save sift visual feature into a file % % Author : Soonhac Hong ([email protected]) % Date : 2/13/2013 function save_visual_features(data_name, dm, cframe, frm, des, elapsed_sift, img, x, y, z, c, elapsed_pre, sequence_data, image_name) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true if strcmp(data_name, 'object_recognition') dataset_dir = strrep(prefix, '/f1',''); else dataset_dir = strrep(prefix, '/d1',''); end if strcmp(image_name, 'depth') file_name = sprintf('%s/depth_feature/d1_%04d.mat',dataset_dir, cframe); else file_name = sprintf('%s/visual_feature/d1_%04d.mat',dataset_dir, cframe); end else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); if strcmp(image_name, 'depth') file_name = sprintf('%s/depth_feature/d%d_%04d.mat',dataset_dir, dm, cframe); else file_name = sprintf('%s/visual_feature/d%d_%04d.mat',dataset_dir, dm, cframe); end end %file_name = sprintf('%s/visual_feature/d1_%04d.mat',dataset_dir, cframe); save(file_name, 'frm', 'des', 'elapsed_sift', 'img', 'x', 'y', 'z', 'c', 'elapsed_pre'); end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_cov_fast_fast.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_cov_fast_fast.m
16,231
utf_8
84b24dd4aa8859f73260befb87e72c1e
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_cov_fast_fast(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, dis) if nargin < 13 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data cframe = sframe; else cframe = j; end first_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe); end %Read second Data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe); end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe, 'none') == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2, 'none'); else [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, 'none'); t_svd = tic; end [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta == 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
scale_img.m
.m
slam_matlab-master/ground_truth_zh/Localization/scale_img.m
871
utf_8
d55161e3ee78642f5867dc40bdcc1d82
% Scale and smoothing image % % Parameters % img : input image % fw : the size of median filter % % Author : Soonhac Hong ([email protected]) % Date : 4/21/11 function [img] = scale_img(img, fw, value_type, data_type) [m, n, v] = find (img>65000); %???? imgt=img; num=size(m,1); for kk=1:num imgt(m(kk), n(kk))=0; end imax=max(max(imgt)); for kk=1:num img(m(kk),n(kk))=imax; end % img=uint8(sqrt(img).*255./sqrt(max(max(img)))); if strcmp(data_type, 'intensity') img=sqrt(img).*255./sqrt(max(max(img))); %This line degrade the performance of SURF elseif strcmp(data_type, 'range') img_max = max(max(img)); if img_max <= 5.0 img_max = 5.0; end img=sqrt(abs(img)).*255./sqrt(img_max); %This line degrade the performance of SURF end if strcmp(value_type, 'int') img = uint8(img); end % img=medfilt2(img, [fw fw]); end
github
rising-turtle/slam_matlab-master
compensate_badpixel.m
.m
slam_matlab-master/ground_truth_zh/Localization/compensate_badpixel.m
1,844
utf_8
f28d56efdbf5d1e06c25dd3f07945a90
% Compenstate the bad pixel with low confidence by median filter % Date : 3/13/12 % Author : Soonhac Hong ([email protected]) function [img, x, y, z, c] = compensate_badpixel(img, x, y, z, c, confidence_cut_off) e_index = c < confidence_cut_off; for i = 1:size(img,1) % row for j=1:size(img,2) % column if e_index(i,j) == 1 start_i = i-1; end_i = i+1; start_j = j-1; end_j = j+1; point_i = 2; point_j = 2; if i == 1 start_i = i; point_i = 1; if j == 1 point_j = 1; end end if i == size(img,1) end_i = i; if j == 1 point_j = 1; end end if j == 1 start_j = j; if i == 1 point_i = 1; end end if j == size(img,2) end_j = j; if i == 1 point_i = 1; end end img_unit=medfilt2(img(start_i:end_i,start_j:end_j), [3 3],'symmetric'); x_unit=medfilt2(x(start_i:end_i,start_j:end_j), [3 3],'symmetric'); y_unit=medfilt2(y(start_i:end_i,start_j:end_j), [3 3],'symmetric'); z_unit=medfilt2(z(start_i:end_i,start_j:end_j), [3 3],'symmetric'); img(i,j) = img_unit(point_i,point_j); x(i,j) = x_unit(point_i,point_j); y(i,j) = y_unit(point_i,point_j); z(i,j) = z_unit(point_i,point_j); end end end end
github
rising-turtle/slam_matlab-master
check_stored_depth_feature.m
.m
slam_matlab-master/ground_truth_zh/Localization/check_stored_depth_feature.m
812
utf_8
a037ad501e066d47ebf04737a0196091
% Check if there is the stored visual feature % % Author : Soonhac Hong ([email protected]) % Date : 2/13/2013 function [exist_flag] = check_stored_depth_feature(data_name, dm, cframe) exist_flag = 0; [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); dataset_dir = strrep(prefix, '/d1',''); dataset_dir = sprintf('%s/depth_feature',dataset_dir); file_name = sprintf('d1_%04d.mat',cframe); dirData = dir(dataset_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; if isempty(file_list) return; else for i=1:size(file_list,1) if strcmp(file_list{i}, file_name) exist_flag = 1; break; end end end dirData=[]; dirIndex=[]; file_list=[]; end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_icp2_cov_fast.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_icp2_cov_fast.m
17,406
utf_8
b03f8f6fe4f24a2e9865f15785efe46f
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 8/30/12 function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_icp2_cov_fast(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, icp_mode, dis) if nargin < 14 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') % Dynamic data cframe = sframe; else cframe = j; end if check_stored_visual_feature(data_name, dm, cframe) == 0 [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); %[frm1,des1] = vl_sift(single(img1)) ; else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe); end %Read second Data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature')% Dynamic data %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end if check_stored_visual_feature(data_name, dm, cframe) == 0 [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); %[frm2,des2] = vl_sift(single(img2)) ; else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe); end %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %[match, scores] = vl_ubcmatch(des1,des2) ; %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 match_new = []; cnt_new = 1; pnum = size(match, 2); if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if img1(ROW1, COL1) >= 0 && img2(ROW2, COL2) >= 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; % stdev_threshold = 0.1; % stdev_count = 0; % count_threshold = 15; % mean_threshold = 0.1; % mean_count = 0; % window_size = 30; % debug_data=[]; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % if cnum >= valid_ransac % break; % end % if cnum/pnum >= inlier_ratio % break; % enddynamic_data_index % total_cnum(i)=cnum; % if i > window_size && inliers_std ~= 0 % inliers_std_prev = inliers_std; % inliers_std = std(total_cnum(i-window_size:i)); %Moving STDEV % inliers_std_delta = abs(inliers_std - inliers_std_prev)/inliers_std_prev; % % inliers_mean_prev = inliers_mean; % inliers_mean = mean(total_cnum(i-window_size:i)); %Moving STDEV % inliers_mean_delta = abs(inliers_mean - inliers_mean_prev)/inliers_mean_prev; % % if inliers_std_delta < stdev_threshold % stdev_count = stdev_count + 1; % else % stdev_count = 0; % end % % if inliers_mean_delta < mean_threshold % mean_count = mean_count + 1; % else % mean_count = 0; % end % % inlier_ratio = max(total_cnum)/pnum; % % count_threshold = 120000 / ((inlier_ratio*100)^2); %-26 * (inlier_ratio*100 - 20) + 800; % % if stdev_count > count_threshold %&& mean_count > count_threshold % break; % end % else % inliers_std = std(total_cnum); % inliers_mean = mean(total_cnum); % end if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1 break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %% Run SVD %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Test LM %[rot_lm, trans_lm] = lm_point(op_pset1, op_pset2); % [rot_lm, trans_lm] = lm_point2plane(op_pset1, op_pset2); % [phi_lm, theta_lm, psi_lm] = rot_to_euler(rot_lm); % [theta*180/pi theta_lm*180/pi] % [phi*180/pi phi_lm*180/pi] % [psi*180/pi psi_lm*180/pi] % Save feature points %feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; % Compute RMSE op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse = rmse + unit_rmse; % end % rmse_feature = rmse / size(op_pset1,2); %rmse_feature = rms_error(op_pset1, op_pset2_transed); % Show correspondent points % plot3(op_pset1(1,:),op_pset1(2,:),op_pset1(3,:),'b*-'); % hold on; % plot3(op_pset2(1,:),op_pset2(2,:),op_pset2(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; %Compute the elapsed time %rt_total = etime(clock,t); %elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; %% Run ICP %[phi_icp, theta_icp, psi_icp, trans_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_2(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_3(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_4(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_5(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); if strcmp(icp_mode, 'icp_ch') [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); else [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_6_cov(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); end %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_10(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_13(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %Check status of SVD if sta_icp == 0 || error ~= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta_icp == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %elapsed_icp = toc(t_icp); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; %rot = rot_icp; % [rmse_feature rmse_icp] % [theta*180/pi theta_icp*180/pi] % [trans(1) trans_icp(1)] %if rmse_icp <= rmse_feature trans = trans_icp; phi = phi_icp; theta = theta_icp; psi = psi_icp; %end %convert degree % r2d=180.0/pi; % phi=phi*r2d; % theta=theta*r2d; % psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
LoadKinect_depthbased.m
.m
slam_matlab-master/ground_truth_zh/Localization/LoadKinect_depthbased.m
2,589
utf_8
eda775a4e73610c0ffdbdb3d7c327da6
% Load data from Kinect % % Parameters % data_name : the directory name of data % dm : index of directory of data % j : index of frame % % Author : Soonhac Hong ([email protected]) % Date : 4/20/11 function [img, X, Y, Z, rtime, depth_time_stamp] = LoadKinect_depthbased(dm, j) t_load = tic; dir_name_list = get_kinect_tum_dir_name(); dir_name = dir_name_list{dm}; % Load depth image [depth_data_dir, err] = sprintf('D:/Soonhac/Data/kinect_tum/%s/depth',dir_name); dirData = dir(depth_data_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; [file_name_full, err]=sprintf('%s/%s',depth_data_dir,file_list{j}); [file_name, err] = sprintf('%s',file_list{j}); depth_time_stamp = str2double(strrep(file_name, '.png','')); depth_img = imread(file_name_full); %figure;imshow(depth_img); depth_img = double(depth_img); [rgb_data_dir, err] = sprintf('D:/Soonhac/Data/kinect_tum/%s/rgb',dir_name); dirData = dir(rgb_data_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; for i=1:size(file_list,1) [color_file_name, err]=sprintf('%s',file_list{i}); color_time_stamp(i,1) = str2double(strrep(color_file_name, '.png','')); end % find nearest tiem stamp of color image color_file_nearest_index = find(color_time_stamp > depth_time_stamp, 1); if color_file_nearest_index ~= 1 && ((color_time_stamp(color_file_nearest_index,1) - depth_time_stamp) > (depth_time_stamp - color_time_stamp(color_file_nearest_index-1,1))) color_file_nearest_index = color_file_nearest_index - 1; end [file_name, err]=sprintf('%s/%s',rgb_data_dir,file_list{color_file_nearest_index}); rgb_img = imread(file_name); img = rgb2gray(rgb_img); %figure;imshow(rgb_img); %figure;imshow(img); %Noise reduction by Gaussian filter gaussian_h = fspecial('gaussian',[3 3],1); img=imfilter(img, gaussian_h,'replicate'); fx = 525.0; %# focal length x fy = 525.0; %# focal length y cx = 319.5; %# optical center x cy = 239.5; %# optical center y ds = 1.0; %# depth scaling factor = 5000.0; %# for the 16-bit PNG files %# OR: factor = 1 %# for the 32-bit float images in the ROS bag files for v=1:size(depth_img,1) %height for u=1:size(depth_img,2) %width z = (depth_img(v,u) / factor) * ds; x = (u - cx) * z / fx; y = (v - cy) * z / fy; X(v,u) = x; Y(v,u) = y; Z(v,u) = z; end end rtime = toc(t_load); %figure;imagesc(X); %figure;imagesc(Y); %figure;imagesc(Z); end
github
rising-turtle/slam_matlab-master
vro_icp_9_cov.m
.m
slam_matlab-master/ground_truth_zh/Localization/vro_icp_9_cov.m
10,624
utf_8
e5d049b0e1df183d4947e039b8a2e8bf
% This function compute the transformation of two 3D point clouds by ICP % % Parameters : % % Author : Soonhac Hong ([email protected]) % Date : 9/20/12 % ICP6 + convexhull = ICP9 function [phi_icp, theta_icp, psi_icp, trans_icp, match_rmse, match_num, elapsed_time, sta_icp, error, pose_std] = vro_icp_9_cov(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2) error = 0; sta_icp = 1; t_icp = tic; % test for local minimum in optimization %trans = [0; 0; 0]; %rot = euler_to_rot(0, 27, 0); if size(op_pset1,2) < 10 fprintf('Error in less point for convex hull.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % compute 3D convex hull t_convex = tic; convexhull_1 = convhulln(op_pset1',{'Qt','Pp'}); convexhull_2 = convhulln(op_pset2',{'Qt','Pp'}); % %show convexhull convexhull_1_x =[]; convexhull_1_y =[]; convexhull_1_z =[]; for i=1:size(convexhull_1,1) for j=1:3 convexhull_1_x = [convexhull_1_x op_pset1(1,convexhull_1(i,j))]; convexhull_1_y = [convexhull_1_y op_pset1(2,convexhull_1(i,j))]; convexhull_1_z = [convexhull_1_z op_pset1(3,convexhull_1(i,j))]; end end % plot3(convexhull_1_x, convexhull_1_y, convexhull_1_z,'d-'); % grid; % axis equal; %draw_data = [convexhull_1_x' convexhull_1_y' convexhull_1_z']; %mesh(draw_data); %M = op_pset1; %D = op_pset2; M_k = 1; D_k = 1; M=[]; D=[]; convex_check = 1; % check convex hull max_confidence_1 = max(c1(:)); max_confidence_2 = max(c2(:)); threshold = 0.5; confidence_thresh_1 = threshold * max_confidence_1; confidence_thresh_2 = threshold * max_confidence_2; %Initialize data by trans subsampling_factor = 2; h_border_cutoff = round(size(x1,2)*0.1/2); v_border_cutoff = round(size(x1,1)*0.1/2); for i=1+v_border_cutoff:subsampling_factor:size(x1,1)-v_border_cutoff for j=1+h_border_cutoff:subsampling_factor:size(x1,2)-h_border_cutoff M_test = [-x1(i,j) z1(i,j) y1(i,j)]; M_in_flag = inhull(M_test,op_pset1',convexhull_1); D_test = [-x2(i,j) z2(i,j) y2(i,j)]; D_in_flag = inhull(D_test,op_pset2',convexhull_2); if M_in_flag == 1 || convex_check == 0 % test point locates in the convex hull %if img1(i,j) >= 50 % intensity filtering for less noise if c1(i,j) >= confidence_thresh_1 % confidence filtering M(:,M_k) = M_test'; %[-x1(i,j); z1(i,j); y1(i,j)]; M_k = M_k + 1; end end if D_in_flag == 1 || convex_check == 0 %if img2(i,j) >= 50 % intensity filtering for less noise if c2(i,j) >= confidence_thresh_2 % confidence filtering D(:,D_k) = D_test'; %[-x2(i,j); z2(i,j); y2(i,j)]; D_k = D_k + 1; end end %temp_pt2 = [-x2(i,j); z2(i,j); y2(i,j)]; %D(:,k) = rot*temp_pt2 + trans; %transed_pt1 = rot*temp_pt + trans; %k = k + 1; end end elapsed_convex = toc(t_convex); ap_size=size(M,2); if isempty(M) || isempty(D) fprintf('Error in less point for ICP.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %t_icp = tic; %[Ricp, Ticp, ER, t]=icp(M, D,'Minimize','plane'); %elapsed_icp = toc(t_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); %Transform data-matrix using ICP result %Dicp = Ricp * D + repmat(Ticp, 1, n); t_icp_icp = tic; converged = 0; rmse_total=[]; rot_total=[]; trans_total=[]; match_num_total=[]; while_cnt = 1; while converged == 0 % find correspondent assoicate Dicp = rot * D + repmat(trans, 1, size(D,2)); %p = rand( 20, 2 ); % input data (m x n); n dimensionality %q = rand( 10, 2 ); % query data (d x n) t_kdtree = tic; pt1=[]; pt2=[]; if size(M,2) > size (D,2) tree = kdtree_build( M' ); correspondent_idxs = kdtree_nearest_neighbor(tree, Dicp'); pt2 = D; for i=1:size(correspondent_idxs,1) pt1(:,i) = M(:,correspondent_idxs(i)); end else tree = kdtree_build( Dicp' ); correspondent_idxs = kdtree_nearest_neighbor(tree, M'); pt1 = M; for i=1:size(correspondent_idxs,1) pt2(:,i) = D(:,correspondent_idxs(i)); end end elapsed_kdtree = toc(t_kdtree); %[R_icp, trans_icp, ER, t]=icp(pt1, pt2,'Minimize','plane','WorstRejection',0.1); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(R_icp); % Outlier removal % Compute error t_icp_ransac = tic; pt2_transed= rot * pt2 + repmat(trans, 1, size(pt2,2)); new_cnt = 1; pt1_new=[]; pt2_new=[]; correspondent_idxs_new=[]; for i=1:size(pt1,2) unit_rmse = sqrt(sum((pt2_transed(:,i) - pt1(:,i)).^2)); if unit_rmse < 0.03 pt1_new(:,new_cnt) = pt1(:,i); pt2_new(:,new_cnt) = pt2(:,i); correspondent_idxs_new(new_cnt) = correspondent_idxs(i); new_cnt = new_cnt + 1; end end pt1 = pt1_new; pt2 = pt2_new; correspondent_idxs = correspondent_idxs_new'; % Delete duplicates in correspondent points % correspondent_unique = unique(correspondent_idxs); % correspondent_unique_idx = ones(size(correspondent_idxs)); % for i=1:length(correspondent_unique) % unit_idx = find(correspondent_idxs == correspondent_unique(i)); % if length(unit_idx) > 1 % correspondent_unique_idx(unit_idx)=0; % end % end % % correspondent_delete_idx=find(correspondent_unique_idx == 0); % pt1(:,correspondent_delete_idx') = []; % pt2(:,correspondent_delete_idx') = []; % correspondent_idxs(correspondent_delete_idx,:) = []; if isempty(pt1) || isempty(pt2) fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num=[ap_size;0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % op_pset1_icp = pt1_new; % op_pset2_icp = pt2_new; % elapsed_icp_ransac = toc(t_icp_ransac); %t_icp_ransac = tic; [op_match, match_num, rtime, error_ransac] = run_ransac_points(pt1, pt2, correspondent_idxs', 0); if error_ransac ~= 0 % Error in RANSAC fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end op_pset1_icp = []; op_pset2_icp = []; for i=1:match_num(2) op_pset1_icp(:,i) = pt1(:,op_match(1,i)); op_pset2_icp(:,i) = pt2(:,op_match(2,i)); end elapsed_icp_ransac = toc(t_icp_ransac); % SVD t_svd_icp = tic; %[rot_icp, trans_icp, sta_icp] = find_transform_matrix(op_pset1_icp, op_pset2_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); %elapsed_svd = etime(clock, t_svd); sta_icp =1; t_init = zeros(6,1); [t_init(2), t_init(1), t_init(3)] = rot_to_euler(rot); t_init(4:6) = trans; [rot_icp, trans_icp] = lm_point(op_pset1_icp, op_pset2_icp, t_init); %[rot_icp, trans_icp] = lm_point2plane(op_pset1, op_pset2, t_init); elapsed_svd = toc(t_svd_icp); % M = op_pset1_icp; % D = op_pset2_icp; rot = rot_icp; trans = trans_icp; rot_total(:,:,while_cnt) = rot; trans_total(:,:,while_cnt) = trans; match_num_total(while_cnt) = size(op_pset1_icp,2); % Plot % figure; % plot3(op_pset1_icp(1,:),op_pset1_icp(2,:),op_pset1_icp(3,:),'b*-'); % hold on; % plot3(op_pset2_icp(1,:),op_pset2_icp(2,:),op_pset2_icp(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; % Compute error op_pset1_icp_normal = lsqnormest(op_pset1_icp,4); op_pset2_icp_transed= rot * op_pset2_icp + repmat(trans, 1, size(op_pset2_icp,2)); % rmse_icp = 0; % for i=1:size(M,2) % unit_rmse = sqrt(sum((D_transed(:,i) - M(:,i)).^2)/3); % rmse_icp = rmse_icp + unit_rmse; % end % rmse_icp = rmse_icp / size(M,2); %rmse_icp = rms_error(op_pset1_icp, op_pset2_icp_transed); rmse_icp = rms_error_normal(op_pset1_icp, op_pset2_icp_transed, op_pset1_icp_normal); % point-to-plain op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse_feature = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse_feature = rmse_feature + unit_rmse; % end % rmse_feature = rmse_feature / size(op_pset1,2); rmse_feature= rms_error(op_pset1,op_pset2_transed); rmse_total = [rmse_total (rmse_icp+rmse_feature)/2]; %rmse_total = [rmse_total rmse_icp]; rmse_thresh = 0.001; if length(rmse_total) > 3 rmse_diff = abs(diff(rmse_total)); rmse_diff_length = length(rmse_diff); if rmse_diff(rmse_diff_length) < rmse_thresh && rmse_diff(rmse_diff_length-1) < rmse_thresh && rmse_diff(rmse_diff_length-2) < rmse_thresh converged = 1; end end while_cnt = while_cnt + 1; end [match_rmse match_rmse_idx] = min(rmse_total); %match_rmse = rmse_total(end); %match_rmse_idx = size(rmse_total,2); match_num = [ap_size; match_num_total(match_rmse_idx)]; rot_icp = rot_total(:,:,match_rmse_idx); trans_icp = trans_total(:,:,match_rmse_idx); [phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); elapsed_icp_icp = toc(t_icp_icp); %t_icp_icp = tic; %[Ricp, trans_icp, ER, t]=icp(op_pset1_icp, op_pset2_icp,'Minimize','plane'); %elapsed_icp_icp = toc(t_icp_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); elapsed_icp = toc(t_icp); elapsed_time = [elapsed_convex, elapsed_kdtree, elapsed_icp_ransac, elapsed_icp_icp, elapsed_icp]; %Compute covariane [pose_std] = compute_pose_std(op_pset1_icp,op_pset2_icp, rot_icp, trans_icp); pose_std = pose_std'; M = []; D = []; pt1 = []; pt2 = []; op_pset1_icp = []; op_pset2_icp = []; tree = []; end
github
rising-turtle/slam_matlab-master
get_it_filename.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_it_filename.m
231
utf_8
41b2a3e2134a87f097824cc0957c80a2
% Get directory name of motive datasets % % Author : Soonhac Hong ([email protected]) % Date : 11/20/13 function it_filename_lists=get_it_filename() it_filename_lists = {'it30','it50','it70','it90','it110','it130','it150'}; end
github
rising-turtle/slam_matlab-master
check_stored_visual_feature.m
.m
slam_matlab-master/ground_truth_zh/Localization/check_stored_visual_feature.m
1,230
utf_8
08b710330ed346960fc4aa626de7a5d7
% Check if there is the stored visual feature % % Author : Soonhac Hong ([email protected]) % Date : 2/13/2013 function [exist_flag] = check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) exist_flag = 0; [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true if strcmp(data_name, 'object_recognition') dataset_dir = strrep(prefix, '/f1',''); else dataset_dir = strrep(prefix, '/d1',''); end file_name = sprintf('d1_%04d.mat',cframe); else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); file_name = sprintf('d%d_%04d.mat',dm,cframe); end if strcmp(image_name, 'depth') dataset_dir = sprintf('%s/depth_feature',dataset_dir); else dataset_dir = sprintf('%s/visual_feature',dataset_dir); end %file_name = sprintf('d1_%04d.mat',cframe); dirData = dir(dataset_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; if isempty(file_list) return; else for i=1:size(file_list,1) if strcmp(file_list{i}, file_name) exist_flag = 1; break; end end end end
github
rising-turtle/slam_matlab-master
localization_siftgpu_ransac_limit_cov_fast_fast_dist2_nobpc_bin.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_siftgpu_ransac_limit_cov_fast_fast_dist2_nobpc_bin.m
20,509
utf_8
a8f61fb98d61082f56a6b7478ddf0d08
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance % No bad pixel compensation function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_siftgpu_ransac_limit_cov_fast_fast_dist2_nobpc_bin(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, sequence_data, is_10M_data, dis) % if nargin < 15 % dis = 0; % end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true cframe = sframe-j; else cframe = j; end first_cframe = cframe; if first_cframe > 0 if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else %[img1, x1, y1, z1, c1, elapsed_pre] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); ld_error=0; [img1, x1, y1, z1, c1, elapsed_pre, ld_error] = LoadSR_no_bpc_time_single_binary(data_name, filter_name, boarder_cut_off, dm, first_cframe, scale, value_type); end if ld_error < 0 fprintf('No image is loaded !!\n'); error=ld_error; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; match_num = [0; 0; 0]; elapsed = [0; 0; 0; 0; 0; 0; 0; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type,'range'); end % if dis == 1 % f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); % %t_sift = clock; % t_sift = tic; % [frm1, des1] = sift(img1, 'Verbosity', 1); % %elapsed_sift = etime(clock,t_sift); % elapsed_sift = toc(t_sift); % plotsiftframe(frm1); % else %t_sift = clock; t_sift = tic; if sift_threshold == 0 %[frm1, des1] = sift(img1); [des1, frm1]=siftgpu_rawdata(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); % end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre, sequence_data, image_name); else t_sift = tic; [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); elapsed_sift = toc(t_sift); elapsed_pre = 0; end if dis==1 && j == 1 figure(1); subplot(2,2,3); imagesc(img1); colormap(gray); axis image; set(gca,'XTick',[]); set(gca,'YTick',[]); title(sprintf('Frame %d', first_cframe)); drawnow; end end %Read second Data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true %cframe = j + sframe; %cframe = sframe+1; %cframe = sframe + j; % Generate constraints cframe = sframe; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else %[img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); ld_error2=0; [img2, x2, y2, z2, c2, elapsed_pre2, ld_error2] = LoadSR_no_bpc_time_single_binary(data_name, filter_name, boarder_cut_off, dm, second_cframe, scale, value_type); end if ld_error2 < 0 fprintf('No image is loaded !!\n'); error=ld_error2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; match_num = [0; 0; 0]; elapsed = [0; 0; 0; 0; 0; 0; 0; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type, 'range'); end % if dis == 1 % f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); % %t_sift = clock; % t_sift2 = tic; % [frm2, des2] = sift(img2, 'Verbosity', 1); % %elapsed_sift2 = etime(clock, t_sift); % elapsed_sift2 = toc(t_sift2); % plotsiftframe(frm2); % else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 %[frm2, des2] = sift(img2); [des2, frm2]=siftgpu_rawdata(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); % end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2, sequence_data, image_name); else t_sift2 = tic; [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); elapsed_sift2 = toc(t_sift2); elapsed_pre2 = 0; end if dis==1 figure(1); subplot(2,2,1); imagesc(img2); colormap(gray); axis image; set(gca,'XTick',[]); set(gca,'YTick',[]); title(sprintf('Frame %d', second_cframe)); drawnow; end if first_cframe <= 0 fprintf('First is loaded !!\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; elapsed = [0; 0; 0; 0; 0; 0; 0; 0]; match_num = [0; 0; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); % if dis == 1 % f3=figure(6); % plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); % end % distance filtering if is_10M_data == 1 valid_dist_max = 8; % 5m else valid_dist_max = 5; % 5m end valid_dist_min = 0.8; % 0.8m match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if COL1 <= 176 && COL2 <= 176 && ROW1 <= 144 && ROW2 <= 144 temp_pt1=[-x1(ROW1, COL1), z1(ROW1, COL1), y1(ROW1, COL1)]; temp_pt2=[-x2(ROW2, COL2), z2(ROW2, COL2), y2(ROW2, COL2)]; temp_pt1_dist = sqrt(sum(temp_pt1.^2)); temp_pt2_dist = sqrt(sum(temp_pt2.^2)); if temp_pt1_dist >= valid_dist_min && temp_pt1_dist <= valid_dist_max && temp_pt2_dist >= valid_dist_min && temp_pt2_dist <= valid_dist_max %if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 % 39 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 12000; %120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end % if dis == 1 % f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); % f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); % f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); % end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2, 'none', sequence_data); else t_ransac = tic; [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); elapsed_ransac = toc(t_ransac); elapsed_match = 0; t_svd = tic; end %[op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); %[rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [rot, trans, sta] = find_transform_matrix_e6(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta <= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; % elseif sta == 2 % fprintf('Points are in co-planar.\n'); % error=4; % phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; % elapsed_ransac = 0.0; % elapsed_svd = 0.0; % %elapsed_icp = 0.0; % %match_num = [pnum; gc_num; op_num]; % elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; % feature_points = []; % pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; % return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; %feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; %feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; %feature_points = [feature_points_1; feature_points_2]; feature_points = []; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane if check_stored_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; save_pose_std(data_name, dm, first_cframe, second_cframe, pose_std, 'none', sequence_data); else [pose_std] = load_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); end %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc_svde6.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc_svde6.m
17,644
utf_8
59d68df885879e92e4bb12165cf177a0
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance % No bad pixel compensation function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc_svde6(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, sequence_data, is_10M_data, dis) if nargin < 15 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true cframe = sframe; else cframe = j; end first_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type,'range'); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre, sequence_data, image_name); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); end %Read second Data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type, 'range'); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2, sequence_data, image_name); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % distance filtering if is_10M_data == 1 valid_dist_max = 8; % 5m else valid_dist_max = 5; % 5m end valid_dist_min = 0.8; % 0.8m match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; temp_pt1=[-x1(ROW1, COL1), z1(ROW1, COL1), y1(ROW1, COL1)]; temp_pt2=[-x2(ROW2, COL2), z2(ROW2, COL2), y2(ROW2, COL2)]; temp_pt1_dist = sqrt(sum(temp_pt1.^2)); temp_pt2_dist = sqrt(sum(temp_pt2.^2)); if temp_pt1_dist >= valid_dist_min && temp_pt1_dist <= valid_dist_max && temp_pt2_dist >= valid_dist_min && temp_pt2_dist <= valid_dist_max %if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 % 39 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2, 'none', sequence_data); else [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); t_svd = tic; end %[op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); %[rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [rot, trans, sta] = find_transform_matrix_e6(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta <= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; % elseif sta == 2 % fprintf('Points are in co-planar.\n'); % error=4; % phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; % elapsed_ransac = 0.0; % elapsed_svd = 0.0; % %elapsed_icp = 0.0; % %match_num = [pnum; gc_num; op_num]; % elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; % feature_points = []; % pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; % return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane if check_stored_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; save_pose_std(data_name, dm, first_cframe, second_cframe, pose_std, 'none', sequence_data); else [pose_std] = load_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); end %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
check_feature_distance_icp.m
.m
slam_matlab-master/ground_truth_zh/Localization/check_feature_distance_icp.m
781
utf_8
04b938571127b8ecb8e8139ba603a597
% Check the distance of feaure points % % Author : Soonhac Hong ([email protected]) % Date : 4/5/13 function [op_pset1, op_pset2] = check_feature_distance_icp(op_pset1, op_pset2) distance_min = 0.8; distance_max = 5; op_pset1_distance = sqrt(sum(op_pset1.^2)); op_pset2_distance = sqrt(sum(op_pset2.^2)); op_pset1_distance_flag = (op_pset1_distance < distance_min | op_pset1_distance > distance_max); op_pset2_distance_flag = (op_pset2_distance < distance_min | op_pset2_distance > distance_max); %debug % if sum(op_pset1_distance_flag) > 0 || sum(op_pset2_distance_flag) > 0 % disp('Distance filter is working'); % end op_pset1(:, op_pset1_distance_flag)=[]; % delete invalid feature points op_pset2(:, op_pset2_distance_flag)=[]; % delete invalid feature points end
github
rising-turtle/slam_matlab-master
load_visual_features.m
.m
slam_matlab-master/ground_truth_zh/Localization/load_visual_features.m
1,115
utf_8
b287b4545e4f246bec0e76880f2e3716
% Load sift visual feature from a file % % Author : Soonhac Hong ([email protected]) % Date : 2/13/2013 function [frm, des, elapsed_sift, img, x, y, z, c, elapsed_pre] = load_visual_features(data_name, dm, cframe, sequence_data, image_name) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true if strcmp(data_name, 'object_recognition') dataset_dir = strrep(prefix, '/f1',''); else dataset_dir = strrep(prefix, '/d1',''); end if strcmp(image_name, 'depth') file_name = sprintf('%s/depth_feature/d1_%04d.mat',dataset_dir, cframe); else file_name = sprintf('%s/visual_feature/d1_%04d.mat',dataset_dir, cframe); end else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); if strcmp(image_name, 'depth') file_name = sprintf('%s/depth_feature/d%d_%04d.mat',dataset_dir, dm, cframe); else file_name = sprintf('%s/visual_feature/d%d_%04d.mat',dataset_dir, dm, cframe); end end %file_name = sprintf('%s/visual_feature/d1_%04d.mat',dataset_dir, cframe); load(file_name); end
github
rising-turtle/slam_matlab-master
load_matched_points.m
.m
slam_matlab-master/ground_truth_zh/Localization/load_matched_points.m
950
utf_8
1a99af336cb68c960b51337530b7259d
% Load matched points from a file % % Author : Soonhac Hong ([email protected]) % Date : 3/11/2013 function [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, isgframe, sequence_data) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true if strcmp(data_name, 'object_recognition') dataset_dir = strrep(prefix, '/f1',''); else dataset_dir = strrep(prefix, '/d1',''); end else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); end if strcmp(isgframe, 'gframe') file_name = sprintf('%s/matched_points_gframe/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); else file_name = sprintf('%s/matched_points/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); end load(file_name); end
github
rising-turtle/slam_matlab-master
vro_icp_6_cov.m
.m
slam_matlab-master/ground_truth_zh/Localization/vro_icp_6_cov.m
10,511
utf_8
641524042e16a232c87308d355249f26
% This function compute the transformation of two 3D point clouds by ICP % % Parameters : % % Author : Soonhac Hong ([email protected]) % Date : 9/20/12 function [phi_icp, theta_icp, psi_icp, trans_icp, match_rmse, match_num, elapsed_time, sta_icp, error, pose_std] = vro_icp_6_cov(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2) error = 0; sta_icp = 1; t_icp = tic; % test for local minimum in optimization %trans = [0; 0; 0]; %rot = euler_to_rot(0, 27, 0); % if size(op_pset1,2) < 5 % fprintf('Error in less point for convex hull.\n'); % error=6; % phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; % elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; % match_rmse = 0.0; % match_num = [0; 0]; % return; % end % compute 3D convex hull t_convex = tic; % convexhull_1 = convhulln(op_pset1',{'Qt','Pp'}); % convexhull_2 = convhulln(op_pset2',{'Qt','Pp'}); % %show convexhull % convexhull_1_x =[]; % convexhull_1_y =[]; % convexhull_1_z =[]; % % for i=1:size(convexhull_1,1) % for j=1:3 % convexhull_1_x = [convexhull_1_x op_pset1(1,convexhull_1(i,j))]; % convexhull_1_y = [convexhull_1_y op_pset1(2,convexhull_1(i,j))]; % convexhull_1_z = [convexhull_1_z op_pset1(3,convexhull_1(i,j))]; % end % end % plot3(convexhull_1_x, convexhull_1_y, convexhull_1_z); %M = op_pset1; %D = op_pset2; M_k = 1; D_k = 1; M=[]; D=[]; convex_check = 0; % check convex hull max_confidence_1 = max(c1(:)); max_confidence_2 = max(c2(:)); threshold = 0.5; confidence_thresh_1 = threshold * max_confidence_1; confidence_thresh_2 = threshold * max_confidence_2; %Initialize data by trans subsampling_factor = 2; h_border_cutoff = round(size(x1,2)*0.1/2); v_border_cutoff = round(size(x1,1)*0.1/2); for i=1+v_border_cutoff:subsampling_factor:size(x1,1)-v_border_cutoff for j=1+h_border_cutoff:subsampling_factor:size(x1,2)-h_border_cutoff M_test = [-x1(i,j) z1(i,j) y1(i,j)]; % M_in_flag = inhull(M_test,op_pset1',convexhull_1); D_test = [-x2(i,j) z2(i,j) y2(i,j)]; % D_in_flag = inhull(D_test,op_pset2',convexhull_2); % if M_in_flag == 1 || convex_check == 0 % test point locates in the convex hull %if img1(i,j) >= 50 %100 % intensity filtering for less noise if c1(i,j) >= confidence_thresh_1 % confidence filtering M(:,M_k) = M_test'; %[-x1(i,j); z1(i,j); y1(i,j)]; M_k = M_k + 1; end % end % if D_in_flag == 1 || convex_check == 0 %if img2(i,j) >= 50 %100 % intensity filtering for less noise if c2(i,j) >= confidence_thresh_2 % confidence filtering D(:,D_k) = D_test'; %[-x2(i,j); z2(i,j); y2(i,j)]; D_k = D_k + 1; end % end %temp_pt2 = [-x2(i,j); z2(i,j); y2(i,j)]; %D(:,k) = rot*temp_pt2 + trans; %transed_pt1 = rot*temp_pt + trans; %k = k + 1; end end elapsed_convex = toc(t_convex); ap_size=size(M,2); if isempty(M) || isempty(D) fprintf('Error in less point for ICP.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %t_icp = tic; %[Ricp, Ticp, ER, t]=icp(M, D,'Minimize','plane'); %elapsed_icp = toc(t_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); %Transform data-matrix using ICP result %Dicp = Ricp * D + repmat(Ticp, 1, n); t_icp_icp = tic; converged = 0; rmse_total=[]; rot_total=[]; trans_total=[]; match_num_total=[]; while_cnt = 1; while converged == 0 % find correspondent assoicate Dicp = rot * D + repmat(trans, 1, size(D,2)); %p = rand( 20, 2 ); % input data (m x n); n dimensionality %q = rand( 10, 2 ); % query data (d x n) t_kdtree = tic; pt1=[]; pt2=[]; if size(M,2) > size (D,2) tree = kdtree_build( M' ); correspondent_idxs = kdtree_nearest_neighbor(tree, Dicp'); pt2 = D; for i=1:size(correspondent_idxs,1) pt1(:,i) = M(:,correspondent_idxs(i)); end else tree = kdtree_build( Dicp' ); correspondent_idxs = kdtree_nearest_neighbor(tree, M'); pt1 = M; for i=1:size(correspondent_idxs,1) pt2(:,i) = D(:,correspondent_idxs(i)); end end elapsed_kdtree = toc(t_kdtree); %[R_icp, trans_icp, ER, t]=icp(pt1, pt2,'Minimize','plane','WorstRejection',0.1); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(R_icp); % Outlier removal % Compute error t_icp_ransac = tic; pt2_transed= rot * pt2 + repmat(trans, 1, size(pt2,2)); new_cnt = 1; pt1_new=[]; pt2_new=[]; correspondent_idxs_new=[]; for i=1:size(pt1,2) unit_rmse = sqrt(sum((pt2_transed(:,i) - pt1(:,i)).^2)); if unit_rmse < 0.03 pt1_new(:,new_cnt) = pt1(:,i); pt2_new(:,new_cnt) = pt2(:,i); correspondent_idxs_new(new_cnt) = correspondent_idxs(i); new_cnt = new_cnt + 1; end end pt1 = pt1_new; pt2 = pt2_new; correspondent_idxs = correspondent_idxs_new'; % Delete duplicates in correspondent points % correspondent_unique = unique(correspondent_idxs); % correspondent_unique_idx = ones(size(correspondent_idxs)); % for i=1:length(correspondent_unique) % unit_idx = find(correspondent_idxs == correspondent_unique(i)); % if length(unit_idx) > 1 % correspondent_unique_idx(unit_idx)=0; % end % end % % correspondent_delete_idx=find(correspondent_unique_idx == 0); % pt1(:,correspondent_delete_idx') = []; % pt2(:,correspondent_delete_idx') = []; % correspondent_idxs(correspondent_delete_idx,:) = []; if isempty(pt1) || isempty(pt2) fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num=[ap_size;0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % op_pset1_icp = pt1_new; % op_pset2_icp = pt2_new; % elapsed_icp_ransac = toc(t_icp_ransac); % %t_icp_ransac = tic; [op_match, match_num, rtime, error_ransac] = run_ransac_points(pt1, pt2, correspondent_idxs', 0); if error_ransac ~= 0 % Error in RANSAC fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end op_pset1_icp = []; op_pset2_icp = []; for i=1:match_num(2) op_pset1_icp(:,i) = pt1(:,op_match(1,i)); op_pset2_icp(:,i) = pt2(:,op_match(2,i)); end elapsed_icp_ransac = toc(t_icp_ransac); % SVD t_svd_icp = tic; %[rot_icp, trans_icp, sta_icp] = find_transform_matrix(op_pset1_icp, op_pset2_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); %elapsed_svd = etime(clock, t_svd); sta_icp =1; t_init = zeros(6,1); [t_init(2), t_init(1), t_init(3)] = rot_to_euler(rot); t_init(4:6) = trans; [rot_icp, trans_icp] = lm_point(op_pset1_icp, op_pset2_icp, t_init); %[rot_icp, trans_icp] = lm_point2plane(op_pset1, op_pset2, t_init); elapsed_svd = toc(t_svd_icp); % M = op_pset1_icp; % D = op_pset2_icp; rot = rot_icp; trans = trans_icp; rot_total(:,:,while_cnt) = rot; trans_total(:,:,while_cnt) = trans; match_num_total(while_cnt) = size(op_pset1_icp,2); % Plot % figure; % plot3(op_pset1_icp(1,:),op_pset1_icp(2,:),op_pset1_icp(3,:),'b*-'); % hold on; % plot3(op_pset2_icp(1,:),op_pset2_icp(2,:),op_pset2_icp(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; % Compute error op_pset1_icp_normal = lsqnormest(op_pset1_icp,4); op_pset2_icp_transed= rot * op_pset2_icp + repmat(trans, 1, size(op_pset2_icp,2)); % rmse_icp = 0; % for i=1:size(M,2) % unit_rmse = sqrt(sum((D_transed(:,i) - M(:,i)).^2)/3); % rmse_icp = rmse_icp + unit_rmse; % end % rmse_icp = rmse_icp / size(M,2); %rmse_icp = rms_error(op_pset1_icp, op_pset2_icp_transed); rmse_icp = rms_error_normal(op_pset1_icp, op_pset2_icp_transed, op_pset1_icp_normal); % point-to-plain op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse_feature = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse_feature = rmse_feature + unit_rmse; % end % rmse_feature = rmse_feature / size(op_pset1,2); rmse_feature= rms_error(op_pset1,op_pset2_transed); rmse_total = [rmse_total (rmse_icp+rmse_feature)/2]; %rmse_total = [rmse_total rmse_icp]; rmse_thresh = 0.001; if length(rmse_total) > 3 rmse_diff = abs(diff(rmse_total)); rmse_diff_length = length(rmse_diff); if rmse_diff(rmse_diff_length) < rmse_thresh && rmse_diff(rmse_diff_length-1) < rmse_thresh && rmse_diff(rmse_diff_length-2) < rmse_thresh converged = 1; end end while_cnt = while_cnt + 1; end [match_rmse match_rmse_idx] = min(rmse_total); %match_rmse = rmse_total(end); %match_rmse_idx = size(rmse_total,2); match_num = [ap_size; match_num_total(match_rmse_idx)]; rot_icp = rot_total(:,:,match_rmse_idx); trans_icp = trans_total(:,:,match_rmse_idx); [phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); elapsed_icp_icp = toc(t_icp_icp); %t_icp_icp = tic; %[Ricp, trans_icp, ER, t]=icp(op_pset1_icp, op_pset2_icp,'Minimize','plane'); %elapsed_icp_icp = toc(t_icp_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); elapsed_icp = toc(t_icp); elapsed_time = [elapsed_convex, elapsed_kdtree, elapsed_icp_ransac, elapsed_icp_icp, elapsed_icp]; %Compute covariane [pose_std] = compute_pose_std(op_pset1_icp,op_pset2_icp, rot_icp, trans_icp); pose_std = pose_std'; M = []; D = []; pt1 = []; pt2 = []; op_pset1_icp = []; op_pset2_icp = []; tree = []; end
github
rising-turtle/slam_matlab-master
vro_icp_9_cov_tol_batch.m
.m
slam_matlab-master/ground_truth_zh/Localization/vro_icp_9_cov_tol_batch.m
11,537
utf_8
59fe048123dca9a364123c99bde295e7
% This function compute the transformation of two 3D point clouds by ICP % % Parameters : % % Author : Soonhac Hong ([email protected]) % Date : 9/20/12 % ICP6 + convexhull = ICP9 % ICP9_cov + tolerance adjustment = ICP9_cov_tol function [phi_icp, theta_icp, psi_icp, trans_icp, match_rmse, match_num, elapsed_time, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2) error = 0; sta_icp = 1; t_icp = tic; % test for local minimum in optimization %trans = [0; 0; 0]; %rot = euler_to_rot(0, 27, 0); if size(op_pset1,2) <= 8 || size(op_pset2,2) <= 8 fprintf('Error in less point for convex hull.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % compute 3D convex hull t_convex = tic; convexhull_1 = convhulln(op_pset1',{'Qt','Pp'}); convexhull_2 = convhulln(op_pset2',{'Qt','Pp'}); % %show convexhull convexhull_1_x =[]; convexhull_1_y =[]; convexhull_1_z =[]; for i=1:size(convexhull_1,1) for j=1:3 convexhull_1_x = [convexhull_1_x op_pset1(1,convexhull_1(i,j))]; convexhull_1_y = [convexhull_1_y op_pset1(2,convexhull_1(i,j))]; convexhull_1_z = [convexhull_1_z op_pset1(3,convexhull_1(i,j))]; end end % plot3(convexhull_1_x, convexhull_1_y, convexhull_1_z,'d-'); % grid; % axis equal; %draw_data = [convexhull_1_x' convexhull_1_y' convexhull_1_z']; %mesh(draw_data); %M = op_pset1; %D = op_pset2; %M_k = 1; %D_k = 1; M=[]; D=[]; %convex_check = 1; % check convex hull convexhull_tolerance = 0.1; %[m] max_confidence_1 = max(c1(:)); max_confidence_2 = max(c2(:)); threshold = 0.5; confidence_thresh_1 = threshold * max_confidence_1; confidence_thresh_2 = threshold * max_confidence_2; %Initialize data by trans subsampling_factor = 2; h_border_cutoff = round(size(x1,2)*0.1/2); v_border_cutoff = round(size(x1,1)*0.1/2); %M_test=[]; %D_test=[]; M_cf=[]; D_cf=[]; sample_idx=1; for i=1+v_border_cutoff:subsampling_factor:size(x1,1)-v_border_cutoff for j=1+h_border_cutoff:subsampling_factor:size(x1,2)-h_border_cutoff M = [M; -x1(i,j) z1(i,j) y1(i,j)]; D = [D; -x2(i,j) z2(i,j) y2(i,j)]; %if M_in_flag == 1 || convex_check == 0 % test point locates in the convex hull %if img1(i,j) >= 50 % intensity filtering for less noise if c1(i,j) >= confidence_thresh_1 % confidence filtering M_cf(sample_idx,1)=1; %M(:,M_k) = M_test'; %[-x1(i,j); z1(i,j); y1(i,j)]; %M_k = M_k + 1; else M_cf(sample_idx,1)=0; end %end %if D_in_flag == 1 || convex_check == 0 %if img2(i,j) >= 50 % intensity filtering for less noise if c2(i,j) >= confidence_thresh_2 % confidence filtering D_cf(sample_idx,1)=1; %D(:,D_k) = D_test'; %[-x2(i,j); z2(i,j); y2(i,j)]; %D_k = D_k + 1; else D_cf(sample_idx,1)=0; end %end %temp_pt2 = [-x2(i,j); z2(i,j); y2(i,j)]; %D(:,k) = rot*temp_pt2 + trans; %transed_pt1 = rot*temp_pt + trans; %k = k + 1; sample_idx = sample_idx + 1; end end m_cf_idx = M_cf(:) == 0; d_cf_idx = D_cf(:) == 0; M(m_cf_idx,:)=[]; D(d_cf_idx,:)=[]; M_in_flag = inhull(M,op_pset1',convexhull_1,convexhull_tolerance); D_in_flag = inhull(D,op_pset2',convexhull_2,convexhull_tolerance); M_in_flag_idx = M_in_flag(:) == 0; D_in_flag_idx = D_in_flag(:) == 0; M(M_in_flag_idx,:)=[]; D(D_in_flag_idx,:)=[]; M=M'; D=D'; elapsed_convex = toc(t_convex); ap_size=size(M,2); if isempty(M) || isempty(D) fprintf('Error in less point for ICP.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %t_icp = tic; %[Ricp, Ticp, ER, t]=icp(M, D,'Minimize','plane'); %elapsed_icp = toc(t_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); %Transform data-matrix using ICP result %Dicp = Ricp * D + repmat(Ticp, 1, n); t_icp_icp = tic; converged = 0; rmse_total=[]; rot_total=[]; trans_total=[]; match_num_total=[]; while_cnt = 1; while converged == 0 % find correspondent assoicate Dicp = rot * D + repmat(trans, 1, size(D,2)); %p = rand( 20, 2 ); % input data (m x n); n dimensionality %q = rand( 10, 2 ); % query data (d x n) t_kdtree = tic; pt1=[]; pt2=[]; if size(M,2) > size (D,2) tree = kdtree_build( M' ); correspondent_idxs = kdtree_nearest_neighbor(tree, Dicp'); pt2 = D; for i=1:size(correspondent_idxs,1) pt1(:,i) = M(:,correspondent_idxs(i)); end else tree = kdtree_build( Dicp' ); correspondent_idxs = kdtree_nearest_neighbor(tree, M'); pt1 = M; for i=1:size(correspondent_idxs,1) pt2(:,i) = D(:,correspondent_idxs(i)); end end elapsed_kdtree = toc(t_kdtree); %[R_icp, trans_icp, ER, t]=icp(pt1, pt2,'Minimize','plane','WorstRejection',0.1); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(R_icp); % Outlier removal % Compute error t_icp_ransac = tic; pt2_transed= rot * pt2 + repmat(trans, 1, size(pt2,2)); new_cnt = 1; pt1_new=[]; pt2_new=[]; correspondent_idxs_new=[]; for i=1:size(pt1,2) unit_rmse = sqrt(sum((pt2_transed(:,i) - pt1(:,i)).^2)); if unit_rmse < 0.03 pt1_new(:,new_cnt) = pt1(:,i); pt2_new(:,new_cnt) = pt2(:,i); correspondent_idxs_new(new_cnt) = correspondent_idxs(i); new_cnt = new_cnt + 1; end end pt1 = pt1_new; pt2 = pt2_new; correspondent_idxs = correspondent_idxs_new'; % Delete duplicates in correspondent points % correspondent_unique = unique(correspondent_idxs); % correspondent_unique_idx = ones(size(correspondent_idxs)); % for i=1:length(correspondent_unique) % unit_idx = find(correspondent_idxs == correspondent_unique(i)); % if length(unit_idx) > 1 % correspondent_unique_idx(unit_idx)=0; % end % end % % correspondent_delete_idx=find(correspondent_unique_idx == 0); % pt1(:,correspondent_delete_idx') = []; % pt2(:,correspondent_delete_idx') = []; % correspondent_idxs(correspondent_delete_idx,:) = []; if isempty(pt1) || isempty(pt2) fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num=[ap_size;0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % op_pset1_icp = pt1_new; % op_pset2_icp = pt2_new; % elapsed_icp_ransac = toc(t_icp_ransac); %t_icp_ransac = tic; [op_match, match_num, rtime, error_ransac] = run_ransac_points(pt1, pt2, correspondent_idxs', 0); if error_ransac ~= 0 % Error in RANSAC fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end op_pset1_icp = []; op_pset2_icp = []; for i=1:match_num(2) op_pset1_icp(:,i) = pt1(:,op_match(1,i)); op_pset2_icp(:,i) = pt2(:,op_match(2,i)); end elapsed_icp_ransac = toc(t_icp_ransac); % SVD t_svd_icp = tic; %[rot_icp, trans_icp, sta_icp] = find_transform_matrix(op_pset1_icp, op_pset2_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); %elapsed_svd = etime(clock, t_svd); sta_icp =1; t_init = zeros(6,1); [t_init(2), t_init(1), t_init(3)] = rot_to_euler(rot); t_init(4:6) = trans; [rot_icp, trans_icp] = lm_point(op_pset1_icp, op_pset2_icp, t_init); %[rot_icp, trans_icp] = lm_point2plane(op_pset1, op_pset2, t_init); elapsed_svd = toc(t_svd_icp); % M = op_pset1_icp; % D = op_pset2_icp; rot = rot_icp; trans = trans_icp; rot_total(:,:,while_cnt) = rot; trans_total(:,:,while_cnt) = trans; match_num_total(while_cnt) = size(op_pset1_icp,2); % Plot % figure; % plot3(op_pset1_icp(1,:),op_pset1_icp(2,:),op_pset1_icp(3,:),'b*-'); % hold on; % plot3(op_pset2_icp(1,:),op_pset2_icp(2,:),op_pset2_icp(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; % Compute error op_pset1_icp_normal = lsqnormest(op_pset1_icp,4); op_pset2_icp_transed= rot * op_pset2_icp + repmat(trans, 1, size(op_pset2_icp,2)); % rmse_icp = 0; % for i=1:size(M,2) % unit_rmse = sqrt(sum((D_transed(:,i) - M(:,i)).^2)/3); % rmse_icp = rmse_icp + unit_rmse; % end % rmse_icp = rmse_icp / size(M,2); %rmse_icp = rms_error(op_pset1_icp, op_pset2_icp_transed); rmse_icp = rms_error_normal(op_pset1_icp, op_pset2_icp_transed, op_pset1_icp_normal); % point-to-plain op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse_feature = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse_feature = rmse_feature + unit_rmse; % end % rmse_feature = rmse_feature / size(op_pset1,2); rmse_feature= rms_error(op_pset1,op_pset2_transed); rmse_total = [rmse_total (rmse_icp+rmse_feature)/2]; %rmse_total = [rmse_total rmse_icp]; rmse_thresh = 0.001; if length(rmse_total) > 3 rmse_diff = abs(diff(rmse_total)); rmse_diff_length = length(rmse_diff); if rmse_diff(rmse_diff_length) < rmse_thresh && rmse_diff(rmse_diff_length-1) < rmse_thresh && rmse_diff(rmse_diff_length-2) < rmse_thresh converged = 1; end end while_cnt = while_cnt + 1; end [match_rmse match_rmse_idx] = min(rmse_total); %match_rmse = rmse_total(end); %match_rmse_idx = size(rmse_total,2); match_num = [ap_size; match_num_total(match_rmse_idx)]; rot_icp = rot_total(:,:,match_rmse_idx); trans_icp = trans_total(:,:,match_rmse_idx); [phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); elapsed_icp_icp = toc(t_icp_icp); %t_icp_icp = tic; %[Ricp, trans_icp, ER, t]=icp(op_pset1_icp, op_pset2_icp,'Minimize','plane'); %elapsed_icp_icp = toc(t_icp_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); elapsed_icp = toc(t_icp); elapsed_time = [elapsed_convex, elapsed_kdtree, elapsed_icp_ransac, elapsed_icp_icp, elapsed_icp]; %Compute covariane [pose_std] = compute_pose_std(op_pset1_icp,op_pset2_icp, rot_icp, trans_icp); pose_std = pose_std'; M = []; D = []; pt1 = []; pt2 = []; op_pset1_icp = []; op_pset2_icp = []; tree = []; convexhull_1=[]; convexhull_2=[]; convexhull_1_x =[]; convexhull_1_y =[]; convexhull_1_z =[]; M_cf=[]; D_cf=[]; M_in_flag=[]; D_in_flag=[]; M_in_flag_idx=[]; D_in_flag_idx=[]; op_pset1=[]; op_pset2=[]; x1=[]; y1=[]; z1=[]; img1=[]; c1=[]; x2=[]; y2=[]; z2=[]; img2=[]; c2=[]; end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_icp2_cov_fast_fast.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_icp2_cov_fast_fast.m
19,935
utf_8
b2230e5879dca9b7519e5b3b37483454
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 8/30/12 function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_icp2_cov_fast(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, icp_mode, dis) if nargin < 14 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') % Dynamic data cframe = sframe; else cframe = j; end first_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); %[frm1,des1] = vl_sift(single(img1)) ; else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe); end %Read second Data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature')% Dynamic data %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); %[frm2,des2] = vl_sift(single(img2)) ; else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe); end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe) == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %[match, scores] = vl_ubcmatch(des1,des2) ; %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 match_new = []; cnt_new = 1; pnum = size(match, 2); if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if img1(ROW1, COL1) >= 0 && img2(ROW2, COL2) >= 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; % stdev_threshold = 0.1; % stdev_count = 0; % count_threshold = 15; % mean_threshold = 0.1; % mean_count = 0; % window_size = 30; % debug_data=[]; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % if cnum >= valid_ransac % break; % end % if cnum/pnum >= inlier_ratio % break; % enddynamic_data_index % total_cnum(i)=cnum; % if i > window_size && inliers_std ~= 0 % inliers_std_prev = inliers_std; % inliers_std = std(total_cnum(i-window_size:i)); %Moving STDEV % inliers_std_delta = abs(inliers_std - inliers_std_prev)/inliers_std_prev; % % inliers_mean_prev = inliers_mean; % inliers_mean = mean(total_cnum(i-window_size:i)); %Moving STDEV % inliers_mean_delta = abs(inliers_mean - inliers_mean_prev)/inliers_mean_prev; % % if inliers_std_delta < stdev_threshold % stdev_count = stdev_count + 1; % else % stdev_count = 0; % end % % if inliers_mean_delta < mean_threshold % mean_count = mean_count + 1; % else % mean_count = 0; % end % % inlier_ratio = max(total_cnum)/pnum; % % count_threshold = 120000 / ((inlier_ratio*100)^2); %-26 * (inlier_ratio*100 - 20) + 800; % % if stdev_count > count_threshold %&& mean_count > count_threshold % break; % end % else % inliers_std = std(total_cnum); % inliers_mean = mean(total_cnum); % end if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1 break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %% Run SVD %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2); else [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe); t_svd = tic; end [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Test LM %[rot_lm, trans_lm] = lm_point(op_pset1, op_pset2); % [rot_lm, trans_lm] = lm_point2plane(op_pset1, op_pset2); % [phi_lm, theta_lm, psi_lm] = rot_to_euler(rot_lm); % [theta*180/pi theta_lm*180/pi] % [phi*180/pi phi_lm*180/pi] % [psi*180/pi psi_lm*180/pi] % Save feature points %feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; % Compute RMSE op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse = rmse + unit_rmse; % end % rmse_feature = rmse / size(op_pset1,2); %rmse_feature = rms_error(op_pset1, op_pset2_transed); % Show correspondent points % plot3(op_pset1(1,:),op_pset1(2,:),op_pset1(3,:),'b*-'); % hold on; % plot3(op_pset2(1,:),op_pset2(2,:),op_pset2(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; %Compute the elapsed time %rt_total = etime(clock,t); %elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; %% Run ICP %[phi_icp, theta_icp, psi_icp, trans_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_2(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_3(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_4(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_5(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); if strcmp(icp_mode, 'icp_ch') [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); else [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_6_cov(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); end %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_10(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_13(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %Check status of SVD if sta_icp == 0 || error ~= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta_icp == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %elapsed_icp = toc(t_icp); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; %rot = rot_icp; % [rmse_feature rmse_icp] % [theta*180/pi theta_icp*180/pi] % [trans(1) trans_icp(1)] %if rmse_icp <= rmse_feature trans = trans_icp; phi = phi_icp; theta = theta_icp; psi = psi_icp; %end %convert degree % r2d=180.0/pi; % phi=phi*r2d; % theta=theta*r2d; % psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
vro_icp_9_cov_tol_dist.m
.m
slam_matlab-master/ground_truth_zh/Localization/vro_icp_9_cov_tol_dist.m
10,953
utf_8
db7a3f2c470869a3f34f6a0b48cec836
% This function compute the transformation of two 3D point clouds by ICP % % Parameters : % % Author : Soonhac Hong ([email protected]) % Date : 9/20/12 % ICP6 + convexhull = ICP9 % ICP9_cov + tolerance adjustment = ICP9_cov_tol function [phi_icp, theta_icp, psi_icp, trans_icp, match_rmse, match_num, elapsed_time, sta_icp, error, pose_std] = vro_icp_9_cov(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2) error = 0; sta_icp = 1; t_icp = tic; % test for local minimum in optimization %trans = [0; 0; 0]; %rot = euler_to_rot(0, 27, 0); if size(op_pset1,2) <= 8 || size(op_pset2,2) <= 8 fprintf('Error in less point for convex hull.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % compute 3D convex hull t_convex = tic; convexhull_1 = convhulln(op_pset1',{'Qt','Pp'}); convexhull_2 = convhulln(op_pset2',{'Qt','Pp'}); % %show convexhull convexhull_1_x =[]; convexhull_1_y =[]; convexhull_1_z =[]; for i=1:size(convexhull_1,1) for j=1:3 convexhull_1_x = [convexhull_1_x op_pset1(1,convexhull_1(i,j))]; convexhull_1_y = [convexhull_1_y op_pset1(2,convexhull_1(i,j))]; convexhull_1_z = [convexhull_1_z op_pset1(3,convexhull_1(i,j))]; end end % plot3(convexhull_1_x, convexhull_1_y, convexhull_1_z,'d-'); % grid; % axis equal; %draw_data = [convexhull_1_x' convexhull_1_y' convexhull_1_z']; %mesh(draw_data); %M = op_pset1; %D = op_pset2; M_k = 1; D_k = 1; M=[]; D=[]; convex_check = 1; % check convex hull convexhull_tolerance = 0.1; %[m] max_confidence_1 = max(c1(:)); max_confidence_2 = max(c2(:)); threshold = 0.5; confidence_thresh_1 = threshold * max_confidence_1; confidence_thresh_2 = threshold * max_confidence_2; %Initialize data by trans subsampling_factor = 2; h_border_cutoff = round(size(x1,2)*0.1/2); v_border_cutoff = round(size(x1,1)*0.1/2); for i=1+v_border_cutoff:subsampling_factor:size(x1,1)-v_border_cutoff for j=1+h_border_cutoff:subsampling_factor:size(x1,2)-h_border_cutoff M_test = [-x1(i,j) z1(i,j) y1(i,j)]; M_in_flag = inhull(M_test,op_pset1',convexhull_1,convexhull_tolerance); D_test = [-x2(i,j) z2(i,j) y2(i,j)]; D_in_flag = inhull(D_test,op_pset2',convexhull_2,convexhull_tolerance); if M_in_flag == 1 || convex_check == 0 % test point locates in the convex hull %if img1(i,j) >= 50 % intensity filtering for less noise if c1(i,j) >= confidence_thresh_1 % confidence filtering M(:,M_k) = M_test'; %[-x1(i,j); z1(i,j); y1(i,j)]; M_k = M_k + 1; end end if D_in_flag == 1 || convex_check == 0 %if img2(i,j) >= 50 % intensity filtering for less noise if c2(i,j) >= confidence_thresh_2 % confidence filtering D(:,D_k) = D_test'; %[-x2(i,j); z2(i,j); y2(i,j)]; D_k = D_k + 1; end end %temp_pt2 = [-x2(i,j); z2(i,j); y2(i,j)]; %D(:,k) = rot*temp_pt2 + trans; %transed_pt1 = rot*temp_pt + trans; %k = k + 1; end end elapsed_convex = toc(t_convex); %distance filter [M, D] = check_feature_distance_icp(M, D); ap_size=size(M,2); if isempty(M) || isempty(D) fprintf('Error in less point for ICP.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %t_icp = tic; %[Ricp, Ticp, ER, t]=icp(M, D,'Minimize','plane'); %elapsed_icp = toc(t_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); %Transform data-matrix using ICP result %Dicp = Ricp * D + repmat(Ticp, 1, n); t_icp_icp = tic; converged = 0; rmse_total=[]; rot_total=[]; trans_total=[]; match_num_total=[]; while_cnt = 1; while converged == 0 % find correspondent assoicate Dicp = rot * D + repmat(trans, 1, size(D,2)); %p = rand( 20, 2 ); % input data (m x n); n dimensionality %q = rand( 10, 2 ); % query data (d x n) t_kdtree = tic; pt1=[]; pt2=[]; if size(M,2) > size (D,2) tree = kdtree_build( M' ); correspondent_idxs = kdtree_nearest_neighbor(tree, Dicp'); pt2 = D; for i=1:size(correspondent_idxs,1) pt1(:,i) = M(:,correspondent_idxs(i)); end else tree = kdtree_build( Dicp' ); correspondent_idxs = kdtree_nearest_neighbor(tree, M'); pt1 = M; for i=1:size(correspondent_idxs,1) pt2(:,i) = D(:,correspondent_idxs(i)); end end elapsed_kdtree = toc(t_kdtree); %[R_icp, trans_icp, ER, t]=icp(pt1, pt2,'Minimize','plane','WorstRejection',0.1); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(R_icp); % Outlier removal % Compute error t_icp_ransac = tic; pt2_transed= rot * pt2 + repmat(trans, 1, size(pt2,2)); new_cnt = 1; pt1_new=[]; pt2_new=[]; correspondent_idxs_new=[]; for i=1:size(pt1,2) unit_rmse = sqrt(sum((pt2_transed(:,i) - pt1(:,i)).^2)); if unit_rmse < 0.03 pt1_new(:,new_cnt) = pt1(:,i); pt2_new(:,new_cnt) = pt2(:,i); correspondent_idxs_new(new_cnt) = correspondent_idxs(i); new_cnt = new_cnt + 1; end end pt1 = pt1_new; pt2 = pt2_new; correspondent_idxs = correspondent_idxs_new'; % Delete duplicates in correspondent points % correspondent_unique = unique(correspondent_idxs); % correspondent_unique_idx = ones(size(correspondent_idxs)); % for i=1:length(correspondent_unique) % unit_idx = find(correspondent_idxs == correspondent_unique(i)); % if length(unit_idx) > 1 % correspondent_unique_idx(unit_idx)=0; % end % end % % correspondent_delete_idx=find(correspondent_unique_idx == 0); % pt1(:,correspondent_delete_idx') = []; % pt2(:,correspondent_delete_idx') = []; % correspondent_idxs(correspondent_delete_idx,:) = []; if isempty(pt1) || isempty(pt2) fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num=[ap_size;0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % op_pset1_icp = pt1_new; % op_pset2_icp = pt2_new; % elapsed_icp_ransac = toc(t_icp_ransac); %t_icp_ransac = tic; [op_match, match_num, rtime, error_ransac] = run_ransac_points(pt1, pt2, correspondent_idxs', 0); if error_ransac ~= 0 % Error in RANSAC fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end op_pset1_icp = []; op_pset2_icp = []; for i=1:match_num(2) op_pset1_icp(:,i) = pt1(:,op_match(1,i)); op_pset2_icp(:,i) = pt2(:,op_match(2,i)); end elapsed_icp_ransac = toc(t_icp_ransac); % SVD t_svd_icp = tic; %[rot_icp, trans_icp, sta_icp] = find_transform_matrix(op_pset1_icp, op_pset2_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); %elapsed_svd = etime(clock, t_svd); sta_icp =1; t_init = zeros(6,1); [t_init(2), t_init(1), t_init(3)] = rot_to_euler(rot); t_init(4:6) = trans; [rot_icp, trans_icp] = lm_point(op_pset1_icp, op_pset2_icp, t_init); %[rot_icp, trans_icp] = lm_point2plane(op_pset1, op_pset2, t_init); elapsed_svd = toc(t_svd_icp); % M = op_pset1_icp; % D = op_pset2_icp; rot = rot_icp; trans = trans_icp; rot_total(:,:,while_cnt) = rot; trans_total(:,:,while_cnt) = trans; match_num_total(while_cnt) = size(op_pset1_icp,2); % Plot % figure; % plot3(op_pset1_icp(1,:),op_pset1_icp(2,:),op_pset1_icp(3,:),'b*-'); % hold on; % plot3(op_pset2_icp(1,:),op_pset2_icp(2,:),op_pset2_icp(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; % Compute error op_pset1_icp_normal = lsqnormest(op_pset1_icp,4); op_pset2_icp_transed= rot * op_pset2_icp + repmat(trans, 1, size(op_pset2_icp,2)); % rmse_icp = 0; % for i=1:size(M,2) % unit_rmse = sqrt(sum((D_transed(:,i) - M(:,i)).^2)/3); % rmse_icp = rmse_icp + unit_rmse; % end % rmse_icp = rmse_icp / size(M,2); %rmse_icp = rms_error(op_pset1_icp, op_pset2_icp_transed); rmse_icp = rms_error_normal(op_pset1_icp, op_pset2_icp_transed, op_pset1_icp_normal); % point-to-plain op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse_feature = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse_feature = rmse_feature + unit_rmse; % end % rmse_feature = rmse_feature / size(op_pset1,2); rmse_feature= rms_error(op_pset1,op_pset2_transed); rmse_total = [rmse_total (rmse_icp+rmse_feature)/2]; %rmse_total = [rmse_total rmse_icp]; rmse_thresh = 0.001; if length(rmse_total) > 3 rmse_diff = abs(diff(rmse_total)); rmse_diff_length = length(rmse_diff); if rmse_diff(rmse_diff_length) < rmse_thresh && rmse_diff(rmse_diff_length-1) < rmse_thresh && rmse_diff(rmse_diff_length-2) < rmse_thresh converged = 1; end end while_cnt = while_cnt + 1; end [match_rmse match_rmse_idx] = min(rmse_total); %match_rmse = rmse_total(end); %match_rmse_idx = size(rmse_total,2); match_num = [ap_size; match_num_total(match_rmse_idx)]; rot_icp = rot_total(:,:,match_rmse_idx); trans_icp = trans_total(:,:,match_rmse_idx); [phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); elapsed_icp_icp = toc(t_icp_icp); %t_icp_icp = tic; %[Ricp, trans_icp, ER, t]=icp(op_pset1_icp, op_pset2_icp,'Minimize','plane'); %elapsed_icp_icp = toc(t_icp_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); elapsed_icp = toc(t_icp); elapsed_time = [elapsed_convex, elapsed_kdtree, elapsed_icp_ransac, elapsed_icp_icp, elapsed_icp]; %Compute covariane [pose_std] = compute_pose_std(op_pset1_icp,op_pset2_icp, rot_icp, trans_icp); pose_std = pose_std'; M = []; D = []; pt1 = []; pt2 = []; pt1_new=[]; pt2_new=[]; op_pset1 = []; op_pset2 = []; op_pset1_icp = []; op_pset2_icp = []; tree = []; convexhull_1=[]; convexhull_2=[]; M_in_flag=[]; D_in_flag=[]; end
github
rising-turtle/slam_matlab-master
check_stored_matched_points.m
.m
slam_matlab-master/ground_truth_zh/Localization/check_stored_matched_points.m
1,184
utf_8
1620fb7c613849c92ba3def37bcd39da
% Check if there is the stored matched points % % Author : Soonhac Hong ([email protected]) % Date : 3/11/2013 function [exist_flag] = check_stored_matched_points(data_name, dm, first_cframe, second_cframe, isgframe, sequence_data) exist_flag = 0; [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true if strcmp(data_name, 'object_recognition') dataset_dir = strrep(prefix, '/f1',''); else dataset_dir = strrep(prefix, '/d1',''); end else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); end if strcmp(isgframe, 'gframe') dataset_dir = sprintf('%s/matched_points_gframe',dataset_dir); else dataset_dir = sprintf('%s/matched_points',dataset_dir); end file_name = sprintf('d1_%04d_%04d.mat',first_cframe, second_cframe); dirData = dir(dataset_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; if isempty(file_list) return; else for i=1:size(file_list,1) if strcmp(file_list{i}, file_name) exist_flag = 1; break; end end end end
github
rising-turtle/slam_matlab-master
rot_to_euler.m
.m
slam_matlab-master/ground_truth_zh/Localization/rot_to_euler.m
1,068
utf_8
5338a4d30525b25e07f1db2f561d509b
% Calculate the euler angle(yaw, pitch, roll) from rotation matrix % % Yaw is a counterclockwise rotation of phi(alpha) about the z-axis % Pitch is a counterclockwise rotation of theta(beta) about the y-axis % Roll is a counterclockwise rotation of psi(gamma) about the x-axis % % Author : Soonhac Hong ([email protected]) % Date : 3/19/2011 % Reference : S.M. Lavalle : Planning Algorithm (p.97-100) function [phi, theta, psi] = rot_to_euler(rot) % phi= atan2(rot(2,1), rot(1,1)); % theta = atan2(-rot(3,1), sqrt(rot(3,2)^2+rot(3,3)^2)); % psi = atan2(rot(3,2), rot(3,3)); % psi= atan2(rot(2,1), rot(1,1)); % phi = atan2(-rot(3,1), sqrt(rot(3,2)^2+rot(3,3)^2)); % theta = atan2(rot(3,2), rot(3,3)); % Original code from Dr. Ye psi = atan2(-rot(1,2), rot(2, 2)); % yaw about z --->this code is right, but the thesis is wrong. theta = atan2(rot(3,2), -rot(1,2)*sin(psi)+rot(2,2)*cos(psi)); % pitch about x phi = atan2(rot(1,3)*cos(psi)+rot(2,3)*sin(psi),rot(1,1)*cos(psi)+rot(2,1)*sin(psi)); % roll about y end
github
rising-turtle/slam_matlab-master
vro_icp_9_cov_tol_batch_dist.m
.m
slam_matlab-master/ground_truth_zh/Localization/vro_icp_9_cov_tol_batch_dist.m
11,663
utf_8
012db11e606c43c3d00d9a83614fbd7c
% This function compute the transformation of two 3D point clouds by ICP % % Parameters : % % Author : Soonhac Hong ([email protected]) % Date : 9/20/12 % ICP6 + convexhull = ICP9 % ICP9_cov + tolerance adjustment = ICP9_cov_tol function [phi_icp, theta_icp, psi_icp, trans_icp, match_rmse, match_num, elapsed_time, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch_dist(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2) error = 0; sta_icp = 1; t_icp = tic; % test for local minimum in optimization %trans = [0; 0; 0]; %rot = euler_to_rot(0, 27, 0); if size(op_pset1,2) <= 8 || size(op_pset2,2) <= 8 fprintf('Error in less point for convex hull.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % compute 3D convex hull t_convex = tic; convexhull_1 = convhulln(op_pset1',{'Qt','Pp'}); convexhull_2 = convhulln(op_pset2',{'Qt','Pp'}); % %show convexhull % convexhull_1_x =[]; % convexhull_1_y =[]; % convexhull_1_z =[]; % % for i=1:size(convexhull_1,1) % for j=1:3 % convexhull_1_x = [convexhull_1_x op_pset1(1,convexhull_1(i,j))]; % convexhull_1_y = [convexhull_1_y op_pset1(2,convexhull_1(i,j))]; % convexhull_1_z = [convexhull_1_z op_pset1(3,convexhull_1(i,j))]; % end % end % plot3(convexhull_1_x, convexhull_1_y, convexhull_1_z,'d-'); % grid; % axis equal; %draw_data = [convexhull_1_x' convexhull_1_y' convexhull_1_z']; %mesh(draw_data); %M = op_pset1; %D = op_pset2; %M_k = 1; %D_k = 1; M=[]; D=[]; %convex_check = 1; % check convex hull convexhull_tolerance = 0.1; %[m] max_confidence_1 = max(c1(:)); max_confidence_2 = max(c2(:)); threshold = 0.5; confidence_thresh_1 = threshold * max_confidence_1; confidence_thresh_2 = threshold * max_confidence_2; %Initialize data by trans subsampling_factor = 2; h_border_cutoff = round(size(x1,2)*0.1/2); v_border_cutoff = round(size(x1,1)*0.1/2); %M_test=[]; %D_test=[]; M_cf=[]; D_cf=[]; sample_idx=1; for i=1+v_border_cutoff:subsampling_factor:size(x1,1)-v_border_cutoff for j=1+h_border_cutoff:subsampling_factor:size(x1,2)-h_border_cutoff M = [M; -x1(i,j) z1(i,j) y1(i,j)]; D = [D; -x2(i,j) z2(i,j) y2(i,j)]; %if M_in_flag == 1 || convex_check == 0 % test point locates in the convex hull %if img1(i,j) >= 50 % intensity filtering for less noise if c1(i,j) >= confidence_thresh_1 % confidence filtering M_cf(sample_idx,1)=1; %M(:,M_k) = M_test'; %[-x1(i,j); z1(i,j); y1(i,j)]; %M_k = M_k + 1; else M_cf(sample_idx,1)=0; end %end %if D_in_flag == 1 || convex_check == 0 %if img2(i,j) >= 50 % intensity filtering for less noise if c2(i,j) >= confidence_thresh_2 % confidence filtering D_cf(sample_idx,1)=1; %D(:,D_k) = D_test'; %[-x2(i,j); z2(i,j); y2(i,j)]; %D_k = D_k + 1; else D_cf(sample_idx,1)=0; end %end %temp_pt2 = [-x2(i,j); z2(i,j); y2(i,j)]; %D(:,k) = rot*temp_pt2 + trans; %transed_pt1 = rot*temp_pt + trans; %k = k + 1; sample_idx = sample_idx + 1; end end m_cf_idx = M_cf(:) == 0; d_cf_idx = D_cf(:) == 0; M(m_cf_idx,:)=[]; D(d_cf_idx,:)=[]; M_in_flag = inhull(M,op_pset1',convexhull_1,convexhull_tolerance); D_in_flag = inhull(D,op_pset2',convexhull_2,convexhull_tolerance); M_in_flag_idx = M_in_flag(:) == 0; D_in_flag_idx = D_in_flag(:) == 0; M(M_in_flag_idx,:)=[]; D(D_in_flag_idx,:)=[]; M=M'; D=D'; elapsed_convex = toc(t_convex); %distance filter [M, D] = check_feature_distance_icp(M, D); ap_size=size(M,2); if isempty(M) || isempty(D) fprintf('Error in less point for ICP.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %t_icp = tic; %[Ricp, Ticp, ER, t]=icp(M, D,'Minimize','plane'); %elapsed_icp = toc(t_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); %Transform data-matrix using ICP result %Dicp = Ricp * D + repmat(Ticp, 1, n); t_icp_icp = tic; converged = 0; rmse_total=[]; rot_total=[]; trans_total=[]; match_num_total=[]; while_cnt = 1; while converged == 0 % find correspondent assoicate Dicp = rot * D + repmat(trans, 1, size(D,2)); %p = rand( 20, 2 ); % input data (m x n); n dimensionality %q = rand( 10, 2 ); % query data (d x n) t_kdtree = tic; pt1=[]; pt2=[]; if size(M,2) > size (D,2) tree = kdtree_build( M' ); correspondent_idxs = kdtree_nearest_neighbor(tree, Dicp'); pt2 = D; for i=1:size(correspondent_idxs,1) pt1(:,i) = M(:,correspondent_idxs(i)); end else tree = kdtree_build( Dicp' ); correspondent_idxs = kdtree_nearest_neighbor(tree, M'); pt1 = M; for i=1:size(correspondent_idxs,1) pt2(:,i) = D(:,correspondent_idxs(i)); end end elapsed_kdtree = toc(t_kdtree); %[R_icp, trans_icp, ER, t]=icp(pt1, pt2,'Minimize','plane','WorstRejection',0.1); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(R_icp); % Outlier removal % Compute error t_icp_ransac = tic; pt2_transed= rot * pt2 + repmat(trans, 1, size(pt2,2)); new_cnt = 1; pt1_new=[]; pt2_new=[]; correspondent_idxs_new=[]; for i=1:size(pt1,2) unit_rmse = sqrt(sum((pt2_transed(:,i) - pt1(:,i)).^2)); if unit_rmse < 0.03 pt1_new(:,new_cnt) = pt1(:,i); pt2_new(:,new_cnt) = pt2(:,i); correspondent_idxs_new(new_cnt) = correspondent_idxs(i); new_cnt = new_cnt + 1; end end pt1 = pt1_new; pt2 = pt2_new; correspondent_idxs = correspondent_idxs_new'; % Delete duplicates in correspondent points % correspondent_unique = unique(correspondent_idxs); % correspondent_unique_idx = ones(size(correspondent_idxs)); % for i=1:length(correspondent_unique) % unit_idx = find(correspondent_idxs == correspondent_unique(i)); % if length(unit_idx) > 1 % correspondent_unique_idx(unit_idx)=0; % end % end % % correspondent_delete_idx=find(correspondent_unique_idx == 0); % pt1(:,correspondent_delete_idx') = []; % pt2(:,correspondent_delete_idx') = []; % correspondent_idxs(correspondent_delete_idx,:) = []; if isempty(pt1) || isempty(pt2) fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num=[ap_size;0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % op_pset1_icp = pt1_new; % op_pset2_icp = pt2_new; % elapsed_icp_ransac = toc(t_icp_ransac); %t_icp_ransac = tic; [op_match, match_num, rtime, error_ransac] = run_ransac_points(pt1, pt2, correspondent_idxs', 0); if error_ransac ~= 0 % Error in RANSAC fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end op_pset1_icp = []; op_pset2_icp = []; for i=1:match_num(2) op_pset1_icp(:,i) = pt1(:,op_match(1,i)); op_pset2_icp(:,i) = pt2(:,op_match(2,i)); end elapsed_icp_ransac = toc(t_icp_ransac); % SVD t_svd_icp = tic; %[rot_icp, trans_icp, sta_icp] = find_transform_matrix(op_pset1_icp, op_pset2_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); %elapsed_svd = etime(clock, t_svd); sta_icp =1; t_init = zeros(6,1); [t_init(2), t_init(1), t_init(3)] = rot_to_euler(rot); t_init(4:6) = trans; [rot_icp, trans_icp] = lm_point(op_pset1_icp, op_pset2_icp, t_init); %[rot_icp, trans_icp] = lm_point2plane(op_pset1, op_pset2, t_init); elapsed_svd = toc(t_svd_icp); % M = op_pset1_icp; % D = op_pset2_icp; rot = rot_icp; trans = trans_icp; rot_total(:,:,while_cnt) = rot; trans_total(:,:,while_cnt) = trans; match_num_total(while_cnt) = size(op_pset1_icp,2); % Plot % figure; % plot3(op_pset1_icp(1,:),op_pset1_icp(2,:),op_pset1_icp(3,:),'b*-'); % hold on; % plot3(op_pset2_icp(1,:),op_pset2_icp(2,:),op_pset2_icp(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; % Compute error op_pset1_icp_normal = lsqnormest(op_pset1_icp,4); op_pset2_icp_transed= rot * op_pset2_icp + repmat(trans, 1, size(op_pset2_icp,2)); % rmse_icp = 0; % for i=1:size(M,2) % unit_rmse = sqrt(sum((D_transed(:,i) - M(:,i)).^2)/3); % rmse_icp = rmse_icp + unit_rmse; % end % rmse_icp = rmse_icp / size(M,2); %rmse_icp = rms_error(op_pset1_icp, op_pset2_icp_transed); rmse_icp = rms_error_normal(op_pset1_icp, op_pset2_icp_transed, op_pset1_icp_normal); % point-to-plain op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse_feature = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse_feature = rmse_feature + unit_rmse; % end % rmse_feature = rmse_feature / size(op_pset1,2); rmse_feature= rms_error(op_pset1,op_pset2_transed); rmse_total = [rmse_total (rmse_icp+rmse_feature)/2]; %rmse_total = [rmse_total rmse_icp]; rmse_thresh = 0.001; if length(rmse_total) > 3 rmse_diff = abs(diff(rmse_total)); rmse_diff_length = length(rmse_diff); if rmse_diff(rmse_diff_length) < rmse_thresh && rmse_diff(rmse_diff_length-1) < rmse_thresh && rmse_diff(rmse_diff_length-2) < rmse_thresh converged = 1; end end while_cnt = while_cnt + 1; end [match_rmse match_rmse_idx] = min(rmse_total); %match_rmse = rmse_total(end); %match_rmse_idx = size(rmse_total,2); match_num = [ap_size; match_num_total(match_rmse_idx)]; rot_icp = rot_total(:,:,match_rmse_idx); trans_icp = trans_total(:,:,match_rmse_idx); [phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); elapsed_icp_icp = toc(t_icp_icp); %t_icp_icp = tic; %[Ricp, trans_icp, ER, t]=icp(op_pset1_icp, op_pset2_icp,'Minimize','plane'); %elapsed_icp_icp = toc(t_icp_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); elapsed_icp = toc(t_icp); elapsed_time = [elapsed_convex, elapsed_kdtree, elapsed_icp_ransac, elapsed_icp_icp, elapsed_icp]; %Compute covariane [pose_std] = compute_pose_std(op_pset1_icp,op_pset2_icp, rot_icp, trans_icp); pose_std = pose_std'; M = []; D = []; pt1 = []; pt2 = []; pt1_new=[]; pt2_new=[]; op_pset1 = []; op_pset2 = []; op_pset1_icp = []; op_pset2_icp = []; tree = []; convexhull_1=[]; convexhull_2=[]; % convexhull_1_x =[]; % convexhull_1_y =[]; % convexhull_1_z =[]; M_cf=[]; D_cf=[]; m_cf_idx=[]; d_cf_idx=[]; M_in_flag=[]; D_in_flag=[]; M_in_flag_idx=[]; D_in_flag_idx=[]; op_pset1_icp_normal=[]; op_pset2_icp_transed=[]; end
github
rising-turtle/slam_matlab-master
load_icp_pose.m
.m
slam_matlab-master/ground_truth_zh/Localization/load_icp_pose.m
1,573
utf_8
0187e4f56957260f4e18836e5804c8cf
% Load matched points from a file % % Author : Soonhac Hong ([email protected]) % Date : 3/11/2013 %function [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, isgframe, sequence_data) function [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = load_icp_pose(data_name, dm, first_cframe, second_cframe, icp_mode, sequence_data) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true dataset_dir = strrep(prefix, '/d1',''); if strcmp(icp_mode, 'icp_ch') file_name = sprintf('%s/icp_ch_pose/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); else file_name = sprintf('%s/icp_pose/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); end else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); if strcmp(icp_mode, 'icp_ch') file_name = sprintf('%s/icp_ch_pose/d1_%04d_d%d_%04d.mat',dataset_dir, first_cframe, dm, second_cframe); else file_name = sprintf('%s/icp_pose/d1_%04d_d%d_%04d.mat',dataset_dir, first_cframe, dm, second_cframe); end end % if strcmp(isgframe, 'gframe') % file_name = sprintf('%s/matched_points_gframe/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); % else % file_name = sprintf('%s/matched_points/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); % end load(file_name); end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_cov_fast_fast_dist.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_cov_fast_fast_dist.m
16,414
utf_8
6d555711bc67c37d10257bef2804a3ea
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_cov_fast_fast_dist(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, dis) if nargin < 13 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data cframe = sframe; else cframe = j; end first_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe); end %Read second Data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe); end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe, 'none') == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2, 'none'); else [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, 'none'); t_svd = tic; end [op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta == 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_cov_fast_fast_dist2.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_cov_fast_fast_dist2.m
17,174
utf_8
9d45403332d443c4e248983141bed911
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_cov_fast_fast_dist2(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, sequence_data, is_10M_data, dis) if nargin < 15 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true cframe = sframe; else cframe = j; end first_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data) == 0 if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre, sequence_data); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe, sequence_data); end %Read second Data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data) == 0 if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2, sequence_data); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe, sequence_data); end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 if is_10M_data == 1 valid_dist_max = 8; % 5m else valid_dist_max = 5; % 5m end valid_dist_min = 0.8; % 0.8m match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; temp_pt1=[-x1(ROW1, COL1), z1(ROW1, COL1), y1(ROW1, COL1)]; temp_pt2=[-x2(ROW2, COL2), z2(ROW2, COL2), y2(ROW2, COL2)]; temp_pt1_dist = sqrt(sum(temp_pt1.^2)); temp_pt2_dist = sqrt(sum(temp_pt2.^2)); if temp_pt1_dist >= valid_dist_min && temp_pt1_dist <= valid_dist_max && temp_pt2_dist >= valid_dist_min && temp_pt2_dist <= valid_dist_max %if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 39 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2, 'none', sequence_data); else [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); t_svd = tic; end %[op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta == 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
save_depth_features.m
.m
slam_matlab-master/ground_truth_zh/Localization/save_depth_features.m
429
utf_8
ac126f69540fa93b52e177bf4693644c
% Save sift visual feature into a file % % Author : Soonhac Hong ([email protected]) % Date : 2/13/2013 function save_depth_features(data_name, dm, cframe, depth_frm, depth_des, depth_ct) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); dataset_dir = strrep(prefix, '/d1',''); file_name = sprintf('%s/depth_feature/d1_%04d.mat',dataset_dir, cframe); save(file_name, 'depth_frm', 'depth_des', 'depth_ct'); end
github
rising-turtle/slam_matlab-master
get_kinect_tum_dir_name.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_kinect_tum_dir_name.m
823
utf_8
54ffe57adc759fb2881357d54c5bc99e
% Get directory name of kinect_tum data set % % Parameters % dm : index of directory of data % % Author : Soonhac Hong ([email protected]) % Date : 9/25/12 function [dir_name_list]=get_kinect_tum_dir_name() dir_name_list={'rgbd_dataset_freiburg1_xyz','rgbd_dataset_freiburg1_floor','rgbd_dataset_freiburg2_large_no_loop','rgbd_dataset_freiburg2_large_with_loop','rgbd_dataset_freiburg2_pioneer_slam','rgbd_dataset_freiburg2_pioneer_slam2','rgbd_dataset_freiburg2_pioneer_slam3','rgbd_dataset_freiburg3_long_office_household','rgbd_dataset_freiburg3_nostructure_texture_near_withloop','rgbd_dataset_freiburg3_structure_notexture_far','rgbd_dataset_freiburg3_structure_notexture_near','rgbd_dataset_freiburg3_structure_texture_far','rgbd_dataset_freiburg3_structure_texture_near'}; %dir_name=dir_name_list{dir_index}; end
github
rising-turtle/slam_matlab-master
get_map_filename.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_map_filename.m
268
utf_8
af875fbea341b78297f219d2a569d248
% Get directory name of motive datasets % % Author : Soonhac Hong ([email protected]) % Date : 11/20/13 function map_filename_lists=get_map_filename() map_filename_lists = {'map1','map2','map3','map4','map5','map6','map7','map8','map9','it50','it100','it150'}; end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_icp2_cov_f_f_dist2_loadicp_nobpc.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_icp2_cov_f_f_dist2_loadicp_nobpc.m
23,316
utf_8
7a78d4b89d5c7e17ecaa11af211713c6
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 8/30/12 % % Load icp_pose function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_icp2_cov_f_f_dist2_loadicp_nobpc(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, icp_mode, is_10M_data, dis) if nargin < 15 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') || strcmp(data_name, 'swing2') || strcmp(data_name, 'motive') || strcmp(data_name, 'map')% Dynamic data cframe = sframe; sequence_data = true; else cframe = j; sequence_data = false; end first_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 %[img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); %[frm1,des1] = vl_sift(single(img1)) ; else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre, sequence_data, image_name); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); end %Read second Data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing')|| strcmp(data_name, 'swing2') || strcmp(data_name, 'motive') || strcmp(data_name, 'map')% Dynamic data %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); %[frm2,des2] = vl_sift(single(img2)) ; else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2, sequence_data, image_name); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe,'none', sequence_data) == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %[match, scores] = vl_ubcmatch(des1,des2) ; %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 match_new = []; cnt_new = 1; pnum = size(match, 2); if is_10M_data == 1 valid_dist_max = 8; % 5m else valid_dist_max = 5; % 5m end valid_dist_min = 0.8; % 0.8m if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; temp_pt1=[-x1(ROW1, COL1), z1(ROW1, COL1), y1(ROW1, COL1)]; temp_pt2=[-x2(ROW2, COL2), z2(ROW2, COL2), y2(ROW2, COL2)]; temp_pt1_dist = sqrt(sum(temp_pt1.^2)); temp_pt2_dist = sqrt(sum(temp_pt2.^2)); if temp_pt1_dist >= valid_dist_min && temp_pt1_dist <= valid_dist_max && temp_pt2_dist >= valid_dist_min && temp_pt2_dist <= valid_dist_max %if img1(ROW1, COL1) >= 0 && img2(ROW2, COL2) >= 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; % stdev_threshold = 0.1; % stdev_count = 0; % count_threshold = 15; % mean_threshold = 0.1; % mean_count = 0; % window_size = 30; % debug_data=[]; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % if cnum >= valid_ransac % break; % end % if cnum/pnum >= inlier_ratio % break; % enddynamic_data_index % total_cnum(i)=cnum; % if i > window_size && inliers_std ~= 0 % inliers_std_prev = inliers_std; % inliers_std = std(total_cnum(i-window_size:i)); %Moving STDEV % inliers_std_delta = abs(inliers_std - inliers_std_prev)/inliers_std_prev; % % inliers_mean_prev = inliers_mean; % inliers_mean = mean(total_cnum(i-window_size:i)); %Moving STDEV % inliers_mean_delta = abs(inliers_mean - inliers_mean_prev)/inliers_mean_prev; % % if inliers_std_delta < stdev_threshold % stdev_count = stdev_count + 1; % else % stdev_count = 0; % end % % if inliers_mean_delta < mean_threshold % mean_count = mean_count + 1; % else % mean_count = 0; % end % % inlier_ratio = max(total_cnum)/pnum; % % count_threshold = 120000 / ((inlier_ratio*100)^2); %-26 * (inlier_ratio*100 - 20) + 800; % % if stdev_count > count_threshold %&& mean_count > count_threshold % break; % end % else % inliers_std = std(total_cnum); % inliers_mean = mean(total_cnum); % end if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1 break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %% Run SVD %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2,'none', sequence_data); else [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe,'none', sequence_data); t_svd = tic; end %[op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta <= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %Test LM %[rot_lm, trans_lm] = lm_point(op_pset1, op_pset2); % [rot_lm, trans_lm] = lm_point2plane(op_pset1, op_pset2); % [phi_lm, theta_lm, psi_lm] = rot_to_euler(rot_lm); % [theta*180/pi theta_lm*180/pi] % [phi*180/pi phi_lm*180/pi] % [psi*180/pi psi_lm*180/pi] % Save feature points %feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; % Compute RMSE op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse = rmse + unit_rmse; % end % rmse_feature = rmse / size(op_pset1,2); %rmse_feature = rms_error(op_pset1, op_pset2_transed); % Show correspondent points % plot3(op_pset1(1,:),op_pset1(2,:),op_pset1(3,:),'b*-'); % hold on; % plot3(op_pset2(1,:),op_pset2(2,:),op_pset2(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; %Compute the elapsed time %rt_total = etime(clock,t); %elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; %% Run ICP %[phi_icp, theta_icp, psi_icp, trans_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_2(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_3(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_4(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_5(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); if check_stored_icp_pose(data_name, dm, first_cframe, second_cframe, icp_mode, sequence_data) [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = load_icp_pose(data_name, dm, first_cframe, second_cframe, icp_mode, sequence_data); else if strcmp(icp_mode, 'icp_ch') [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch_dist(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); else [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_6_cov(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_6_cov_dynamic(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); end if error == 0 && sta_icp == 1 save_icp_pose(data_name, dm, first_cframe, second_cframe, icp_mode, sequence_data, phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std); end end %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_10(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_13(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %Check status of SVD if sta_icp == 0 || error ~= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta_icp == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %elapsed_icp = toc(t_icp); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; %rot = rot_icp; % [rmse_feature rmse_icp] % [theta*180/pi theta_icp*180/pi] % [trans(1) trans_icp(1)] %if rmse_icp <= rmse_feature trans = trans_icp; phi = phi_icp; theta = theta_icp; psi = psi_icp; %end %convert degree % r2d=180.0/pi; % phi=phi*r2d; % theta=theta*r2d; % psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
vro_icp_9_cov_tol_dist_EKF.m
.m
slam_matlab-master/ground_truth_zh/Localization/vro_icp_9_cov_tol_dist_EKF.m
11,437
utf_8
9c985fd9089bbf1de243e1f8f0ab0be1
% This function compute the transformation of two 3D point clouds by ICP % % Parameters : % % Author : Soonhac Hong ([email protected]) % Date : 9/20/12 % ICP6 + convexhull = ICP9 % ICP9_cov + tolerance adjustment = ICP9_cov_tol % ICP9_cov_tol_dist + adjust coordinate for EKF = ICP9_cov_tol_dist_EKF function [phi_icp, theta_icp, psi_icp, trans_icp, match_rmse, match_num, elapsed_time, sta_icp, error, pose_std] = vro_icp_9_cov_tol_dist_EKF(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2) error = 0; sta_icp = 1; t_icp = tic; % test for local minimum in optimization %trans = [0; 0; 0]; %rot = euler_to_rot(0, 27, 0); if size(op_pset1,2) <= 8 || size(op_pset2,2) <= 8 fprintf('Error in less point for convex hull.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % compute 3D convex hull t_convex = tic; convexhull_1 = convhulln(op_pset1',{'Qt','Pp'}); convexhull_2 = convhulln(op_pset2',{'Qt','Pp'}); % %show convexhull convexhull_1_x =[]; convexhull_1_y =[]; convexhull_1_z =[]; for i=1:size(convexhull_1,1) for j=1:3 convexhull_1_x = [convexhull_1_x op_pset1(1,convexhull_1(i,j))]; convexhull_1_y = [convexhull_1_y op_pset1(2,convexhull_1(i,j))]; convexhull_1_z = [convexhull_1_z op_pset1(3,convexhull_1(i,j))]; end end % plot3(convexhull_1_x, convexhull_1_y, convexhull_1_z,'d-'); % grid; % axis equal; %draw_data = [convexhull_1_x' convexhull_1_y' convexhull_1_z']; %mesh(draw_data); %M = op_pset1; %D = op_pset2; M_k = 1; D_k = 1; M=[]; D=[]; convex_check = 1; % check convex hull convexhull_tolerance = 0.1; %[m] max_confidence_1 = max(c1(:)); max_confidence_2 = max(c2(:)); threshold = 0.5; confidence_thresh_1 = threshold * max_confidence_1; confidence_thresh_2 = threshold * max_confidence_2; %Initialize data by trans subsampling_factor = 2; h_border_cutoff = round(size(x1,2)*0.1/2); v_border_cutoff = round(size(x1,1)*0.1/2); for i=1+v_border_cutoff:subsampling_factor:size(x1,1)-v_border_cutoff for j=1+h_border_cutoff:subsampling_factor:size(x1,2)-h_border_cutoff M_test = [-x1(i,j) -y1(i,j) z1(i,j)]; M_in_flag = inhull(M_test,op_pset1',convexhull_1,convexhull_tolerance); D_test = [-x2(i,j) -y2(i,j) z2(i,j)]; D_in_flag = inhull(D_test,op_pset2',convexhull_2,convexhull_tolerance); if M_in_flag == 1 || convex_check == 0 % test point locates in the convex hull %if img1(i,j) >= 50 % intensity filtering for less noise if c1(i,j) >= confidence_thresh_1 % confidence filtering M(:,M_k) = M_test'; %[-x1(i,j); z1(i,j); y1(i,j)]; M_k = M_k + 1; end end if D_in_flag == 1 || convex_check == 0 %if img2(i,j) >= 50 % intensity filtering for less noise if c2(i,j) >= confidence_thresh_2 % confidence filtering D(:,D_k) = D_test'; %[-x2(i,j); z2(i,j); y2(i,j)]; D_k = D_k + 1; end end %temp_pt2 = [-x2(i,j); z2(i,j); y2(i,j)]; %D(:,k) = rot*temp_pt2 + trans; %transed_pt1 = rot*temp_pt + trans; %k = k + 1; end end elapsed_convex = toc(t_convex); %distance filter [M, D] = check_feature_distance_icp(M, D); ap_size=size(M,2); if isempty(M) || isempty(D) fprintf('Error in less point for ICP.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %t_icp = tic; %[Ricp, Ticp, ER, t]=icp(M, D,'Minimize','plane'); %elapsed_icp = toc(t_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); %Transform data-matrix using ICP result %Dicp = Ricp * D + repmat(Ticp, 1, n); t_icp_icp = tic; converged = 0; rmse_total=[]; rot_total=[]; trans_total=[]; match_num_total=[]; while_cnt = 1; while converged == 0 % find correspondent assoicate Dicp = rot * D + repmat(trans, 1, size(D,2)); %p = rand( 20, 2 ); % input data (m x n); n dimensionality %q = rand( 10, 2 ); % query data (d x n) t_kdtree = tic; pt1=[]; pt2=[]; if size(M,2) > size (D,2) tree = kdtree_build( M' ); correspondent_idxs = kdtree_nearest_neighbor(tree, Dicp'); pt2 = D; for i=1:size(correspondent_idxs,1) pt1(:,i) = M(:,correspondent_idxs(i)); end else tree = kdtree_build( Dicp' ); correspondent_idxs = kdtree_nearest_neighbor(tree, M'); pt1 = M; for i=1:size(correspondent_idxs,1) pt2(:,i) = D(:,correspondent_idxs(i)); end end elapsed_kdtree = toc(t_kdtree); %[R_icp, trans_icp, ER, t]=icp(pt1, pt2,'Minimize','plane','WorstRejection',0.1); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(R_icp); % Outlier removal % Compute error t_icp_ransac = tic; pt2_transed= rot * pt2 + repmat(trans, 1, size(pt2,2)); new_cnt = 1; pt1_new=[]; pt2_new=[]; correspondent_idxs_new=[]; for i=1:size(pt1,2) unit_rmse = sqrt(sum((pt2_transed(:,i) - pt1(:,i)).^2)); if unit_rmse < 0.03 pt1_new(:,new_cnt) = pt1(:,i); pt2_new(:,new_cnt) = pt2(:,i); correspondent_idxs_new(new_cnt) = correspondent_idxs(i); new_cnt = new_cnt + 1; end end pt1 = pt1_new; pt2 = pt2_new; correspondent_idxs = correspondent_idxs_new'; % Delete duplicates in correspondent points % correspondent_unique = unique(correspondent_idxs); % correspondent_unique_idx = ones(size(correspondent_idxs)); % for i=1:length(correspondent_unique) % unit_idx = find(correspondent_idxs == correspondent_unique(i)); % if length(unit_idx) > 1 % correspondent_unique_idx(unit_idx)=0; % end % end % % correspondent_delete_idx=find(correspondent_unique_idx == 0); % pt1(:,correspondent_delete_idx') = []; % pt2(:,correspondent_delete_idx') = []; % correspondent_idxs(correspondent_delete_idx,:) = []; if isempty(pt1) || isempty(pt2) fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num=[ap_size;0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % op_pset1_icp = pt1_new; % op_pset2_icp = pt2_new; % elapsed_icp_ransac = toc(t_icp_ransac); %t_icp_ransac = tic; [op_match, match_num, rtime, error_ransac] = run_ransac_points(pt1, pt2, correspondent_idxs', 0); if error_ransac ~= 0 % Error in RANSAC fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end op_pset1_icp = []; op_pset2_icp = []; for i=1:match_num(2) op_pset1_icp(:,i) = pt1(:,op_match(1,i)); op_pset2_icp(:,i) = pt2(:,op_match(2,i)); end elapsed_icp_ransac = toc(t_icp_ransac); % SVD t_svd_icp = tic; %[rot_icp, trans_icp, sta_icp] = find_transform_matrix(op_pset1_icp, op_pset2_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); %elapsed_svd = etime(clock, t_svd); sta_icp =1; t_init = zeros(6,1); %[t_init(2), t_init(1), t_init(3)] = rot_to_euler(rot); [t_init(1:3)] = R2e(rot); t_init(4:6) = trans; [rot_icp, trans_icp] = lm_point_EKF(op_pset1_icp, op_pset2_icp, t_init); %[rot_icp, trans_icp] = lm_point2plane(op_pset1, op_pset2, t_init); elapsed_svd = toc(t_svd_icp); % M = op_pset1_icp; % D = op_pset2_icp; rot = rot_icp; trans = trans_icp; rot_total(:,:,while_cnt) = rot; trans_total(:,:,while_cnt) = trans; match_num_total(while_cnt) = size(op_pset1_icp,2); % Plot % figure; % plot3(op_pset1_icp(1,:),op_pset1_icp(2,:),op_pset1_icp(3,:),'b*-'); % hold on; % plot3(op_pset2_icp(1,:),op_pset2_icp(2,:),op_pset2_icp(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; % Compute error op_pset1_icp_normal = lsqnormest(op_pset1_icp,4); op_pset2_icp_transed= rot * op_pset2_icp + repmat(trans, 1, size(op_pset2_icp,2)); % rmse_icp = 0; % for i=1:size(M,2) % unit_rmse = sqrt(sum((D_transed(:,i) - M(:,i)).^2)/3); % rmse_icp = rmse_icp + unit_rmse; % end % rmse_icp = rmse_icp / size(M,2); %rmse_icp = rms_error(op_pset1_icp, op_pset2_icp_transed); rmse_icp = rms_error_normal(op_pset1_icp, op_pset2_icp_transed, op_pset1_icp_normal); % point-to-plain op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse_feature = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse_feature = rmse_feature + unit_rmse; % end % rmse_feature = rmse_feature / size(op_pset1,2); rmse_feature= rms_error(op_pset1,op_pset2_transed); rmse_total = [rmse_total (rmse_icp+rmse_feature)/2]; %rmse_total = [rmse_total rmse_icp]; rmse_thresh = 0.001; if length(rmse_total) > 3 rmse_diff = abs(diff(rmse_total)); rmse_diff_length = length(rmse_diff); if rmse_diff(rmse_diff_length) < rmse_thresh && rmse_diff(rmse_diff_length-1) < rmse_thresh && rmse_diff(rmse_diff_length-2) < rmse_thresh converged = 1; end end while_cnt = while_cnt + 1; end [match_rmse match_rmse_idx] = min(rmse_total); %match_rmse = rmse_total(end); %match_rmse_idx = size(rmse_total,2); match_num = [ap_size; match_num_total(match_rmse_idx)]; rot_icp = rot_total(:,:,match_rmse_idx); trans_icp = trans_total(:,:,match_rmse_idx); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); [euler_icp] = R2e(rot_icp); %rot_to_euler(rot_icp); phi_icp = euler_icp(1); theta_icp = euler_icp(2); psi_icp = euler_icp(3); elapsed_icp_icp = toc(t_icp_icp); %t_icp_icp = tic; %[Ricp, trans_icp, ER, t]=icp(op_pset1_icp, op_pset2_icp,'Minimize','plane'); %elapsed_icp_icp = toc(t_icp_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); elapsed_icp = toc(t_icp); elapsed_time = [elapsed_convex, elapsed_kdtree, elapsed_icp_ransac, elapsed_icp_icp, elapsed_icp]; %Compute covariane %[pose_std] = compute_pose_std(op_pset1_icp,op_pset2_icp, rot_icp, trans_icp); %pose_std = pose_std'; pose_std = []; % M = []; % D = []; % pt1 = []; % pt2 = []; % pt1_new=[]; % pt2_new=[]; % op_pset1 = []; % op_pset2 = []; % op_pset1_icp = []; % op_pset2_icp = []; % tree = []; % convexhull_1=[]; % convexhull_2=[]; % M_in_flag=[]; % D_in_flag=[]; clear M D pt1 pt2 pt1_new pt2_new op_pset1 op_pset2 op_pset1_icp op_pset2_icp tree convexhull_1 convexhull_2 M_in_flag D_in_flag convexhull_1_x convexhull_1_y convexhull_1_z clear FUN end
github
rising-turtle/slam_matlab-master
LoadSR_no_bpc_time_single_binary.m
.m
slam_matlab-master/ground_truth_zh/Localization/LoadSR_no_bpc_time_single_binary.m
6,295
utf_8
c01368aeffe7d712b1c93d366697a3ee
% Load data from Swiss Ranger % % Parameters % data_name : the directory name of data % dm : index of directory of data % j : index of frame % % Author : Soonhac Hong ([email protected]) % Date : 4/20/11 % No bad pixel compensation function [img, x, y, z, c, rtime, error] = LoadSR_no_bpc_time_single_binary(data_name, filter_name, boarder_cut_off, dm, j, scale, type_value) % if nargin < 6 % scale = 1; % end %apitch=-43+3*dm; %[prefix, err]=sprintf('../data/d%d_%d/d%d', dm, apitch, dm); % [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); % % if j<10 % [s, err]=sprintf('%s_000%d.dat', prefix, j); % elseif j<100 % [s, err]=sprintf('%s_00%d.dat', prefix, j); % elseif j<1000 % [s, err]=sprintf('%s_0%d.dat', prefix, j); % else % [s, err]=sprintf('%s_%d.dat', prefix, j); % end img=[]; x=[]; y=[]; z=[]; c=[]; error=0; rtime=0; %s_binary='D:\soonhac\Project\PNBD\SW\sr4000\SwissRangerSampleGui\data\d1_0001.bdat'; %s_binary='d1_0001.bdat'; %s_binary=sprintf('E:\\data\\motive\\m5_swing_loop_2\\processed_data\\binary_data\\d1_%04d.bdat',j); %s_binary=sprintf('E:\\data\\swing\\revisiting2_10m\\processed_data\\binary_data\\d1_%04d.bdat',j); %s_binary=sprintf('E:\\data\\Amir\\processed_data\\exp1_bus_door_straight_150_Copy\\binary_data\\d1_%04d.bdat',j); %s_binary=sprintf('D:\\Soonhac\\Data\\sr4k\\exp1_bus_door_straight_150_Copy\\binary_data\\d1_%04d.bdat',j); %s_binary=sprintf('D:\\Soonhac\\Data\\sr4k\\smart_cane\\binary_data\\d1_%04d.bdat',j); % for KCLCD test %s_binary=sprintf('C:\\SC-DATA-TRANSFER\\d1_0001.bdat'); s_binary=sprintf('C:\\SC-DATA-TRANSFER\\d1_%04d.bdat',j); % for running demo %s_binary=sprintf('D:\\Soonhac\\Data\\sr4k\\smart_cane\\exp2_etas523_lefthallway_exp1\\d1_%04d.bdat',j); % for KCLCD test confidence_read=1; fw=1; sr4k_image_width = 176; sr4k_image_height = 144; sr4k_image_size=[sr4k_image_height sr4k_image_width]; %t_pre = clock; %cputime; t_pre = tic; %a = load(s); % text file fileID=fopen(s_binary); if fileID==-1 %disp('File open fails !!'); error=-1; return; end %a=fread(fileID,[sr4k_image_width*3,sr4k_image_height],'float'); %fseek(fileID,sr4k_image_height*3*sr4k_image_width,'bof'); %b=fread(fileID,[sr4k_image_width*2,sr4k_image_height],'uint16'); %a=vec2mat(a',sr4k_image_width); z=fread(fileID,[sr4k_image_width,sr4k_image_height],'float'); x=fread(fileID,[sr4k_image_width,sr4k_image_height],'float'); y=fread(fileID,[sr4k_image_width,sr4k_image_height],'float'); img=fread(fileID,[sr4k_image_width,sr4k_image_height],'uint16'); c=fread(fileID,[sr4k_image_width,sr4k_image_height],'uint16'); fclose(fileID); z=z'; x=x'; y=y'; img=img'; c=c'; % k=144*3+1; % img = double(b(1:sr4k_image_height, :)); % z = a(1:144, :); % x = a(145:288, :); % y = a(289:144*3, :); % z = medfilt2(z,[fw fw]); x = medfilt2(x, [fw fw]); y = medfilt2(y, [fw fw]); %time_stamp = a(721,1); % time stamp time_stamp=0; % if confidence_read == 1 % c = b(sr4k_image_height+1:sr4k_image_height*2, :); % %c = a(144*4+1:144*5, :); % % Apply median filter to a pixel which confidence leve is zero. % %confidence_cut_off = 1; % %[img, x, y, z, c] = compensate_badpixel(img, x, y, z, c, confidence_cut_off); % else % c = 0; % end img_size=size(img); x_size=size(x); y_size=size(y); z_size=size(z); c_size=size(c); if sum(img_size-sr4k_image_size)~=0 || sum(x_size-sr4k_image_size)~=0 || sum(y_size-sr4k_image_size)~=0 || sum(z_size-sr4k_image_size)~=0 || sum(c_size-sr4k_image_size)~=0 %disp('One of matrix is corrupted.'); error=-1; return; end %Cut-off on the horizontal boarder if boarder_cut_off > 0 img=cut_boarder(img,boarder_cut_off); x=cut_boarder(x,boarder_cut_off); y=cut_boarder(y,boarder_cut_off); z=cut_boarder(z,boarder_cut_off); end %Scale intensity image to [0 255] if scale == 1 img = scale_img(img, fw, type_value, 'intensity'); end % % Adaptive histogram equalization img = adapthisteq(img); %img = histeq(img); %filtering %filter_list={'none','median','gaussian'}; gaussian_h = fspecial('gaussian',[3 3],1); %sigma = 1 gaussian_h_5 = fspecial('gaussian',[5 5],1); %sigma = 1 switch filter_name case 'median' img=medfilt2(img, [3 3]); x=medfilt2(x, [3 3]); y=medfilt2(y, [3 3]); z=medfilt2(z, [3 3]); case 'median5' img=medfilt2(img, [5 5]); x=medfilt2(x, [5 5]); y=medfilt2(y, [5 5]); z=medfilt2(z, [5 5]); case 'gaussian' img=imfilter(img, gaussian_h,'replicate'); x=imfilter(x, gaussian_h,'replicate'); y=imfilter(y, gaussian_h,'replicate'); z=imfilter(z, gaussian_h,'replicate'); case 'gaussian_edge_std' img=imfilter(img, gaussian_h,'replicate'); x_g=imfilter(x, gaussian_h,'replicate'); y_g=imfilter(y, gaussian_h,'replicate'); z_g=imfilter(z, gaussian_h,'replicate'); x = check_edges(x, x_g); y = check_edges(y, y_g); z = check_edges(z, z_g); case 'gaussian5' img=imfilter(img, gaussian_h_5,'replicate'); x=imfilter(x, gaussian_h_5,'replicate'); y=imfilter(y, gaussian_h_5,'replicate'); z=imfilter(z, gaussian_h_5,'replicate'); end %rtime = etime(clock, t_pre); %cputime - t_pre; %delete('d1_0001.bdat'); rtime = toc(t_pre); end function [img]=cut_boarder(img, cut_off) image_size=size(img); h_cut_off_pixel=round(image_size(2)*cut_off/100); v_cut_off_pixel=round(image_size(1)*cut_off/100); img(:,(image_size(2)-h_cut_off_pixel+1):image_size(2))=[]; %right side of Horizontal img(:,1:h_cut_off_pixel)=[]; %left side of Horizontal img((image_size(1)-v_cut_off_pixel+1):image_size(1),:)=[]; %up side of vertical img(1:v_cut_off_pixel,:)=[]; %bottom side of vertical end function [data] = check_edges(data, data_g) %edges = 0; for i = 2:size(data,1)-1 for j= 2:size(data,2)-1 %if var(data(i-1:i+1,j-1:j+1)) <= 0.001 unit_vector = [data(i-1,j-1:j+1) data(i, j-1:j+1) data(i+1, j-1:j+1)]; %if std(unit_vector)/(max(unit_vector) - min(unit_vector)) <= 0.4 if std(unit_vector) <= 0.1 data(i,j) = data_g(i,j); %else % edges = edges + 1; end end end %edges end
github
rising-turtle/slam_matlab-master
confidence_filter.m
.m
slam_matlab-master/ground_truth_zh/Localization/confidence_filter.m
633
utf_8
736f36b137dc30db3995599cb4ed1cb3
% Eliminate the points by confidence map function [updated_match] = confidence_filter(match, pset1_index, pset2_index, c1, c2) % confidence_threshold = 3; confidence_threshold_percentage = 0.4; confidence_threshold_1 = floor((max(max(c1)) - min(min(c1))) * confidence_threshold_percentage); confidence_threshold_2 = floor((max(max(c2)) - min(min(c2))) * confidence_threshold_percentage); i = 1; for m=1:size(match,2) if c1(pset1_index(1,m), pset1_index(2,m)) > confidence_threshold_1 && c2(pset2_index(1,m), pset2_index(2,m)) > confidence_threshold_2 updated_match(:,i) = match(:,m); i = i + 1; end end end
github
rising-turtle/slam_matlab-master
vro_icp_9_cov_tol.m
.m
slam_matlab-master/ground_truth_zh/Localization/vro_icp_9_cov_tol.m
10,748
utf_8
47385bb52bb3f1b4eda923d9ea20d7d9
% This function compute the transformation of two 3D point clouds by ICP % % Parameters : % % Author : Soonhac Hong ([email protected]) % Date : 9/20/12 % ICP6 + convexhull = ICP9 % ICP9_cov + tolerance adjustment = ICP9_cov_tol function [phi_icp, theta_icp, psi_icp, trans_icp, match_rmse, match_num, elapsed_time, sta_icp, error, pose_std] = vro_icp_9_cov(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2) error = 0; sta_icp = 1; t_icp = tic; % test for local minimum in optimization %trans = [0; 0; 0]; %rot = euler_to_rot(0, 27, 0); if size(op_pset1,2) < 5 fprintf('Error in less point for convex hull.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % compute 3D convex hull t_convex = tic; convexhull_1 = convhulln(op_pset1',{'Qt','Pp'}); convexhull_2 = convhulln(op_pset2',{'Qt','Pp'}); % %show convexhull convexhull_1_x =[]; convexhull_1_y =[]; convexhull_1_z =[]; for i=1:size(convexhull_1,1) for j=1:3 convexhull_1_x = [convexhull_1_x op_pset1(1,convexhull_1(i,j))]; convexhull_1_y = [convexhull_1_y op_pset1(2,convexhull_1(i,j))]; convexhull_1_z = [convexhull_1_z op_pset1(3,convexhull_1(i,j))]; end end % plot3(convexhull_1_x, convexhull_1_y, convexhull_1_z,'d-'); % grid; % axis equal; %draw_data = [convexhull_1_x' convexhull_1_y' convexhull_1_z']; %mesh(draw_data); %M = op_pset1; %D = op_pset2; M_k = 1; D_k = 1; M=[]; D=[]; convex_check = 1; % check convex hull convexhull_tolerance = 0.1; %[m] max_confidence_1 = max(c1(:)); max_confidence_2 = max(c2(:)); threshold = 0.5; confidence_thresh_1 = threshold * max_confidence_1; confidence_thresh_2 = threshold * max_confidence_2; %Initialize data by trans subsampling_factor = 2; h_border_cutoff = round(size(x1,2)*0.1/2); v_border_cutoff = round(size(x1,1)*0.1/2); for i=1+v_border_cutoff:subsampling_factor:size(x1,1)-v_border_cutoff for j=1+h_border_cutoff:subsampling_factor:size(x1,2)-h_border_cutoff M_test = [-x1(i,j) z1(i,j) y1(i,j)]; M_in_flag = inhull(M_test,op_pset1',convexhull_1,convexhull_tolerance); D_test = [-x2(i,j) z2(i,j) y2(i,j)]; D_in_flag = inhull(D_test,op_pset2',convexhull_2,convexhull_tolerance); if M_in_flag == 1 || convex_check == 0 % test point locates in the convex hull %if img1(i,j) >= 50 % intensity filtering for less noise if c1(i,j) >= confidence_thresh_1 % confidence filtering M(:,M_k) = M_test'; %[-x1(i,j); z1(i,j); y1(i,j)]; M_k = M_k + 1; end end if D_in_flag == 1 || convex_check == 0 %if img2(i,j) >= 50 % intensity filtering for less noise if c2(i,j) >= confidence_thresh_2 % confidence filtering D(:,D_k) = D_test'; %[-x2(i,j); z2(i,j); y2(i,j)]; D_k = D_k + 1; end end %temp_pt2 = [-x2(i,j); z2(i,j); y2(i,j)]; %D(:,k) = rot*temp_pt2 + trans; %transed_pt1 = rot*temp_pt + trans; %k = k + 1; end end elapsed_convex = toc(t_convex); ap_size=size(M,2); if isempty(M) || isempty(D) fprintf('Error in less point for ICP.\n'); error=6; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num = [0; 0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %t_icp = tic; %[Ricp, Ticp, ER, t]=icp(M, D,'Minimize','plane'); %elapsed_icp = toc(t_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); %Transform data-matrix using ICP result %Dicp = Ricp * D + repmat(Ticp, 1, n); t_icp_icp = tic; converged = 0; rmse_total=[]; rot_total=[]; trans_total=[]; match_num_total=[]; while_cnt = 1; while converged == 0 % find correspondent assoicate Dicp = rot * D + repmat(trans, 1, size(D,2)); %p = rand( 20, 2 ); % input data (m x n); n dimensionality %q = rand( 10, 2 ); % query data (d x n) t_kdtree = tic; pt1=[]; pt2=[]; if size(M,2) > size (D,2) tree = kdtree_build( M' ); correspondent_idxs = kdtree_nearest_neighbor(tree, Dicp'); pt2 = D; for i=1:size(correspondent_idxs,1) pt1(:,i) = M(:,correspondent_idxs(i)); end else tree = kdtree_build( Dicp' ); correspondent_idxs = kdtree_nearest_neighbor(tree, M'); pt1 = M; for i=1:size(correspondent_idxs,1) pt2(:,i) = D(:,correspondent_idxs(i)); end end elapsed_kdtree = toc(t_kdtree); %[R_icp, trans_icp, ER, t]=icp(pt1, pt2,'Minimize','plane','WorstRejection',0.1); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(R_icp); % Outlier removal % Compute error t_icp_ransac = tic; pt2_transed= rot * pt2 + repmat(trans, 1, size(pt2,2)); new_cnt = 1; pt1_new=[]; pt2_new=[]; correspondent_idxs_new=[]; for i=1:size(pt1,2) unit_rmse = sqrt(sum((pt2_transed(:,i) - pt1(:,i)).^2)); if unit_rmse < 0.03 pt1_new(:,new_cnt) = pt1(:,i); pt2_new(:,new_cnt) = pt2(:,i); correspondent_idxs_new(new_cnt) = correspondent_idxs(i); new_cnt = new_cnt + 1; end end pt1 = pt1_new; pt2 = pt2_new; correspondent_idxs = correspondent_idxs_new'; % Delete duplicates in correspondent points % correspondent_unique = unique(correspondent_idxs); % correspondent_unique_idx = ones(size(correspondent_idxs)); % for i=1:length(correspondent_unique) % unit_idx = find(correspondent_idxs == correspondent_unique(i)); % if length(unit_idx) > 1 % correspondent_unique_idx(unit_idx)=0; % end % end % % correspondent_delete_idx=find(correspondent_unique_idx == 0); % pt1(:,correspondent_delete_idx') = []; % pt2(:,correspondent_delete_idx') = []; % correspondent_idxs(correspondent_delete_idx,:) = []; if isempty(pt1) || isempty(pt2) fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; match_num=[ap_size;0]; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % op_pset1_icp = pt1_new; % op_pset2_icp = pt2_new; % elapsed_icp_ransac = toc(t_icp_ransac); %t_icp_ransac = tic; [op_match, match_num, rtime, error_ransac] = run_ransac_points(pt1, pt2, correspondent_idxs', 0); if error_ransac ~= 0 % Error in RANSAC fprintf('Error in RANSAC with additional points.\n'); error=5; phi_icp = 0.0; theta_icp = 0.0; psi_icp = 0.0; trans_icp = [0.0; 0.0; 0.0]; elapsed_time = [0.0, 0.0, 0.0, 0.0, 0.0]; sta_icp = 0; match_rmse = 0.0; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end op_pset1_icp = []; op_pset2_icp = []; for i=1:match_num(2) op_pset1_icp(:,i) = pt1(:,op_match(1,i)); op_pset2_icp(:,i) = pt2(:,op_match(2,i)); end elapsed_icp_ransac = toc(t_icp_ransac); % SVD t_svd_icp = tic; %[rot_icp, trans_icp, sta_icp] = find_transform_matrix(op_pset1_icp, op_pset2_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); %elapsed_svd = etime(clock, t_svd); sta_icp =1; t_init = zeros(6,1); [t_init(2), t_init(1), t_init(3)] = rot_to_euler(rot); t_init(4:6) = trans; [rot_icp, trans_icp] = lm_point(op_pset1_icp, op_pset2_icp, t_init); %[rot_icp, trans_icp] = lm_point2plane(op_pset1, op_pset2, t_init); elapsed_svd = toc(t_svd_icp); % M = op_pset1_icp; % D = op_pset2_icp; rot = rot_icp; trans = trans_icp; rot_total(:,:,while_cnt) = rot; trans_total(:,:,while_cnt) = trans; match_num_total(while_cnt) = size(op_pset1_icp,2); % Plot % figure; % plot3(op_pset1_icp(1,:),op_pset1_icp(2,:),op_pset1_icp(3,:),'b*-'); % hold on; % plot3(op_pset2_icp(1,:),op_pset2_icp(2,:),op_pset2_icp(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; % Compute error op_pset1_icp_normal = lsqnormest(op_pset1_icp,4); op_pset2_icp_transed= rot * op_pset2_icp + repmat(trans, 1, size(op_pset2_icp,2)); % rmse_icp = 0; % for i=1:size(M,2) % unit_rmse = sqrt(sum((D_transed(:,i) - M(:,i)).^2)/3); % rmse_icp = rmse_icp + unit_rmse; % end % rmse_icp = rmse_icp / size(M,2); %rmse_icp = rms_error(op_pset1_icp, op_pset2_icp_transed); rmse_icp = rms_error_normal(op_pset1_icp, op_pset2_icp_transed, op_pset1_icp_normal); % point-to-plain op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse_feature = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse_feature = rmse_feature + unit_rmse; % end % rmse_feature = rmse_feature / size(op_pset1,2); rmse_feature= rms_error(op_pset1,op_pset2_transed); rmse_total = [rmse_total (rmse_icp+rmse_feature)/2]; %rmse_total = [rmse_total rmse_icp]; rmse_thresh = 0.001; if length(rmse_total) > 3 rmse_diff = abs(diff(rmse_total)); rmse_diff_length = length(rmse_diff); if rmse_diff(rmse_diff_length) < rmse_thresh && rmse_diff(rmse_diff_length-1) < rmse_thresh && rmse_diff(rmse_diff_length-2) < rmse_thresh converged = 1; end end while_cnt = while_cnt + 1; end [match_rmse match_rmse_idx] = min(rmse_total); %match_rmse = rmse_total(end); %match_rmse_idx = size(rmse_total,2); match_num = [ap_size; match_num_total(match_rmse_idx)]; rot_icp = rot_total(:,:,match_rmse_idx); trans_icp = trans_total(:,:,match_rmse_idx); [phi_icp, theta_icp, psi_icp] = rot_to_euler(rot_icp); elapsed_icp_icp = toc(t_icp_icp); %t_icp_icp = tic; %[Ricp, trans_icp, ER, t]=icp(op_pset1_icp, op_pset2_icp,'Minimize','plane'); %elapsed_icp_icp = toc(t_icp_icp); %[phi_icp, theta_icp, psi_icp] = rot_to_euler(Ricp); elapsed_icp = toc(t_icp); elapsed_time = [elapsed_convex, elapsed_kdtree, elapsed_icp_ransac, elapsed_icp_icp, elapsed_icp]; %Compute covariane [pose_std] = compute_pose_std(op_pset1_icp,op_pset2_icp, rot_icp, trans_icp); pose_std = pose_std'; M = []; D = []; pt1 = []; pt2 = []; op_pset1_icp = []; op_pset2_icp = []; tree = []; end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_cov_fast.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_cov_fast.m
14,320
utf_8
4a81d4c1c55144dcff1bb08eb0eb1664
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_cov(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, dis) if nargin < 13 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') % Dynamic data cframe = sframe; else cframe = j; end if check_stored_visual_feature(data_name, dm, cframe) == 0 if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe); end %Read second Data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') % Dynamic data %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end if check_stored_visual_feature(data_name, dm, cframe) == 0 if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe); end %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta == 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
get_data_name_list.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_data_name_list.m
350
utf_8
32051a0a56ef1fde60cf550e437b7861
% Get data name list % % Author : Soonhac Hong ([email protected]) % Date : 12/2/13 function data_name_list=get_data_name_list() data_name_list = {'pitch','pan','roll','x2','y2','c1','c2', 'c3', 'c4','m','etas','loops','kinect_tum','loops2','amir_vro','sparse_feature','swing','swing2','motive','object_recognition','map','it','smart_cane'}; end
github
rising-turtle/slam_matlab-master
concatenate_files.m
.m
slam_matlab-master/ground_truth_zh/Localization/concatenate_files.m
2,428
utf_8
4a5f7b78f540db97fd0f5f804c370bb2
% Concatenate result files % % Author : Soonhac Hong ([email protected]) % Date : 3/4/13 function concatenate_files() %data_name = 'sparse_feature'; data_name = 'object_recognition'; %'sparse_feature'; %'etas'; %'loops2'; dynamic_index = 16; data_type_index = 3; % select data type; See data_type data_type={'','_pose_std','_feature_points'}; base_file_name = textscan('198_frame_abs_intensity_sift_i_r_s_i_t_t_c_i_a_c_c_featureidxfix_fast_fast_dist2_nobpc_gaussian_0','%d%s'); nframe=base_file_name{1,1}; data_type={'','_pose_std','_feature_points'}; %data_dir_list=get_loops2_filename(); data_dir_list = get_dir_name(data_name); %data_dir = sprintf('D:\\soonhac\\Project\\PNBD\\SW\\ASEE\\Localization\\result\\loops2\\%s',data_dir_list{dynamic_index}); data_dir = sprintf('D:\\soonhac\\SW\\Localization\\result\\%s\\%s',data_name,data_dir_list{dynamic_index}); file_name_core = sprintf('%s%s.dat', base_file_name{1,2}{1,1}, data_type{data_type_index}); output_file_name = sprintf('%s\\%d%s_total',data_dir,nframe, file_name_core); dirData = dir(data_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; % Load data according to the file_name_core data={}; data_index = 1; for i=1:size(file_list,1) unit_file_name = textscan(file_list{i,1}, '%d%s'); if strcmp(unit_file_name{1,2}, file_name_core) input_file_name_full = sprintf('%s\\%s',data_dir, file_list{i,1}); data{data_index,1} = load(input_file_name_full); data_first_index(data_index,1) = data{data_index,1}(1,1); data_index = data_index + 1; end end %Write data into a unfied file. [~, data_first_index_sorted_index] = sort(data_first_index); output_fd = fopen(output_file_name,'a'); for i=1:size(data_first_index,1) unit_data = data{data_first_index_sorted_index(i)}; %save(output_file_name,'unit_data', '-ascii', '-append'); switch data_type_index case 1 fprintf(output_fd,'%d %d %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n', unit_data'); case 2 % pose_std fprintf(output_fd,'%d %d %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f %12.8f\n', unit_data'); case 3 % feature_points fprintf(output_fd,'%d %d %d %f %f %f %f %f\n',unit_data'); end end fclose(output_fd); end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc_text.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc_text.m
20,852
utf_8
1da2b2cbb6975181a2ec503bad42c23a
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance % No bad pixel compensation function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc_text(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, sequence_data, is_10M_data, dis) % if nargin < 15 % dis = 0; % end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true cframe = sframe-j; else cframe = j; end first_cframe = cframe; if first_cframe > 0 if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); ld_error=0; %[img1, x1, y1, z1, c1, elapsed_pre, ld_error] = LoadSR_no_bpc_time_single_binary(data_name, filter_name, boarder_cut_off, dm, first_cframe, scale, value_type); end if ld_error < 0 fprintf('No image is loaded !!\n'); error=ld_error; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; match_num = [0; 0; 0]; elapsed = [0; 0; 0; 0; 0; 0; 0; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type,'range'); end % if dis == 1 % f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); % %t_sift = clock; % t_sift = tic; % [frm1, des1] = sift(img1, 'Verbosity', 1); % %elapsed_sift = etime(clock,t_sift); % elapsed_sift = toc(t_sift); % plotsiftframe(frm1); % else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); % end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre, sequence_data, image_name); else t_sift = tic; [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); elapsed_sift = toc(t_sift); elapsed_pre = 0; end if dis==1 && j == 1 figure(1); subplot(2,2,3); imagesc(img1); colormap(gray); axis image; set(gca,'XTick',[]); set(gca,'YTick',[]); title(sprintf('Frame %d', first_cframe)); drawnow; end end %Read second Data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true %cframe = j + sframe; %cframe = sframe+1; %cframe = sframe + j; % Generate constraints cframe = sframe; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); ld_error2=0; %[img2, x2, y2, z2, c2, elapsed_pre2, ld_error2] = LoadSR_no_bpc_time_single_binary(data_name, filter_name, boarder_cut_off, dm, second_cframe, scale, value_type); end if ld_error2 < 0 fprintf('No image is loaded !!\n'); error=ld_error2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; match_num = [0; 0; 0]; elapsed = [0; 0; 0; 0; 0; 0; 0; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type, 'range'); end % if dis == 1 % f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); % %t_sift = clock; % t_sift2 = tic; % [frm2, des2] = sift(img2, 'Verbosity', 1); % %elapsed_sift2 = etime(clock, t_sift); % elapsed_sift2 = toc(t_sift2); % plotsiftframe(frm2); % else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); % end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2, sequence_data, image_name); else t_sift2 = tic; [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); elapsed_sift2 = toc(t_sift2); elapsed_pre2 = 0; end if dis==1 figure(1); subplot(2,2,1); imagesc(img2); colormap(gray); axis image; set(gca,'XTick',[]); set(gca,'YTick',[]); title(sprintf('Frame %d', second_cframe)); drawnow; end if first_cframe <= 0 fprintf('First is loaded !!\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; elapsed = [0; 0; 0; 0; 0; 0; 0; 0]; match_num = [0; 0; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); % if dis == 1 % f3=figure(6); % plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); % end % distance filtering if is_10M_data == 1 valid_dist_max = 8; % 5m else valid_dist_max = 5; % 5m end valid_dist_min = 0.8; % 0.8m match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; temp_pt1=[-x1(ROW1, COL1), z1(ROW1, COL1), y1(ROW1, COL1)]; temp_pt2=[-x2(ROW2, COL2), z2(ROW2, COL2), y2(ROW2, COL2)]; temp_pt1_dist = sqrt(sum(temp_pt1.^2)); temp_pt2_dist = sqrt(sum(temp_pt2.^2)); if temp_pt1_dist >= valid_dist_min && temp_pt1_dist <= valid_dist_max && temp_pt2_dist >= valid_dist_min && temp_pt2_dist <= valid_dist_max %if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 % 39 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 6000; %120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end % if dis == 1 % f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); % f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); % f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); % end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end % if pnum <= 12 % 39 % fprintf('too few matched points for SVD.\n'); % error=1; % phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; % elapsed_ransac = 0.0; % elapsed_svd = 0.0; % match_num = [pnum; 0]; % %rt_total = etime(clock,t); % elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; % feature_points = []; % pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; % return; % end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2, 'none', sequence_data); else t_ransac = tic; [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); elapsed_ransac = toc(t_ransac); elapsed_match = 0; t_svd = tic; end %[op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); %[rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [rot, trans, sta] = find_transform_matrix_e6(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta <= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; % elseif sta == 2 % fprintf('Points are in co-planar.\n'); % error=4; % phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; % elapsed_ransac = 0.0; % elapsed_svd = 0.0; % %elapsed_icp = 0.0; % %match_num = [pnum; gc_num; op_num]; % elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; % feature_points = []; % pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; % return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; %feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; %feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; %feature_points = [feature_points_1; feature_points_2]; feature_points = []; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane if check_stored_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; save_pose_std(data_name, dm, first_cframe, second_cframe, pose_std, 'none', sequence_data); else [pose_std] = load_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); end %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_icp2_cov_fast_fast_dist2.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_icp2_cov_fast_fast_dist2.m
21,044
utf_8
f999be537c4198a4027573b0d293d8e8
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 8/30/12 function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_icp2_cov_fast_fast_dist2(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, icp_mode, dis) if nargin < 14 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') % Dynamic data cframe = sframe; else cframe = j; end first_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); %[frm1,des1] = vl_sift(single(img1)) ; else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe); end %Read second Data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature')% Dynamic data %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); %[frm2,des2] = vl_sift(single(img2)) ; else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe); end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe,'none') == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %[match, scores] = vl_ubcmatch(des1,des2) ; %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 valid_dist_max = 5; % 5m valid_dist_min = 0.8; % 0.8m match_new = []; cnt_new = 1; pnum = size(match, 2); if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; temp_pt1=[-x1(ROW1, COL1), z1(ROW1, COL1), y1(ROW1, COL1)]; temp_pt2=[-x2(ROW2, COL2), z2(ROW2, COL2), y2(ROW2, COL2)]; temp_pt1_dist = sqrt(sum(temp_pt1.^2)); temp_pt2_dist = sqrt(sum(temp_pt2.^2)); if temp_pt1_dist >= valid_dist_min && temp_pt1_dist <= valid_dist_max && temp_pt2_dist >= valid_dist_min && temp_pt2_dist <= valid_dist_max %if img1(ROW1, COL1) >= 0 && img2(ROW2, COL2) >= 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; % stdev_threshold = 0.1; % stdev_count = 0; % count_threshold = 15; % mean_threshold = 0.1; % mean_count = 0; % window_size = 30; % debug_data=[]; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % if cnum >= valid_ransac % break; % end % if cnum/pnum >= inlier_ratio % break; % enddynamic_data_index % total_cnum(i)=cnum; % if i > window_size && inliers_std ~= 0 % inliers_std_prev = inliers_std; % inliers_std = std(total_cnum(i-window_size:i)); %Moving STDEV % inliers_std_delta = abs(inliers_std - inliers_std_prev)/inliers_std_prev; % % inliers_mean_prev = inliers_mean; % inliers_mean = mean(total_cnum(i-window_size:i)); %Moving STDEV % inliers_mean_delta = abs(inliers_mean - inliers_mean_prev)/inliers_mean_prev; % % if inliers_std_delta < stdev_threshold % stdev_count = stdev_count + 1; % else % stdev_count = 0; % end % % if inliers_mean_delta < mean_threshold % mean_count = mean_count + 1; % else % mean_count = 0; % end % % inlier_ratio = max(total_cnum)/pnum; % % count_threshold = 120000 / ((inlier_ratio*100)^2); %-26 * (inlier_ratio*100 - 20) + 800; % % if stdev_count > count_threshold %&& mean_count > count_threshold % break; % end % else % inliers_std = std(total_cnum); % inliers_mean = mean(total_cnum); % end if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1 break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %% Run SVD %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2,'none'); else [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe,'none'); t_svd = tic; end %[op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Test LM %[rot_lm, trans_lm] = lm_point(op_pset1, op_pset2); % [rot_lm, trans_lm] = lm_point2plane(op_pset1, op_pset2); % [phi_lm, theta_lm, psi_lm] = rot_to_euler(rot_lm); % [theta*180/pi theta_lm*180/pi] % [phi*180/pi phi_lm*180/pi] % [psi*180/pi psi_lm*180/pi] % Save feature points %feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; % Compute RMSE op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse = rmse + unit_rmse; % end % rmse_feature = rmse / size(op_pset1,2); %rmse_feature = rms_error(op_pset1, op_pset2_transed); % Show correspondent points % plot3(op_pset1(1,:),op_pset1(2,:),op_pset1(3,:),'b*-'); % hold on; % plot3(op_pset2(1,:),op_pset2(2,:),op_pset2(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; %Compute the elapsed time %rt_total = etime(clock,t); %elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; %% Run ICP %[phi_icp, theta_icp, psi_icp, trans_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_2(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_3(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_4(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_5(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); if strcmp(icp_mode, 'icp_ch') [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol_dist(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch_dist(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); else [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_6_cov(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); end %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_10(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_13(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %Check status of SVD if sta_icp == 0 || error ~= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta_icp == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %elapsed_icp = toc(t_icp); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; %rot = rot_icp; % [rmse_feature rmse_icp] % [theta*180/pi theta_icp*180/pi] % [trans(1) trans_icp(1)] %if rmse_icp <= rmse_feature trans = trans_icp; phi = phi_icp; theta = theta_icp; psi = psi_icp; %end %convert degree % r2d=180.0/pi; % phi=phi*r2d; % theta=theta*r2d; % psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
get_object_recognition_filename.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_object_recognition_filename.m
538
utf_8
fe6f6bb535b834d17035b2783e64b452
% Get directory name of motive datasets % % Author : Soonhac Hong ([email protected]) % Date : 11/20/13 function motive_filename_lists=get_object_recognition_filename() motive_filename_lists = {'floor1','indoor_monitor_1','indoor_doorway_1','indoor_monitor_2','indoor_stairway_1','indoor_stairway_2','indoor_stairway_3','indoor_stairway_4','indoor_stairway_5','indoor_monitor_3','indoor_monitor_4','knob1','knob2','drawer2','drawer3','whiteboard', 'doorknob_creative1','doorknob_creative2', 'drawer_creative1','drawer_creative2'}; end
github
rising-turtle/slam_matlab-master
copy_sr4k_files.m
.m
slam_matlab-master/ground_truth_zh/Localization/copy_sr4k_files.m
1,390
utf_8
4259d34333c45fe053ca49fb12dd77f4
% Copy files to a designated directory % % Author : Soonhac Hong ([email protected]) % Date : 2/15/13 function copy_sr4k_files() source_dir = 'F:\home_sc_data\l2o'; %'E:\data\swing\revisiting10_10m' %; % %''E:/data/sparse_feature/exp4_etas_2nd' %destination_dir = 'C:\SC-DATA-TRANSFER'; destination_dir = sprintf('%s/processed_data',source_dir); mkdir(source_dir,'processed_data'); % destination_dir = sprintf('%s/processed_data_c6',source_dir); % mkdir(source_dir,'processed_data_c6'); %destination_dir = 'E:\data\sparse_feature\exp15_etas_4th_swing_2culling\processed_data'; % Get file names from source directory dirData = dir(source_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; interval = 1; destination_file_idx=748; %1; first_file_number = 757; %1; last_file_number =1400; %size(file_list,1) for i=first_file_number:interval:last_file_number source_file_name = sprintf('%s/%s',source_dir, file_list{i}); %unit_destination_file_name = sprintf('d1_%04d.bdat',destination_file_idx); unit_destination_file_name = sprintf('d1_%04d.dat',destination_file_idx); destination_file_name = sprintf('%s/%s',destination_dir,unit_destination_file_name); copyfile(source_file_name, destination_file_name); destination_file_idx = destination_file_idx + 1; end end
github
rising-turtle/slam_matlab-master
save_icp_pose.m
.m
slam_matlab-master/ground_truth_zh/Localization/save_icp_pose.m
1,449
utf_8
1dbca54b1c887539d2074a5459abc5db
% Save matched points into a file % % Author : Soonhac Hong ([email protected]) % Date : 8/12/2013 function save_icp_pose(data_name, dm, first_cframe, second_cframe, icp_mode, sequence_data, phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true dataset_dir = strrep(prefix, '/d1',''); if strcmp(icp_mode, 'icp_ch') file_name = sprintf('%s/icp_ch_pose/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); else file_name = sprintf('%s/icp_pose/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); end else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); if strcmp(icp_mode, 'icp_ch') file_name = sprintf('%s/icp_ch_pose/d1_%04d_d%d_%04d.mat',dataset_dir, first_cframe, dm, second_cframe); else file_name = sprintf('%s/icp_pose/d1_%04d_d%d_%04d.mat',dataset_dir, first_cframe, dm, second_cframe); end end % if strcmp(isgframe, 'gframe') % file_name = sprintf('%s/matched_points_gframe/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); % else % file_name = sprintf('%s/matched_points/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); % end save(file_name, 'phi_icp', 'theta_icp', 'psi_icp', 'trans_icp', 'rmse_icp', 'match_num', 'elapsed_icp', 'sta_icp', 'error', 'pose_std'); end
github
rising-turtle/slam_matlab-master
LoadSR_no_bpc.m
.m
slam_matlab-master/ground_truth_zh/Localization/LoadSR_no_bpc.m
3,982
utf_8
86bd582604e93f27c5f6f237343ea294
% Load data from Swiss Ranger % % Parameters % data_name : the directory name of data % dm : index of directory of data % j : index of frame % % Author : Soonhac Hong ([email protected]) % Date : 4/20/11 % No bad pixel compensation function [img, x, y, z, c, rtime] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, j, scale, type_value) % if nargin < 6 % scale = 1; % end %apitch=-43+3*dm; %[prefix, err]=sprintf('../data/d%d_%d/d%d', dm, apitch, dm); [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if j<10 [s, err]=sprintf('%s_000%d.dat', prefix, j); elseif j<100 [s, err]=sprintf('%s_00%d.dat', prefix, j); elseif j<1000 [s, err]=sprintf('%s_0%d.dat', prefix, j); else [s, err]=sprintf('%s_%d.dat', prefix, j); end %t_pre = clock; %cputime; t_pre = tic; fw=1; a = load(s); % elapsed time := 0.2 sec k=144*3+1; img = double(a(k:k+143, :)); z = a(1:144, :); x = a(145:288, :); y = a(289:144*3, :); z = medfilt2(z,[fw fw]); x = medfilt2(x, [fw fw]); y = medfilt2(y, [fw fw]); if confidence_read == 1 c = a(144*4+1:144*5, :); % Apply median filter to a pixel which confidence leve is zero. %confidence_cut_off = 1; %[img, x, y, z, c] = compensate_badpixel(img, x, y, z, c, confidence_cut_off); else c = 0; end %Cut-off on the horizontal boarder if boarder_cut_off > 0 img=cut_boarder(img,boarder_cut_off); x=cut_boarder(x,boarder_cut_off); y=cut_boarder(y,boarder_cut_off); z=cut_boarder(z,boarder_cut_off); end %Scale intensity image to [0 255] if scale == 1 img = scale_img(img, fw, type_value, 'intensity'); end % % Adaptive histogram equalization %img = adapthisteq(img); %img = histeq(img); %filtering %filter_list={'none','median','gaussian'}; gaussian_h = fspecial('gaussian',[3 3],1); %sigma = 1 gaussian_h_5 = fspecial('gaussian',[5 5],1); %sigma = 1 switch filter_name case 'median' img=medfilt2(img, [3 3]); x=medfilt2(x, [3 3]); y=medfilt2(y, [3 3]); z=medfilt2(z, [3 3]); case 'median5' img=medfilt2(img, [5 5]); x=medfilt2(x, [5 5]); y=medfilt2(y, [5 5]); z=medfilt2(z, [5 5]); case 'gaussian' img=imfilter(img, gaussian_h,'replicate'); x=imfilter(x, gaussian_h,'replicate'); y=imfilter(y, gaussian_h,'replicate'); z=imfilter(z, gaussian_h,'replicate'); case 'gaussian_edge_std' img=imfilter(img, gaussian_h,'replicate'); x_g=imfilter(x, gaussian_h,'replicate'); y_g=imfilter(y, gaussian_h,'replicate'); z_g=imfilter(z, gaussian_h,'replicate'); x = check_edges(x, x_g); y = check_edges(y, y_g); z = check_edges(z, z_g); case 'gaussian5' img=imfilter(img, gaussian_h_5,'replicate'); x=imfilter(x, gaussian_h_5,'replicate'); y=imfilter(y, gaussian_h_5,'replicate'); z=imfilter(z, gaussian_h_5,'replicate'); end %rtime = etime(clock, t_pre); %cputime - t_pre; rtime = toc(t_pre); end function [img]=cut_boarder(img, cut_off) image_size=size(img); h_cut_off_pixel=round(image_size(2)*cut_off/100); v_cut_off_pixel=round(image_size(1)*cut_off/100); img(:,(image_size(2)-h_cut_off_pixel+1):image_size(2))=[]; %right side of Horizontal img(:,1:h_cut_off_pixel)=[]; %left side of Horizontal img((image_size(1)-v_cut_off_pixel+1):image_size(1),:)=[]; %up side of vertical img(1:v_cut_off_pixel,:)=[]; %bottom side of vertical end function [data] = check_edges(data, data_g) %edges = 0; for i = 2:size(data,1)-1 for j= 2:size(data,2)-1 %if var(data(i-1:i+1,j-1:j+1)) <= 0.001 unit_vector = [data(i-1,j-1:j+1) data(i, j-1:j+1) data(i+1, j-1:j+1)]; %if std(unit_vector)/(max(unit_vector) - min(unit_vector)) <= 0.4 if std(unit_vector) <= 0.1 data(i,j) = data_g(i,j); %else % edges = edges + 1; end end end %edges end
github
rising-turtle/slam_matlab-master
get_motive_filename.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_motive_filename.m
806
utf_8
9f66fc9c9102dc46b086a8818cff3946
% Get directory name of motive datasets % % Author : Soonhac Hong ([email protected]) % Date : 11/20/13 function motive_filename_lists=get_motive_filename() motive_filename_lists = {'move_forward','swing_forward','move_loop','swing_loop','move_loop_2','move_loop_3','swing_loop_2','m5_loop','m5_loop_2','m5_swing_loop','m5_loop_3','m5_swing_loop_2','sf1_m5_10m','sf2_m5_10m','srv1_m5_10m','srv2_m5_10m','sf3_m5','sf4_m5','sf6_m5_10m','sf7_m5_10m','srv3_m5_10m','srv4_m5_10m','m5_1_10m','m5_2_10m','m5_3_10m','m5_4_10m','m5_5_10m','m5_6_10m','m5_7_10m','m5_8_10m','m5_1_c5','m5_1','m5_2','m5_3','m5_4','m5_5','m5_6','st1','st2','sw1','sw2','sw101','sw102','sw201','sw202','sw401','sw402','sw501','sw502','sw051','sw052','sw151','sw152','sw251','sw252','sw153','sw154','sw203','sw204','swf1','swf2'}; end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_cov.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_cov.m
13,451
utf_8
05fdb67deba8117bf940baeee024754b
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_cov(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, dis) if nargin < 13 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') % Dynamic data cframe = sframe; else cframe = j; end if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); %Read second Data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') % Dynamic data %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta == 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
run_ransac_points.m
.m
slam_matlab-master/ground_truth_zh/Localization/run_ransac_points.m
2,268
utf_8
282c75429fdbf0eb0159f9aac971d395
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % pt1 : point cloud of data set (n x m) n : data dimensionality % pt2 : point cloud of data set (n x m) n : data dimensionality % match : match index % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 9/10/12 function [op_match, match_num, rtime, error] = run_ransac_points(pt1, pt2, match, dis) error = 0; pnum = size(match, 2); ransac_error = 0; if pnum<4 fprintf('too few sift points for ransac.\n'); op_num=0; op_match=0; rtime = 0; match_num = [pnum; op_num]; error=1; return; else t_ransac = tic; %Standard termination criterion valid_ransac = 12; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; max_iteration = 120000; while eta > eta_0 i = i+1; [n_match, rs_match, cnum] = ransac_gc(pt1, pt2); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); op_num=0; op_match=0; rtime = toc(t_ransac); match_num = [pnum; op_num]; error=2; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end rtime = toc(t_ransac); match_num = [pnum; op_num]; end end
github
rising-turtle/slam_matlab-master
LoadSR.m
.m
slam_matlab-master/ground_truth_zh/Localization/LoadSR.m
3,943
utf_8
baf1a3a507ef76292082b44303a3d65b
% Load data from Swiss Ranger % % Parameters % data_name : the directory name of data % dm : index of directory of data % j : index of frame % % Author : Soonhac Hong ([email protected]) % Date : 4/20/11 function [img, x, y, z, c, rtime] = LoadSR(data_name, filter_name, boarder_cut_off, dm, j, scale, type_value) % if nargin < 6 % scale = 1; % end %apitch=-43+3*dm; %[prefix, err]=sprintf('../data/d%d_%d/d%d', dm, apitch, dm); [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if j<10 [s, err]=sprintf('%s_000%d.dat', prefix, j); elseif j<100 [s, err]=sprintf('%s_00%d.dat', prefix, j); elseif j<1000 [s, err]=sprintf('%s_0%d.dat', prefix, j); else [s, err]=sprintf('%s_%d.dat', prefix, j); end %t_pre = clock; %cputime; t_pre = tic; fw=1; a = load(s); % elapsed time := 0.2 sec k=144*3+1; img = double(a(k:k+143, :)); z = a(1:144, :); x = a(145:288, :); y = a(289:144*3, :); z = medfilt2(z,[fw fw]); x = medfilt2(x, [fw fw]); y = medfilt2(y, [fw fw]); if confidence_read == 1 c = a(144*4+1:144*5, :); % Apply median filter to a pixel which confidence leve is zero. confidence_cut_off = 1; [img, x, y, z, c] = compensate_badpixel(img, x, y, z, c, confidence_cut_off); else c = 0; end %Cut-off on the horizontal boarder if boarder_cut_off > 0 img=cut_boarder(img,boarder_cut_off); x=cut_boarder(x,boarder_cut_off); y=cut_boarder(y,boarder_cut_off); z=cut_boarder(z,boarder_cut_off); end %Scale intensity image to [0 255] if scale == 1 img = scale_img(img, fw, type_value, 'intensity'); end % % Adaptive histogram equalization %img = adapthisteq(img); img = histeq(img); %filtering %filter_list={'none','median','gaussian'}; gaussian_h = fspecial('gaussian',[3 3],1); %sigma = 1 gaussian_h_5 = fspecial('gaussian',[5 5],1); %sigma = 1 switch filter_name case 'median' img=medfilt2(img, [3 3]); x=medfilt2(x, [3 3]); y=medfilt2(y, [3 3]); z=medfilt2(z, [3 3]); case 'median5' img=medfilt2(img, [5 5]); x=medfilt2(x, [5 5]); y=medfilt2(y, [5 5]); z=medfilt2(z, [5 5]); case 'gaussian' img=imfilter(img, gaussian_h,'replicate'); x=imfilter(x, gaussian_h,'replicate'); y=imfilter(y, gaussian_h,'replicate'); z=imfilter(z, gaussian_h,'replicate'); case 'gaussian_edge_std' img=imfilter(img, gaussian_h,'replicate'); x_g=imfilter(x, gaussian_h,'replicate'); y_g=imfilter(y, gaussian_h,'replicate'); z_g=imfilter(z, gaussian_h,'replicate'); x = check_edges(x, x_g); y = check_edges(y, y_g); z = check_edges(z, z_g); case 'gaussian5' img=imfilter(img, gaussian_h_5,'replicate'); x=imfilter(x, gaussian_h_5,'replicate'); y=imfilter(y, gaussian_h_5,'replicate'); z=imfilter(z, gaussian_h_5,'replicate'); end %rtime = etime(clock, t_pre); %cputime - t_pre; rtime = toc(t_pre); end function [img]=cut_boarder(img, cut_off) image_size=size(img); h_cut_off_pixel=round(image_size(2)*cut_off/100); v_cut_off_pixel=round(image_size(1)*cut_off/100); img(:,(image_size(2)-h_cut_off_pixel+1):image_size(2))=[]; %right side of Horizontal img(:,1:h_cut_off_pixel)=[]; %left side of Horizontal img((image_size(1)-v_cut_off_pixel+1):image_size(1),:)=[]; %up side of vertical img(1:v_cut_off_pixel,:)=[]; %bottom side of vertical end function [data] = check_edges(data, data_g) %edges = 0; for i = 2:size(data,1)-1 for j= 2:size(data,2)-1 %if var(data(i-1:i+1,j-1:j+1)) <= 0.001 unit_vector = [data(i-1,j-1:j+1) data(i, j-1:j+1) data(i+1, j-1:j+1)]; %if std(unit_vector)/(max(unit_vector) - min(unit_vector)) <= 0.4 if std(unit_vector) <= 0.1 data(i,j) = data_g(i,j); %else % edges = edges + 1; end end end %edges end
github
rising-turtle/slam_matlab-master
get_dir_name.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_dir_name.m
2,287
utf_8
ded775277a379e337e56f9430ba2560e
% Get directory name of each data se % % Author : Soonhac Hong ([email protected]) % Date : 4/4/13 function dir_name = get_dir_name(data_name) switch data_name case'py_xy_data_sr4000' dir_name = {'0','y12_x-8_p-5.3_y5'}; case 'c1' dir_name = {'0','y-3_p6_x100','y-12_p9_x300','y-6_p12_x500'}; case 'c2' dir_name = {'0','y-6_p3_y200','y-9_p12_y400','y-12_p6_y600'}; case 'c3' dir_name = {'0','y3_p12_x100','y6_p9_x200','y9_p6_x300','y12_p3_x400'}; case 'c4' dir_name = {'0','y-3_p9_y300'}; case 'm' dir_name={'pitch_3degree','pitch_9degree','pan_3degree','pan_9degree','pan_30degree','pan_60degree','roll_3degree','roll_9degree','x_30mm','x_150mm','x_300mm','y_30mm','y_150mm','y_300mm','square_500','square_700','square_swing','square_1000','test'}; case 'etas' dir_name = {'3th_straight','3th_swing','4th_straight','4th_swing','5th_straight','5th_swing'}; case 'loops' dir_name = {'bus','bus_3','bus_door_straight_150','bus_straight_150','data_square_small_100','eit_data_150','exp1','exp2','exp3','exp4','exp5','lab_80_dynamic_1','lab_80_swing_1','lab_it_80','lab_lookforward_4','s2','second_floor_150_not_square','second_floor_150_square','second_floor_small_80_swing','third_floor_it_150'}; case 'loops2' dir_name = get_loops2_filename(); case 'loops3' dir_name = {'exp1_etas_2nd','exp2_etas_2nd','exp3_biz_1st','exp4_biz_1st','exp5_biz_1st'}; case 'sparse_feature' dir_name = get_sparse_feature_filename(); case {'swing', 'swing2'} dir_name = get_swing_filename(); %{'forward1','forward2','forward3','forward4','forward5','forward6','forward7_10m','forward8_10m', 'forward9_10m','forward10_10m','forward11_10m','forward12_10m','forward13_10m','forward14_10m','forward15_10m','forward16_10m','revisiting1_10m','revisiting2_10m','revisiting3_10m'}; case {'kinect_tum'} dir_name = get_kinect_tum_dir_name(); case {'motive'} dir_name = get_motive_filename(); case {'map'} dir_name = get_map_filename(); case {'it'} dir_name = get_it_filename(); case {'object_recognition'} dir_name = get_object_recognition_filename(); otherwise dir_name = {'none'}; end end
github
rising-turtle/slam_matlab-master
save_pose_std.m
.m
slam_matlab-master/ground_truth_zh/Localization/save_pose_std.m
1,374
utf_8
94abed80c2732098f1ef02641015c5f9
% Save matched points into a file % % Author : Soonhac Hong ([email protected]) % Date : 2/13/2013 function save_pose_std(data_name, dm, first_cframe, second_cframe, pose_std, isgframe, sequence_data) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true if strcmp(data_name, 'object_recognition') dataset_dir = strrep(prefix, '/f1',''); else dataset_dir = strrep(prefix, '/d1',''); end if strcmp(isgframe, 'gframe') file_name = sprintf('%s/pose_std_gframe/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); else file_name = sprintf('%s/pose_std/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); end else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); if strcmp(isgframe, 'gframe') file_name = sprintf('%s/pose_std_gframe/d1_%04d_d%d_%04d.mat',dataset_dir, first_cframe, dm, second_cframe); else file_name = sprintf('%s/pose_std/d1_%04d_d%d_%04d.mat',dataset_dir, first_cframe, dm, second_cframe); end end % if strcmp(isgframe, 'gframe') % file_name = sprintf('%s/matched_points_gframe/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); % else % file_name = sprintf('%s/matched_points/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); % end save(file_name, 'pose_std'); end
github
rising-turtle/slam_matlab-master
check_stored_icp_pose.m
.m
slam_matlab-master/ground_truth_zh/Localization/check_stored_icp_pose.m
1,201
utf_8
7af72ceae02de07502cf86983c93c78b
% Check if there is the stored matched points % % Author : Soonhac Hong ([email protected]) % Date : 8/12/2013 function [exist_flag] = check_stored_icp_pose(data_name, dm, first_cframe, second_cframe, icp_mode, sequence_data) exist_flag = 0; [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true dataset_dir = strrep(prefix, '/d1',''); file_name = sprintf('d1_%04d_%04d.mat',first_cframe, second_cframe); else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); file_name = sprintf('d1_%04d_d%d_%04d.mat',first_cframe, dm, second_cframe); end if strcmp(icp_mode, 'icp_ch') dataset_dir = sprintf('%s/icp_ch_pose',dataset_dir); else dataset_dir = sprintf('%s/icp_pose',dataset_dir); end %file_name = sprintf('d1_%04d_%04d.mat',first_cframe, second_cframe); dirData = dir(dataset_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; if isempty(file_list) return; else for i=1:size(file_list,1) if strcmp(file_list{i}, file_name) exist_flag = 1; break; end end end end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_icp2_cov_fast_fast_dist.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_icp2_cov_fast_fast_dist.m
20,434
utf_8
c03980c62e56add66fadbcc1d0662a38
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 8/30/12 function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_icp2_cov_fast_fast_dist(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, icp_mode, dis) if nargin < 14 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') % Dynamic data cframe = sframe; else cframe = j; end first_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 [img1, x1, y1, z1, c1, elapsed_pre] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); %[frm1,des1] = vl_sift(single(img1)) ; else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe); end %Read second Data set if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature')% Dynamic data %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe) == 0 [img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); %[frm2,des2] = vl_sift(single(img2)) ; else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe); end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe,'none') == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %[match, scores] = vl_ubcmatch(des1,des2) ; %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % Eliminate pairwises which have zero in depth image of kinect or less 100 gray level in image of SR4000 match_new = []; cnt_new = 1; pnum = size(match, 2); if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if img1(ROW1, COL1) >= 0 && img2(ROW2, COL2) >= 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; % stdev_threshold = 0.1; % stdev_count = 0; % count_threshold = 15; % mean_threshold = 0.1; % mean_count = 0; % window_size = 30; % debug_data=[]; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % if cnum >= valid_ransac % break; % end % if cnum/pnum >= inlier_ratio % break; % enddynamic_data_index % total_cnum(i)=cnum; % if i > window_size && inliers_std ~= 0 % inliers_std_prev = inliers_std; % inliers_std = std(total_cnum(i-window_size:i)); %Moving STDEV % inliers_std_delta = abs(inliers_std - inliers_std_prev)/inliers_std_prev; % % inliers_mean_prev = inliers_mean; % inliers_mean = mean(total_cnum(i-window_size:i)); %Moving STDEV % inliers_mean_delta = abs(inliers_mean - inliers_mean_prev)/inliers_mean_prev; % % if inliers_std_delta < stdev_threshold % stdev_count = stdev_count + 1; % else % stdev_count = 0; % end % % if inliers_mean_delta < mean_threshold % mean_count = mean_count + 1; % else % mean_count = 0; % end % % inlier_ratio = max(total_cnum)/pnum; % % count_threshold = 120000 / ((inlier_ratio*100)^2); %-26 * (inlier_ratio*100 - 20) + 800; % % if stdev_count > count_threshold %&& mean_count > count_threshold % break; % end % else % inliers_std = std(total_cnum); % inliers_mean = mean(total_cnum); % end if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1 break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %% Run SVD %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2,'none'); else [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe,'none'); t_svd = tic; end [op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); tmp_rsmatch = []; tmp_cnum = []; tmp_nmatch = []; op_match = []; %Test LM %[rot_lm, trans_lm] = lm_point(op_pset1, op_pset2); % [rot_lm, trans_lm] = lm_point2plane(op_pset1, op_pset2); % [phi_lm, theta_lm, psi_lm] = rot_to_euler(rot_lm); % [theta*180/pi theta_lm*180/pi] % [phi*180/pi phi_lm*180/pi] % [psi*180/pi psi_lm*180/pi] % Save feature points %feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; % Compute RMSE op_pset2_transed= rot * op_pset2 + repmat(trans, 1, size(op_pset2,2)); % rmse = 0; % for i=1:size(op_pset1,2) % unit_rmse = sqrt(sum((op_pset2_transed(:,i) - op_pset1(:,i)).^2)/3); % rmse = rmse + unit_rmse; % end % rmse_feature = rmse / size(op_pset1,2); %rmse_feature = rms_error(op_pset1, op_pset2_transed); % Show correspondent points % plot3(op_pset1(1,:),op_pset1(2,:),op_pset1(3,:),'b*-'); % hold on; % plot3(op_pset2(1,:),op_pset2(2,:),op_pset2(3,:),'ro-'); % xlabel('X'); % ylabel('Y'); % zlabel('Z'); % grid; % hold off; %Compute the elapsed time %rt_total = etime(clock,t); %elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; %% Run ICP %[phi_icp, theta_icp, psi_icp, trans_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_2(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_3(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_4(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_5(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); if strcmp(icp_mode, 'icp_ch') [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch_dist(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol_batch(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_9_cov_tol(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); else [phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error, pose_std] = vro_icp_6_cov(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, c1, x2, y2, z2, img2, c2); end %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_10(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %[phi_icp, theta_icp, psi_icp, trans_icp, rmse_icp, match_num, elapsed_icp, sta_icp, error] = vro_icp_13(op_pset1, op_pset2, rot, trans, x1, y1, z1, img1, x2, y2, z2, img2); %Check status of SVD if sta_icp == 0 || error ~= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta_icp == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end %elapsed_icp = toc(t_icp); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; elapsed_icp(5)]; %rot = rot_icp; % [rmse_feature rmse_icp] % [theta*180/pi theta_icp*180/pi] % [trans(1) trans_icp(1)] %if rmse_icp <= rmse_feature trans = trans_icp; phi = phi_icp; theta = theta_icp; psi = psi_icp; %end %convert degree % r2d=180.0/pi; % phi=phi*r2d; % theta=theta*r2d; % psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc.m
17,831
utf_8
8d2f4aba8fde338deb7f7eacf2abf598
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance % No bad pixel compensation function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, sequence_data, is_10M_data, dis) if nargin < 15 dis = 0; end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true cframe = sframe; else cframe = j; end first_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else %[img1, x1, y1, z1, c1, elapsed_pre] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); [img1, x1, y1, z1, c1, elapsed_pre] = load_or_datasets(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type,'range'); end if dis == 1 f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift = tic; [frm1, des1] = sift(img1, 'Verbosity', 1); %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); plotsiftframe(frm1); else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); end % confidence filtering %[frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre, sequence_data, image_name); else [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); end %Read second Data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true %cframe = j + sframe; %cframe = sframe+1; cframe = sframe + j; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else %[img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); [img2, x2, y2, z2, c2, elapsed_pre2] = load_or_datasets(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type, 'range'); end if dis == 1 f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); %t_sift = clock; t_sift2 = tic; [frm2, des2] = sift(img2, 'Verbosity', 1); %elapsed_sift2 = etime(clock, t_sift); elapsed_sift2 = toc(t_sift2); plotsiftframe(frm2); else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); end % confidence filtering %[frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2, sequence_data, image_name); else [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); if dis == 1 f3=figure(6); plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); end % distance filtering if is_10M_data == 1 valid_dist_max = 8; % 5m else valid_dist_max = 5; % 5m end valid_dist_min = 0.1; %0.8; % 0.8m match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; temp_pt1=[-x1(ROW1, COL1), z1(ROW1, COL1), y1(ROW1, COL1)]; temp_pt2=[-x2(ROW2, COL2), z2(ROW2, COL2), y2(ROW2, COL2)]; temp_pt1_dist = sqrt(sum(temp_pt1.^2)); temp_pt2_dist = sqrt(sum(temp_pt2.^2)); if temp_pt1_dist >= valid_dist_min && temp_pt1_dist <= valid_dist_max && temp_pt2_dist >= valid_dist_min && temp_pt2_dist <= valid_dist_max %if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 % 39 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 12000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end if dis == 1 f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end %save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2, 'none', sequence_data); else [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); t_svd = tic; end %[op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); [rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta <= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; elseif sta == 2 fprintf('Points are in co-planar.\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; feature_points = [feature_points_1; feature_points_2]; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane if check_stored_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; %save_pose_std(data_name, dm, first_cframe, second_cframe, pose_std, 'none', sequence_data); else [pose_std] = load_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); end %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
localization_addpath.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_addpath.m
502
utf_8
fe374d186ac7f5b67dfa33ec164d888a
% Add the path for graph slam % % Author : Soonhac Hong ([email protected]) % Date : 10/16/12 function localization_addpath addpath('D:\Soonhac\SW\icp'); addpath('D:\Soonhac\SW\kdtree'); addpath('D:\Soonhac\SW\LevenbergMarquardt'); addpath('D:\Soonhac\SW\SIFT\sift-0.9.19-bin\sift'); %addpath('D:\Soonhac\SW\SIFT\SIFTGPU2\TestWin\src'); % for siftgpu %addpath('D:\Soonhac\SW\GradientConcensus'); %addpath('D:\Soonhac\SW\OpenSURF_version1c'); %addpath('E:\data\Amir\code\code3\code_from_dr_ye'); end
github
rising-turtle/slam_matlab-master
localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc_binary.m
.m
slam_matlab-master/ground_truth_zh/Localization/localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc_binary.m
20,311
utf_8
67ee44d670077f91dc97c883a2faf22b
% This function computes the pose of the sensor between two data set from % SR400 using SIFT . The orignial function was vot.m in the ASEE/pitch_4_plot1. % % Parameters : % dm : number of prefix of directory containing the first data set. % inc : relative number of prefix of directory containing the second data set. % The number of prefix of data set 2 will be dm+inc. % j : index of frame for data set 1 and data set 2 % dis : index to display logs and images [1 = display][0 = no display] % % Author : Soonhac Hong ([email protected]) % Date : 3/10/11 % localization_sift_ransac_limit + covariance % No bad pixel compensation function [phi, theta, psi, trans, error, elapsed, match_num, feature_points, pose_std] = localization_sift_ransac_limit_cov_fast_fast_dist2_nobpc_binary(image_name, data_name, filter_name, boarder_cut_off, ransac_iteration_limit, valid_ransac, scale, value_type, dm, inc, j, sframe, sequence_data, is_10M_data, dis) % if nargin < 15 % dis = 0; % end %Initilize parameters error = 0; sift_threshold = 0; %t = clock; %Read first data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true cframe = sframe-j; else cframe = j; end first_cframe = cframe; if first_cframe > 0 if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img1, x1, y1, z1, elapsed_pre] = LoadKinect(dm, cframe); [img1, x1, y1, z1, elapsed_pre, time_stamp1] = LoadKinect_depthbased(dm, cframe); else %[img1, x1, y1, z1, c1, elapsed_pre] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); ld_error=0; [img1, x1, y1, z1, c1, elapsed_pre, ld_error] = LoadSR_no_bpc_time_single_binary(data_name, filter_name, boarder_cut_off, dm, first_cframe, scale, value_type); end if ld_error < 0 fprintf('No image is loaded !!\n'); error=ld_error; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; match_num = [0; 0; 0]; elapsed = [0; 0; 0; 0; 0; 0; 0; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img1 = scale_img(z1, 1, value_type,'range'); end % if dis == 1 % f1 = figure(4); imagesc(img1); colormap(gray); title(['frame ', int2str(j)]); % %t_sift = clock; % t_sift = tic; % [frm1, des1] = sift(img1, 'Verbosity', 1); % %elapsed_sift = etime(clock,t_sift); % elapsed_sift = toc(t_sift); % plotsiftframe(frm1); % else %t_sift = clock; t_sift = tic; if sift_threshold == 0 [frm1, des1] = sift(img1); else [frm1, des1] = sift(img1, 'threshold', sift_threshold); end %elapsed_sift = etime(clock,t_sift); elapsed_sift = toc(t_sift); % end % confidence filtering [frm1, des1] = confidence_filtering(frm1, des1, c1); save_visual_features(data_name, dm, cframe, frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre, sequence_data, image_name); else t_sift = tic; [frm1, des1, elapsed_sift, img1, x1, y1, z1, c1, elapsed_pre] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); elapsed_sift = toc(t_sift); elapsed_pre = 0; end if dis==1 && j == 1 figure(1); subplot(2,2,3); imagesc(img1); colormap(gray); axis image; set(gca,'XTick',[]); set(gca,'YTick',[]); title(sprintf('Frame %d', first_cframe)); drawnow; end end %Read second Data set %if strcmp(data_name, 'm') || strcmp(data_name, 'etas') || strcmp(data_name, 'loops') || strcmp(data_name, 'kinect_tum') || strcmp(data_name, 'loops2') || strcmp(data_name, 'sparse_feature') || strcmp(data_name, 'swing') % Dynamic data if sequence_data == true %cframe = j + sframe; %cframe = sframe+1; %cframe = sframe + j; % Generate constraints cframe = sframe; % Generate constraints else dm=dm+inc; cframe = j; end second_cframe = cframe; if check_stored_visual_feature(data_name, dm, cframe, sequence_data, image_name) == 0 if strcmp(data_name, 'kinect_tum') %[img2, x2, y2, z2, elapsed_pre2] = LoadKinect(dm, cframe); [img2, x2, y2, z2, elapsed_pre2, time_stamp2] = LoadKinect_depthbased(dm, cframe); else %[img2, x2, y2, z2, c2, elapsed_pre2] = LoadSR_no_bpc(data_name, filter_name, boarder_cut_off, dm, cframe, scale, value_type); ld_error2=0; [img2, x2, y2, z2, c2, elapsed_pre2, ld_error2] = LoadSR_no_bpc_time_single_binary(data_name, filter_name, boarder_cut_off, dm, second_cframe, scale, value_type); end if ld_error2 < 0 fprintf('No image is loaded !!\n'); error=ld_error2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; match_num = [0; 0; 0]; elapsed = [0; 0; 0; 0; 0; 0; 0; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end if strcmp(image_name, 'depth') %image_name == 'depth' %Assign depth image to img1 img2 = scale_img(z2, 1, value_type, 'range'); end % if dis == 1 % f2=figure(5); imagesc(img2); colormap(gray); title(['frame ', int2str(j)]); % %t_sift = clock; % t_sift2 = tic; % [frm2, des2] = sift(img2, 'Verbosity', 1); % %elapsed_sift2 = etime(clock, t_sift); % elapsed_sift2 = toc(t_sift2); % plotsiftframe(frm2); % else %t_sift = clock; t_sift2 = tic; if sift_threshold == 0 [frm2, des2] = sift(img2); else [frm2, des2] = sift(img2,'threshold', sift_threshold); end %elapsed_sift2 = etime(clock,t_sift); elapsed_sift2 = toc(t_sift2); % end % confidence filtering [frm2, des2] = confidence_filtering(frm2, des2, c2); save_visual_features(data_name, dm, cframe, frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2, sequence_data, image_name); else t_sift2 = tic; [frm2, des2, elapsed_sift2, img2, x2, y2, z2, c2, elapsed_pre2] = load_visual_features(data_name, dm, cframe, sequence_data, image_name); elapsed_sift2 = toc(t_sift2); elapsed_pre2 = 0; end if dis==1 figure(1); subplot(2,2,1); imagesc(img2); colormap(gray); axis image; set(gca,'XTick',[]); set(gca,'YTick',[]); title(sprintf('Frame %d', second_cframe)); drawnow; end if first_cframe <= 0 fprintf('First is loaded !!\n'); error=4; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; elapsed = [0; 0; 0; 0; 0; 0; 0; 0]; match_num = [0; 0; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end if check_stored_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 %t_match = clock; t_match = tic; match = siftmatch(des1, des2); %elapsed_match = etime(clock,t_match); elapsed_match = toc(t_match); % if dis == 1 % f3=figure(6); % plotmatches(img1,img2,frm1,frm2,match); title('Match of SIFT'); % end % distance filtering if is_10M_data == 1 valid_dist_max = 8; % 5m else valid_dist_max = 5; % 5m end valid_dist_min = 0.8; % 0.8m match_new = []; cnt_new = 1; pnum = size(match, 2); intensity_threshold = 0; if strcmp(data_name, 'kinect_tum') for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; if z1(ROW1, COL1) > 0 && z2(ROW2, COL2) > 0 match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end else for i=1:pnum frm1_index=match(1, i); frm2_index=match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; temp_pt1=[-x1(ROW1, COL1), z1(ROW1, COL1), y1(ROW1, COL1)]; temp_pt2=[-x2(ROW2, COL2), z2(ROW2, COL2), y2(ROW2, COL2)]; temp_pt1_dist = sqrt(sum(temp_pt1.^2)); temp_pt2_dist = sqrt(sum(temp_pt2.^2)); if temp_pt1_dist >= valid_dist_min && temp_pt1_dist <= valid_dist_max && temp_pt2_dist >= valid_dist_min && temp_pt2_dist <= valid_dist_max %if img1(ROW1, COL1) >= intensity_threshold && img2(ROW2, COL2) >= intensity_threshold match_new(:,cnt_new) = match(:,i); cnt_new = cnt_new + 1; end end end match = match_new; %find the matched two point sets. %match = [4 6 21 18; 3 7 19 21]; pnum = size(match, 2); if pnum <= 12 % 39 fprintf('too few sift points for ransac.\n'); error=1; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; 0]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; 0]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; else %t_ransac = clock; %cputime; t_ransac = tic; %Eliminate outliers by geometric constraints % for i=1:pnum % frm1_index=match(1, i); frm2_index=match(2, i); % matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1)); ROW1=round(matched_pix1(2)); % matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1)); ROW2=round(matched_pix2(2)); % pset1(1,i)=-x1(ROW1, COL1); pset1(2,i)=z1(ROW1, COL1); pset1(3,i)=y1(ROW1, COL1); % pset2(1,i)=-x2(ROW2, COL2); pset2(2,i)=z2(ROW2, COL2); pset2(3,i)=y2(ROW2, COL2); % pset1_index(1,i) = ROW1; % pset1_index(2,i) = COL1; % pset2_index(1,i) = ROW2; % pset2_index(2,i) = COL2; % end % % [match] = gc_distance(match, pset1,pset2); % % Eliminate outlier by confidence map % [match] = confidence_filter(match, pset1_index, pset2_index, c1, c2); if ransac_iteration_limit ~= 0 % Fixed Iteration limit % rst = min(700, nchoosek(pnum, 4)); rst = min(ransac_iteration_limit, nchoosek(pnum, 4)); % rst = nchoosek(pnum, 4); % valid_ransac = 3; % stdev_threshold = 0.5; % stdev_threshold_min_iteration = 30; tmp_nmatch=zeros(2, pnum, rst); for i=1:rst [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; % total_cnum(i)=cnum; % inliers_std = std(total_cnum); % if i > stdev_threshold_min_iteration && inliers_std < stdev_threshold % break; % end end else %Standard termination criterion inlier_ratio = 0.15; % 14 percent % valid_ransac = 3; %inlier_ratio * pnum; i=0; eta_0 = 0.01; % 99 percent confidence cur_p = 4 / pnum; eta = (1-cur_p^4)^i; ransac_error = 0; max_iteration = 120000; while eta > eta_0 % t_ransac_internal = clock; %cputime; i = i+1; [n_match, rs_match, cnum] = ransac(frm1, frm2, match, x1, y1, z1, x2, y2, z2, data_name); % [n_match, rs_match, cnum] = ransac_3point(frm1, frm2, match, x1, y1, z1, x2, y2, z2); %ct_internal = cputime - t_ransac_internal; % ct_internal = etime(clock, t_ransac_internal); for k=1:cnum tmp_nmatch(:,k,i) = n_match(:,k); end tmp_rsmatch(:, :, i) = rs_match; tmp_cnum(i) = cnum; if cnum ~= 0 cur_p = cnum/pnum; eta = (1-cur_p^4)^i; end if i > max_iteration ransac_error = 1; break; end % debug_data(i,:)=[cnum, cur_p, eta, ct_internal]; end ransac_iteration = i; end [rs_max, rs_ind] = max(tmp_cnum); op_num = tmp_cnum(rs_ind); if(op_num<valid_ransac || ransac_error == 1) fprintf('no consensus found, ransac fails.\n'); error=2; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; match_num = [pnum; op_num]; %rt_total = etime(clock,t); elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; end for k=1:op_num op_match(:, k) = tmp_nmatch(:, k, rs_ind); end % if dis == 1 % f4=figure(7); plotmatches(img1,img2,frm1,frm2,tmp_rsmatch(:,:,rs_ind)); title('Feature points for RANSAC'); % f5=figure(8); plotmatches(img1,img2,frm1,frm2,op_match); title('Match after RANSAC'); % f6=figure(9); plotmatches_multi(img1,img2,frm1,frm2,op_match,match); title('Match after SIFT'); % end %elapsed_ransac = etime(clock, t_ransac); %cputime - t_ransac; elapsed_ransac = toc(t_ransac); match_num = [pnum; op_num]; end %t_svd = clock; t_svd = tic; op_pset_cnt = 1; for i=1:op_num frm1_index=op_match(1, i); frm2_index=op_match(2, i); matched_pix1=frm1(:, frm1_index); COL1=round(matched_pix1(1))+1; ROW1=round(matched_pix1(2))+1; matched_pix2=frm2(:, frm2_index); COL2=round(matched_pix2(1))+1; ROW2=round(matched_pix2(2))+1; op_pset1_image_index(i,:) = [matched_pix1(1), matched_pix1(2)]; %[COL1, ROW1]; op_pset2_image_index(i,:) = [matched_pix2(1), matched_pix2(2)]; %[COL2, ROW2]; if strcmp(data_name, 'kinect_tum') %op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=-y1(ROW1, COL1); %op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=-y2(ROW2, COL2); op_pset1(1,op_pset_cnt)=x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=y1(ROW1, COL1); op_pset1(3,op_pset_cnt)=z1(ROW1, COL1); op_pset2(1,op_pset_cnt)=x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=y2(ROW2, COL2); op_pset2(3,op_pset_cnt)=z2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; else %if img1(ROW1, COL1) >= 100 && img2(ROW2, COL2) >= 100 op_pset1(1,op_pset_cnt)=-x1(ROW1, COL1); op_pset1(2,op_pset_cnt)=z1(ROW1, COL1); op_pset1(3,op_pset_cnt)=y1(ROW1, COL1); op_pset2(1,op_pset_cnt)=-x2(ROW2, COL2); op_pset2(2,op_pset_cnt)=z2(ROW2, COL2); op_pset2(3,op_pset_cnt)=y2(ROW2, COL2); op_pset_cnt = op_pset_cnt + 1; %end end % op_pset1(1,i)=x1(ROW1, COL1); op_pset1(2,i)=y1(ROW1, COL1); op_pset1(3,i)=z1(ROW1, COL1); % op_pset2(1,i)=x2(ROW2, COL2); op_pset2(2,i)=y2(ROW2, COL2); op_pset2(3,i)=z2(ROW2, COL2); end save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2, 'none', sequence_data); else t_ransac = tic; [match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2] = load_matched_points(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); elapsed_ransac = toc(t_ransac); elapsed_match = 0; t_svd = tic; end %[op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index); %[rot, trans, sta] = find_transform_matrix(op_pset1, op_pset2); [rot, trans, sta] = find_transform_matrix_e6(op_pset1, op_pset2); [phi, theta, psi] = rot_to_euler(rot); %elapsed_svd = etime(clock, t_svd); elapsed_svd = toc(t_svd); %Check status of SVD if sta <= 0 % No Solution fprintf('no solution in SVD.\n'); error=3; phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; elapsed_ransac = 0.0; elapsed_svd = 0.0; %elapsed_icp = 0.0; %match_num = [pnum; gc_num; op_num]; elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; feature_points = []; pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; return; % elseif sta == 2 % fprintf('Points are in co-planar.\n'); % error=4; % phi=0.0; theta=0.0; psi=0.0; trans=[0.0; 0.0; 0.0]; % elapsed_ransac = 0.0; % elapsed_svd = 0.0; % %elapsed_icp = 0.0; % %match_num = [pnum; gc_num; op_num]; % elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; % feature_points = []; % pose_std = [0.0; 0.0; 0.0; 0.0; 0.0; 0.0]; % return; end % Save feature points %feature_points_1 =[repmat(1,[op_num 1]) op_pset1']; %feature_points_2 =[repmat(2,[op_num 1]) op_pset2']; %feature_points_1 =[repmat(1,[op_pset_cnt-1 1]) op_pset1' op_pset1_image_index]; %feature_points_2 =[repmat(2,[op_pset_cnt-1 1]) op_pset2' op_pset2_image_index]; %feature_points = [feature_points_1; feature_points_2]; feature_points = []; %Compute the elapsed time %rt_total = etime(clock,t); if strcmp(data_name, 'kinect_tum') elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; time_stamp1; ransac_iteration]; else elapsed = [elapsed_pre; elapsed_sift; elapsed_pre2; elapsed_sift2; elapsed_match; elapsed_ransac; elapsed_svd; ransac_iteration]; end %Compute covariane if check_stored_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data) == 0 [pose_std] = compute_pose_std(op_pset1,op_pset2, rot, trans); pose_std = pose_std'; save_pose_std(data_name, dm, first_cframe, second_cframe, pose_std, 'none', sequence_data); else [pose_std] = load_pose_std(data_name, dm, first_cframe, second_cframe, 'none', sequence_data); end %convert degree %r2d=180.0/pi; %phi=phi*r2d; %theta=theta*r2d; %psi=psi*r2d; %trans'; end
github
rising-turtle/slam_matlab-master
save_matched_points.m
.m
slam_matlab-master/ground_truth_zh/Localization/save_matched_points.m
1,099
utf_8
a1d872acde1b9be2e749a1768097b780
% Save matched points into a file % % Author : Soonhac Hong ([email protected]) % Date : 2/13/2013 function save_matched_points(data_name, dm, first_cframe, second_cframe, match_num, ransac_iteration, op_pset1_image_index, op_pset2_image_index, op_pset_cnt, elapsed_match, elapsed_ransac, op_pset1, op_pset2, isgframe, sequence_data) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true if strcmp(data_name, 'object_recognition') dataset_dir = strrep(prefix, '/f1',''); else dataset_dir = strrep(prefix, '/d1',''); end else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); end if strcmp(isgframe, 'gframe') file_name = sprintf('%s/matched_points_gframe/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); else file_name = sprintf('%s/matched_points/d1_%04d_%04d.mat',dataset_dir, first_cframe, second_cframe); end save(file_name, 'match_num', 'ransac_iteration', 'op_pset1_image_index', 'op_pset2_image_index', 'op_pset_cnt', 'elapsed_match', 'elapsed_ransac', 'op_pset1', 'op_pset2'); end
github
rising-turtle/slam_matlab-master
get_kinect_tum_dir_name_vro_cpp.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_kinect_tum_dir_name_vro_cpp.m
355
utf_8
4dd3f8a1ba991e4517e0073c27ad290d
% Get directory name of kinect_tum data set % % Parameters % dm : index of directory of data % % Author : Soonhac Hong ([email protected]) % Date : 9/25/12 function [dir_name_list]=get_kinect_tum_dir_name() dir_name_list={'freiburg1_xyz','freiburg1_floor','freiburg2_large_no_loop','freiburg2_large_with_loop'}; %dir_name=dir_name_list{dir_index}; end
github
rising-turtle/slam_matlab-master
LoadKinect.m
.m
slam_matlab-master/ground_truth_zh/Localization/LoadKinect.m
1,839
utf_8
45cf2fbc839ba26005f6f0a47ddc3e1d
% Load data from Kinect % % Parameters % data_name : the directory name of data % dm : index of directory of data % j : index of frame % % Author : Soonhac Hong ([email protected]) % Date : 4/20/11 function [img, X, Y, Z, rtime] = LoadKinect(dm, j) t_load = tic; dir_name = get_kinect_tum_dir_name(); [rgb_data_dir, err] = sprintf('E:/data/kinect_tum/%s/rgb',dir_name{dm}); dirData = dir(rgb_data_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; [file_name, err]=sprintf('%s/%s',rgb_data_dir,file_list{j}); rgb_img = imread(file_name); img = rgb2gray(rgb_img); %figure;imshow(rgb_img); %figure;imshow(img); %Noise reduction by Gaussian filter gaussian_h = fspecial('gaussian',[3 3],1); img=imfilter(img, gaussian_h,'replicate'); [depth_data_dir, err] = sprintf('E:/data/kinect_tum/%s/depth',dir_name{dm}); dirData = dir(depth_data_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; [file_name, err]=sprintf('%s/%s',depth_data_dir,file_list{j}); depth_img = imread(file_name); %figure;imshow(depth_img); depth_img = double(depth_img); fx = 525.0; %# focal length x fy = 525.0; %# focal length y cx = 319.5; %# optical center x cy = 239.5; %# optical center y ds = 1.0; %# depth scaling factor = 5000.0; %# for the 16-bit PNG files %# OR: factor = 1 %# for the 32-bit float images in the ROS bag files for v=1:size(depth_img,1) %height for u=1:size(depth_img,2) %width z = (depth_img(v,u) / factor) * ds; x = (u - cx) * z / fx; y = (v - cy) * z / fy; X(v,u) = x; Y(v,u) = y; Z(v,u) = z; end end rtime = toc(t_load); %figure;imagesc(X); %figure;imagesc(Y); %figure;imagesc(Z); end
github
rising-turtle/slam_matlab-master
copy_sr4k_files_t2b.m
.m
slam_matlab-master/ground_truth_zh/Localization/copy_sr4k_files_t2b.m
1,774
utf_8
70e0e7831a817f3749fca6eb9ac61020
% Copy files to a designated directory from text to binary % % Author : Soonhac Hong ([email protected]) % Date : 2/15/13 function copy_sr4k_files_t2b() source_dir = 'D:\Soonhac\Data\sr4k\swing\revisiting9'; %'E:\data\Amir\processed_data\exp1_bus_door_straight_150_Copy'; %'E:\data\swing\revisiting2_10m\processed_data'; %'E:\data\swing\revisiting10_10m' %; % %''E:/data/sparse_feature/exp4_etas_2nd' destination_dir = sprintf('%s/binary_data',source_dir); mkdir(source_dir,'binary_data'); %destination_dir = 'E:\data\sparse_feature\exp15_etas_4th_swing_2culling\processed_data'; % Get file names from source directory dirData = dir(source_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; interval = 1; destination_file_idx=1; first_file_number = 1; %1; last_file_number =size(file_list,1) for i=first_file_number:interval:last_file_number source_file_name = sprintf('%s/%s',source_dir, file_list{i}); unit_destination_file_name = sprintf('d1_%04d.bdat',destination_file_idx); destination_file_name = sprintf('%s/%s',destination_dir,unit_destination_file_name); %copyfile(source_file_name, destination_file_name); % Load a text file a = load(source_file_name); % elapsed time := 0.2 sec k=144*3+1; img = double(a(k:k+143, :)); z = a(1:144, :); x = a(145:288, :); y = a(289:144*3, :); c = a(144*4+1:144*5, :); %Save a binary file fid = fopen(destination_file_name,'w+b'); fwrite(fid,z','float'); fwrite(fid,x','float'); fwrite(fid,y','float'); fwrite(fid,img','uint16'); fwrite(fid,c','uint16'); fclose(fid); destination_file_idx = destination_file_idx + 1; end end
github
rising-turtle/slam_matlab-master
get_swing_filename_backup.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_swing_filename_backup.m
602
utf_8
64c7715196e67deccaa8180a055072c3
% Get directory name of motive datasets % % Author : Soonhac Hong ([email protected]) % Date : 11/20/13 function motive_filename_lists=get_swing_filename_backup() motive_filename_lists = {'forward1','forward2','forward3','forward4','forward5','forward6','forward7_10m','forward8_10m', 'forward9_10m','forward10_10m','forward11_10m','forward12_10m','forward13_10m','forward14_10m','forward15_10m','forward16_10m','revisiting1_10m','revisiting2_10m','revisiting3_10m','revisiting4_10m','revisiting5_10m','revisiting6_10m','revisiting7_10m','revisiting8_10m','revisiting9_10m','revisiting10_10m'}; end
github
rising-turtle/slam_matlab-master
plotmatches_multi.m
.m
slam_matlab-master/ground_truth_zh/Localization/plotmatches_multi.m
10,894
utf_8
1abc9136006be4112288feadc80f61fa
function h=plotmatches_multi(I1,I2,P1,P2,matches,matches2,varargin) % PLOTMATCHES Plot keypoint matches % PLOTMATCHES(I1,I2,P1,P2,MATCHES) plots the two images I1 and I2 % and lines connecting the frames (keypoints) P1 and P2 as specified % by MATCHES. % % P1 and P2 specify two sets of frames, one per column. The first % two elements of each column specify the X,Y coordinates of the % corresponding frame. Any other element is ignored. % % MATCHES specifies a set of matches, one per column. The two % elementes of each column are two indexes in the sets P1 and P2 % respectively. % % The images I1 and I2 might be either both grayscale or both color % and must have DOUBLE storage class. If they are color the range % must be normalized in [0,1]. % % The function accepts the following option-value pairs: % % 'Stacking' ['h'] % Stacking of images: horizontal ['h'], vertical ['v'], diagonal % ['h'], overlap ['o'] % % 'Interactive' [0] % If set to 1, starts the interactive session. In this mode the % program lets the user browse the matches by moving the mouse: % Click to select and highlight a match; press any key to end. % If set to a value greater than 1, the feature matches are not % drawn at all (useful for cluttered scenes). % % See also PLOTSIFTDESCRIPTOR(), PLOTSIFTFRAME(), PLOTSS(). % AUTORIGHTS % Copyright (c) 2006 The Regents of the University of California. % All Rights Reserved. % % Created by Andrea Vedaldi % UCLA Vision Lab - Department of Computer Science % % Permission to use, copy, modify, and distribute this software and its % documentation for educational, research and non-profit purposes, % without fee, and without a written agreement is hereby granted, % provided that the above copyright notice, this paragraph and the % following three paragraphs appear in all copies. % % This software program and documentation are copyrighted by The Regents % of the University of California. The software program and % documentation are supplied "as is", without any accompanying services % from The Regents. The Regents does not warrant that the operation of % the program will be uninterrupted or error-free. The end-user % understands that the program was developed for research purposes and % is advised not to rely exclusively on the program for any reason. % % This software embodies a method for which the following patent has % been issued: "Method and apparatus for identifying scale invariant % features in an image and use of same for locating an object in an % image," David G. Lowe, US Patent 6,711,293 (March 23, % 2004). Provisional application filed March 8, 1999. Asignee: The % University of British Columbia. % % IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY % FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, % INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND % ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN % ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF % CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT % LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR % A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" % BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE % MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. % -------------------------------------------------------------------- % Check the arguments % -------------------------------------------------------------------- stack='h' ; interactive=0 ; only_interactive=0 ; for k=1:2:length(varargin) switch lower(varargin{k}) case 'stacking' stack=varargin{k+1} ; case 'interactive' interactive=varargin{k+1}; otherwise error(['[Unknown option ''', varargin{k}, '''.']) ; end end % -------------------------------------------------------------------- % Do the job % -------------------------------------------------------------------- [M1,N1,K1]=size(I1) ; [M2,N2,K2]=size(I2) ; switch stack case 'h' N3=N1+N2 ; M3=max(M1,M2) ; oj=N1 ; oi=0 ; case 'v' M3=M1+M2 ; N3=max(N1,N2) ; oj=0 ; oi=M1 ; case 'd' M3=M1+M2 ; N3=N1+N2 ; oj=N1 ; oi=M1 ; case 'o' M3=max(M1,M2) ; N3=max(N1,N2) ; oj=0; oi=0; otherwise error(['Unkown stacking type '''], stack, ['''.']) ; end % Combine the two images. In most cases just place one image next to % the other. If the stacking is 'o', however, combine the two images % linearly. I=zeros(M3,N3,K1) ; if stack ~= 'o' I(1:M1,1:N1,:) = I1 ; I(oi+(1:M2),oj+(1:N2),:) = I2 ; else I(oi+(1:M2),oj+(1:N2),:) = I2 ; I(1:M1,1:N1,:) = I(1:M1,1:N1,:) + I1 ; I(1:min(M1,M2),1:min(N1,N2),:) = 0.5 * I(1:min(M1,M2),1:min(N1,N2),:) ; end axes('Position', [0 0 1 1]) ; imagesc(I) ; colormap gray ; hold on ; axis image ; axis off ; K = size(matches, 2) ; nans = NaN * ones(1,K) ; x = [ P1(1,matches(1,:)) ; P2(1,matches(2,:))+oj ; nans ] ; y = [ P1(2,matches(1,:)) ; P2(2,matches(2,:))+oi ; nans ] ; % if interactive > 1 we do not drive lines, but just points. if(interactive > 1) h = plot(x(:),y(:),'g.') ; else h = line(x(:)', y(:)') ; end set(h,'Marker','.','Color','g') ; new_matches = []; for k = 1:size(matches2,2) [row, col] = find(matches == matches2(1,k)); if size(row,1) ~= 0 for m = 1: size(row,2) if matches(2, col(1,m)) ~= matches2(2, k) new_matches = [new_matches matches2(:,K)]; end end else new_matches = [new_matches matches2(:,k)]; end end K = size(new_matches, 2) ; nans = NaN * ones(1,K) ; x = [ P1(1,new_matches(1,:)) ; P2(1,new_matches(2,:))+oj ; nans ] ; y = [ P1(2,new_matches(1,:)) ; P2(2,new_matches(2,:))+oi ; nans ] ; % if interactive > 1 we do not drive lines, but just points. if(interactive > 1) h = plot(x(:),y(:),'r.') ; else h = line(x(:)', y(:)') ; end set(h,'Marker','.','Color','r') ; % -------------------------------------------------------------------- % Interactive % -------------------------------------------------------------------- if(~interactive), return ; end sel1 = unique(matches(1,:)) ; sel2 = unique(matches(2,:)) ; K1 = length(sel1) ; %size(P1,2) ; K2 = length(sel2) ; %size(P2,2) ; X = [ P1(1,sel1) P2(1,sel2)+oj ; P1(2,sel1) P2(2,sel2)+oi ; ] ; fig = gcf ; is_hold = ishold ; hold on ; % save the handlers for later to restore dhandler = get(fig,'WindowButtonDownFcn') ; uhandler = get(fig,'WindowButtonUpFcn') ; mhandler = get(fig,'WindowButtonMotionFcn') ; khandler = get(fig,'KeyPressFcn') ; pointer = get(fig,'Pointer') ; set(fig,'KeyPressFcn', @key_handler) ; set(fig,'WindowButtonDownFcn',@click_down_handler) ; set(fig,'WindowButtonUpFcn', @click_up_handler) ; set(fig,'Pointer','crosshair') ; data.exit = 0 ; % signal exit to the interactive mode data.selected = [] ; % currently selected feature data.X = X ; % feature anchors highlighted = [] ; % currently highlighted feature hh = [] ; % hook of the highlight plot guidata(fig,data) ; while ~ data.exit uiwait(fig) ; data = guidata(fig) ; if(any(size(highlighted) ~= size(data.selected)) || ... any(highlighted ~= data.selected) ) highlighted = data.selected ; % delete previous highlight if( ~isempty(hh) ) delete(hh) ; end hh=[] ; % each selected feature uses its own color c=1 ; colors=[1.0 0.0 0.0 ; 0.0 1.0 0.0 ; 0.0 0.0 1.0 ; 1.0 1.0 0.0 ; 0.0 1.0 1.0 ; 1.0 0.0 1.0 ] ; % more than one feature might be seleted at one time... for this=highlighted % find matches if( this <= K1 ) sel=find(matches(1,:)== sel1(this)) ; else sel=find(matches(2,:)== sel2(this-K1)) ; end K=length(sel) ; % plot matches x = [ P1(1,matches(1,sel)) ; P2(1,matches(2,sel))+oj ; nan*ones(1,K) ] ; y = [ P1(2,matches(1,sel)) ; P2(2,matches(2,sel))+oi ; nan*ones(1,K) ] ; hh = [hh line(x(:)', y(:)',... 'Marker','*',... 'Color',colors(c,:),... 'LineWidth',3)]; if( size(P1,1) == 4 ) f1 = unique(P1(:,matches(1,sel))','rows')' ; hp=plotsiftframe(f1); set(hp,'Color',colors(c,:)) ; hh=[hh hp] ; end if( size(P2,1) == 4 ) f2 = unique(P2(:,matches(2,sel))','rows')' ; f2(1,:)=f2(1,:)+oj ; f2(2,:)=f2(2,:)+oi ; hp=plotsiftframe(f2); set(hp,'Color',colors(c,:)) ; hh=[hh hp] ; end c=c+1 ; end drawnow ; end end if( ~isempty(hh) ) delete(hh) ; end if ~is_hold hold off ; end set(fig,'WindowButtonDownFcn', dhandler) ; set(fig,'WindowButtonUpFcn', uhandler) ; set(fig,'WindowButtonMotionFcn',mhandler) ; set(fig,'KeyPressFcn', khandler) ; set(fig,'Pointer', pointer ) ; % ==================================================================== function data=selection_helper(data) % -------------------------------------------------------------------- P = get(gca, 'CurrentPoint') ; P = [P(1,1); P(1,2)] ; d = (data.X(1,:) - P(1)).^2 + (data.X(2,:) - P(2)).^2 ; dmin=min(d) ; idx=find(d==dmin) ; data.selected = idx ; % ==================================================================== function click_down_handler(obj,event) % -------------------------------------------------------------------- % select a feature and change motion handler for dragging [obj,fig]=gcbo ; data = guidata(fig) ; data.mhandler = get(fig,'WindowButtonMotionFcn') ; set(fig,'WindowButtonMotionFcn',@motion_handler) ; data = selection_helper(data) ; guidata(fig,data) ; uiresume(obj) ; % ==================================================================== function click_up_handler(obj,event) % -------------------------------------------------------------------- % stop dragging [obj,fig]=gcbo ; data = guidata(fig) ; set(fig,'WindowButtonMotionFcn',data.mhandler) ; guidata(fig,data) ; uiresume(obj) ; % ==================================================================== function motion_handler(obj,event) % -------------------------------------------------------------------- % select features while dragging data = guidata(obj) ; data = selection_helper(data); guidata(obj,data) ; uiresume(obj) ; % ==================================================================== function key_handler(obj,event) % -------------------------------------------------------------------- % use keypress to exit data = guidata(gcbo) ; data.exit = 1 ; guidata(obj,data) ; uiresume(gcbo) ;
github
rising-turtle/slam_matlab-master
load_depth_features.m
.m
slam_matlab-master/ground_truth_zh/Localization/load_depth_features.m
397
utf_8
73b869902c9029fed3f113649c1e42e6
% Load sift visual feature from a file % % Author : Soonhac Hong ([email protected]) % Date : 2/13/2013 function [depth_frm, depth_des, depth_ct] = load_depth_features(data_name, dm, cframe) [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); dataset_dir = strrep(prefix, '/d1',''); file_name = sprintf('%s/depth_feature/d1_%04d.mat',dataset_dir, cframe); load(file_name); end
github
rising-turtle/slam_matlab-master
check_feature_distance.m
.m
slam_matlab-master/ground_truth_zh/Localization/check_feature_distance.m
1,190
utf_8
17b466611fb0573eb8e7667c8b2663d2
% Check the distance of feaure points % % Author : Soonhac Hong ([email protected]) % Date : 4/5/13 function [op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index] = check_feature_distance(op_pset1, op_pset2, op_pset_cnt, op_pset1_image_index, op_pset2_image_index) distance_min = 0.8; distance_max = 5; op_pset1_distance = sqrt(sum(op_pset1.^2)); op_pset2_distance = sqrt(sum(op_pset2.^2)); op_pset1_distance_flag = (op_pset1_distance < distance_min | op_pset1_distance > distance_max); op_pset2_distance_flag = (op_pset2_distance < distance_min | op_pset2_distance > distance_max); %debug if sum(op_pset1_distance_flag) > 0 || sum(op_pset2_distance_flag) > 0 disp('Distance filter is working'); op_pset_cnt = op_pset_cnt - max(sum(op_pset1_distance_flag),sum(op_pset2_distance_flag)); end op_pset1(:, (op_pset1_distance_flag|op_pset2_distance_flag))=[]; % delete invalid feature points op_pset2(:, (op_pset1_distance_flag|op_pset2_distance_flag))=[]; % delete invalid feature points op_pset1_image_index((op_pset1_distance_flag'|op_pset2_distance_flag'),:) = []; op_pset2_image_index((op_pset1_distance_flag'|op_pset2_distance_flag'),:) = []; end
github
rising-turtle/slam_matlab-master
get_nframe_nvro_npose.m
.m
slam_matlab-master/ground_truth_zh/Localization/get_nframe_nvro_npose.m
9,903
utf_8
9e44a07be619283be5135223a8f4ad04
% Get nFrame, vro_size, pose_size % % Author : Soonhac Hong ([email protected]) % Date : 8/9/13 function [nFrame, vro_size, pose_size, vro_icp_size, pose_vro_icp_size, vro_icp_ch_size, pose_vro_icp_ch_size] = get_nframe_nvro_npose(file_index, dynamic_index) %% nFrame list etas_nFrame_list = [979 1488 988 1979 1889]; %[3rd_straight, 3rd_swing, 4th_straigth, 4th_swing, 5th_straight, 5th_swing] loops_nFrame_list = [0 1359 2498 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2669]; kinect_tum_nFrame_list = [0 98 0 0]; m_nFrame_list = [0 5414 0 729]; sparse_feature_nFrame_list = [232 198 432 365 277 413 0 206 235 0 706 190 275 358 290 578]; swing_nFrame_list = [271 322 600 534 530 334 379 379 379 379 379 299 365 248 245 249 220 245 249 302 399 389 489 446 383 486]; swing2_nFrame_list = [99 128 221 176 210 110]; motive_nFrame_list =[82 145 231 200 227 260 254 236 196 242 182 184 84 0 199 212 81 95 98 99 209 215 96 80 124 112 207 190 115 109 175 214 206 222 177 158 171 158]; object_recognition_nFrame_list =[998 498 498 498 398 398 398 848 848 798 848 35 37 41 14 198 198 198 198 348]; map_nFrame_list =[0 8770 3961 844 1899 1397 302 197 351]; %map_nFrame_list =[0 8770 1320]; %% vro size list %etas_vro_size_list = [1940 0 1665 0 9490 0]; % NMMP < 13 etas_vro_size_list = [2629 0 1665 0 9490 0]; % NMMP < 6 %etas_vro_size_list_vro_icp_ch = [1938 0 1665 0 9490 0]; % NMMP < 13 etas_vro_size_list_vro_icp_ch = [2475 0 1665 0 9490 0]; % NMMP < 6 %etas_pose_size_list = [919 0 1665 0 9490 0]; % NMMP < 13 etas_pose_size_list = [964 0 1665 0 9490 0]; % NMMP < 6 %etas_pose_size_list_vro_icp_ch = [919 0 1665 0 9490 0]; % NMMP < 13 etas_pose_size_list_vro_icp_ch = [954 0 1665 0 9490 0];% NMMP < 6 loops_vro_size_list = [0 13098 12476 0 0 0 0 0 0 0 0 0 0 0 0 0 0 26613]; kinect_tum_vro_size_list = [0 98 0 0]; sparse_feature_vro_size_list_vro = [814 689 1452 1716 851 2104 0 483 0 0 4438 0 0 0 0 4939]; %232 sparse_feature_vro_size_list_vro_icp = [926 0 1783 365 1153 2328 0 674 0 0 4122 0 0 0 0 0]; %926 232 sparse_feature_vro_size_list_vro_icp_ch = [874 762 1616 1889 1153 2308 0 575 0 0 4738 0 0 0 0 5187];% 896 232 2040 sparse_feature_pose_size_list_vro = [232 195 432 364 258 408 0 184 0 0 701 0 0 0 0 576]; sparse_feature_pose_size_list_vro_icp = [232 0 432 365 274 413 0 201 0 0 708 0 0 0 0 0]; sparse_feature_pose_size_list_vro_icp_ch = [232 197 432 365 274 410 0 195 0 0 703 0 0 0 0 578]; %410 swing_vro_size_list_vro = [1525 1230 432 363 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; swing_vro_size_list_vro_icp = [1943 1815 1783 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; %232 swing_vro_size_list_vro_icp_ch = [1790 1437 1650 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; %1494 swing_pose_size_list = [269 321 432 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; swing_pose_size_list_vro_icp = [269 321 432 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; swing_pose_size_list_vro_icp_ch = [269 321 432 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; swing2_vro_size_list_vro = [171 0 0 0]; swing2_vro_size_list_vro_icp = [236 0 0 0]; %232 swing2_vro_size_list_vro_icp_ch = [206 0 0 0]; %1494 swing2_pose_size_list = [99 0 0 0]; loops2_nFrame_list = [830 582 830 832 649 930 479 580 699 458 368 239]; %loops2_nFrame_list = [830 0 832 832 649 932 479 580 699 458 398 239]; %2498 578 loops2_vro_size_list = [9508 7344 8915 7341 9157 5278 2777 9485 6435 4465 3035 673]; %4145 5754 with static5 %loops2_vro_size_list = [10792 9468 11700 7341 9157 5278 2777 9485 6435 4465 3035 673]; %4145 5754 loops2_vro_size_list_vro_icp = [830 0 11293 7427 649 932 479 580 699 458 398 1118]; %4145 5754 loops2_vro_size_list_vro_icp_ch = [10511 8762 11416 7427 10814 6473 3273 10685 7102 4612 3188 783]; % % NMMP < 6 %loops2_vro_size_list_vro_icp_ch = [9506 7329 10525 7427 9123 5275 2757 9481 6417 4463 3032 783]; % NMMP < 13 loops2_pose_size_list = [830 582 830 832 649 928 477 580 699 455 365 227]; loops2_pose_size_list_vro_icp = [830 582 830 832 649 932 479 580 699 458 398 238]; %loops2_pose_size_list_vro_icp_ch = [830 582 830 832 649 928 477 580 698 455 364 234]; % NMMP < 13 loops2_pose_size_list_vro_icp_ch = [830 582 830 832 649 929 479 580 698 458 366 234]; % NMMP < 6 motive_vro_size_list_vro = [1525 1230 432 363 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; motive_vro_size_list_vro_icp = [1943 1815 1783 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; %232 motive_vro_size_list_vro_icp_ch = [1790 1437 1650 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; %1494 motive_pose_size_list = [269 321 432 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; motive_pose_size_list_vro_icp = [269 321 432 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; motive_pose_size_list_vro_icp_ch = [269 321 432 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; object_recognition_vro_size_list_vro = [1525 1230 432 9706 0 0 0 0 0 0 16089 0 0 0 0 0 0 0 0 0]; object_recognition_vro_size_list_vro_icp = [1943 1815 1783 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; %232 object_recognition_vro_size_list_vro_icp_ch = [1790 1437 1650 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; %1494 object_recognition_pose_size_list = [269 321 432 365 0 0 0 0 0 0 848 0 0 0 0 0 0 0 0 0]; object_recognition_pose_size_list_vro_icp = [269 321 432 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; object_recognition_pose_size_list_vro_icp_ch = [269 321 432 365 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]; map_vro_size_list_vro = [0 0 0 0 0 0 0 0 0]; map_vro_size_list_vro_icp = [0 0 0 0 0 0 0 0 0]; %232 map_vro_size_list_vro_icp_ch = [0 0 0 0 0 0 0 0 0]; %1494 map_pose_size_list = [0 0 0 0 0 0 0 0 0]; map_pose_size_list_vro_icp = [0 0 0 0 0 0 0 0 0]; map_pose_size_list_vro_icp_ch = [0 0 0 0 0 0 0 0 0]; switch file_index case 5 nFrame = m_nFrame_list(dynamic_index - 14); vro_size = 6992; %5382; %46; %5365; %5169; case 6 nFrame = etas_nFrame_list(dynamic_index); %289; 5414; %46; %5468; %296; %46; %86; %580; %3920; vro_size = etas_vro_size_list(dynamic_index); %etas_vro_size_list(dynamic_index); %1951; 1942; %5382; %46; %5365; %5169; pose_size = etas_pose_size_list(dynamic_index); vro_icp_size = 0; pose_vro_icp_size = 0; vro_icp_ch_size = etas_vro_size_list_vro_icp_ch(dynamic_index); pose_vro_icp_ch_size =etas_pose_size_list_vro_icp_ch(dynamic_index); case 7 nFrame = loops_nFrame_list(dynamic_index); vro_size = loops_vro_size_list(dynamic_index); case 8 nFrame = kinect_tum_nFrame_list(dynamic_index); vro_size = kinect_tum_vro_size_list(dynamic_index); case 9 nFrame = loops2_nFrame_list(dynamic_index); vro_size = loops2_vro_size_list(dynamic_index); pose_size = loops2_pose_size_list(dynamic_index); vro_icp_size = loops2_vro_size_list_vro_icp(dynamic_index); pose_vro_icp_size = loops2_pose_size_list_vro_icp(dynamic_index); vro_icp_ch_size = loops2_vro_size_list_vro_icp_ch(dynamic_index); pose_vro_icp_ch_size = loops2_pose_size_list_vro_icp_ch(dynamic_index); case 11 nFrame = sparse_feature_nFrame_list(dynamic_index); vro_size = sparse_feature_vro_size_list_vro(dynamic_index); pose_size = sparse_feature_pose_size_list_vro(dynamic_index); vro_icp_size = sparse_feature_vro_size_list_vro_icp(dynamic_index); pose_vro_icp_size = sparse_feature_pose_size_list_vro_icp(dynamic_index); vro_icp_ch_size = sparse_feature_vro_size_list_vro_icp_ch(dynamic_index); pose_vro_icp_ch_size = sparse_feature_pose_size_list_vro_icp_ch(dynamic_index); case 12 nFrame = swing_nFrame_list(dynamic_index); vro_size = swing_vro_size_list_vro(dynamic_index); pose_size = swing_pose_size_list(dynamic_index); vro_icp_size = swing_vro_size_list_vro_icp(dynamic_index); pose_vro_icp_size = swing_pose_size_list_vro_icp(dynamic_index); vro_icp_ch_size = swing_vro_size_list_vro_icp_ch(dynamic_index); pose_vro_icp_ch_size = swing_pose_size_list_vro_icp_ch(dynamic_index); case 13 nFrame = swing2_nFrame_list(dynamic_index); vro_size = swing2_vro_size_list_vro(dynamic_index); pose_size = swing2_pose_size_list(dynamic_index); case 14 nFrame = motive_nFrame_list(dynamic_index); vro_size = motive_vro_size_list_vro(dynamic_index); pose_size = motive_pose_size_list(dynamic_index); vro_icp_size = motive_vro_size_list_vro_icp(dynamic_index); pose_vro_icp_size = motive_pose_size_list_vro_icp(dynamic_index); vro_icp_ch_size = motive_vro_size_list_vro_icp_ch(dynamic_index); pose_vro_icp_ch_size = motive_pose_size_list_vro_icp_ch(dynamic_index); case 15 nFrame = object_recognition_nFrame_list(dynamic_index); vro_size = object_recognition_vro_size_list_vro(dynamic_index); pose_size = object_recognition_pose_size_list(dynamic_index); vro_icp_size = object_recognition_vro_size_list_vro_icp(dynamic_index); pose_vro_icp_size = object_recognition_pose_size_list_vro_icp(dynamic_index); vro_icp_ch_size = object_recognition_vro_size_list_vro_icp_ch(dynamic_index); pose_vro_icp_ch_size = object_recognition_pose_size_list_vro_icp_ch(dynamic_index); case 16 nFrame = map_nFrame_list(dynamic_index); vro_size = map_vro_size_list_vro(dynamic_index); pose_size = map_pose_size_list(dynamic_index); vro_icp_size = map_vro_size_list_vro_icp(dynamic_index); pose_vro_icp_size = map_pose_size_list_vro_icp(dynamic_index); vro_icp_ch_size = map_vro_size_list_vro_icp_ch(dynamic_index); pose_vro_icp_ch_size = map_pose_size_list_vro_icp_ch(dynamic_index); end end
github
rising-turtle/slam_matlab-master
check_stored_pose_std.m
.m
slam_matlab-master/ground_truth_zh/Localization/check_stored_pose_std.m
1,321
utf_8
b4da71858b5b61210cfbb759eee86f78
% Check if there is the stored matched points % % Author : Soonhac Hong ([email protected]) % Date : 3/11/2013 function [exist_flag] = check_stored_pose_std(data_name, dm, first_cframe, second_cframe, isgframe, sequence_data) exist_flag = 0; [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name, dm); if sequence_data == true if strcmp(data_name, 'object_recognition') dataset_dir = strrep(prefix, '/f1',''); else dataset_dir = strrep(prefix, '/d1',''); end file_name = sprintf('d1_%04d_%04d.mat',first_cframe, second_cframe); else dataset_dir = prefix(1:max(strfind(prefix,sprintf('/d%d',dm)))-1); file_name = sprintf('d1_%04d_d%d_%04d.mat',first_cframe, dm, second_cframe); end if strcmp(isgframe, 'gframe') dataset_dir = sprintf('%s/pose_std_gframe',dataset_dir); else dataset_dir = sprintf('%s/pose_std',dataset_dir); end %file_name = sprintf('d1_%04d_%04d.mat',first_cframe, second_cframe); dirData = dir(dataset_dir); %# Get the data for the current directory dirIndex = [dirData.isdir]; %# Find the index for directories file_list = {dirData(~dirIndex).name}'; if isempty(file_list) return; else for i=1:size(file_list,1) if strcmp(file_list{i}, file_name) exist_flag = 1; break; end end end end
github
rising-turtle/slam_matlab-master
vl_compile.m
.m
slam_matlab-master/SIFT/vlfeat-0.9.16/toolbox/vl_compile.m
5,060
utf_8
978f5189bb9b2a16db3368891f79aaa6
function vl_compile(compiler) % VL_COMPILE Compile VLFeat MEX files % VL_COMPILE() uses MEX() to compile VLFeat MEX files. This command % works only under Windows and is used to re-build problematic % binaries. The preferred method of compiling VLFeat on both UNIX % and Windows is through the provided Makefiles. % % VL_COMPILE() only compiles the MEX files and assumes that the % VLFeat DLL (i.e. the file VLFEATROOT/bin/win{32,64}/vl.dll) has % already been built. This file is built by the Makefiles. % % By default VL_COMPILE() assumes that Visual C++ is the active % MATLAB compiler. VL_COMPILE('lcc') assumes that the active % compiler is LCC instead (see MEX -SETUP). Unfortunately LCC does % not seem to be able to compile the latest versions of VLFeat due % to bugs in the support of 64-bit integers. Therefore it is % recommended to use Visual C++ instead. % % See also: VL_NOPREFIX(), VL_HELP(). % Authors: Andrea Vedadli, Jonghyun Choi % Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. % All rights reserved. % % This file is part of the VLFeat library and is made available under % the terms of the BSD license (see the COPYING file). if nargin < 1, compiler = 'visualc' ; end switch lower(compiler) case 'visualc' fprintf('%s: assuming that Visual C++ is the active compiler\n', mfilename) ; useLcc = false ; case 'lcc' fprintf('%s: assuming that LCC is the active compiler\n', mfilename) ; warning('LCC may fail to compile VLFeat. See help vl_compile.') ; useLcc = true ; otherwise error('Unknown compiler ''%s''.', compiler) end vlDir = vl_root ; toolboxDir = fullfile(vlDir, 'toolbox') ; switch computer case 'PCWIN' fprintf('%s: compiling for PCWIN (32 bit)\n', mfilename); mexwDir = fullfile(toolboxDir, 'mex', 'mexw32') ; binwDir = fullfile(vlDir, 'bin', 'win32') ; case 'PCWIN64' fprintf('%s: compiling for PCWIN64 (64 bit)\n', mfilename); mexwDir = fullfile(toolboxDir, 'mex', 'mexw64') ; binwDir = fullfile(vlDir, 'bin', 'win64') ; otherwise error('The architecture is neither PCWIN nor PCWIN64. See help vl_compile.') ; end impLibPath = fullfile(binwDir, 'vl.lib') ; libDir = fullfile(binwDir, 'vl.dll') ; mkd(mexwDir) ; % find the subdirectories of toolbox that we should process subDirs = dir(toolboxDir) ; subDirs = subDirs([subDirs.isdir]) ; discard = regexp({subDirs.name}, '^(.|..|noprefix|mex.*)$', 'start') ; keep = cellfun('isempty', discard) ; subDirs = subDirs(keep) ; subDirs = {subDirs.name} ; % Copy support files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if ~exist(fullfile(binwDir, 'vl.dll')) error('The VLFeat DLL (%s) could not be found. See help vl_compile.', ... fullfile(binwDir, 'vl.dll')) ; end tmp = dir(fullfile(binwDir, '*.dll')) ; supportFileNames = {tmp.name} ; for fi = 1:length(supportFileNames) name = supportFileNames{fi} ; cp(fullfile(binwDir, name), ... fullfile(mexwDir, name) ) ; end % Ensure implib for LCC ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ if useLcc lccImpLibDir = fullfile(mexwDir, 'lcc') ; lccImpLibPath = fullfile(lccImpLibDir, 'VL.lib') ; lccRoot = fullfile(matlabroot, 'sys', 'lcc', 'bin') ; lccImpExePath = fullfile(lccRoot, 'lcc_implib.exe') ; mkd(lccImpLibDir) ; cp(fullfile(binwDir, 'vl.dll'), fullfile(lccImpLibDir, 'vl.dll')) ; cmd = ['"' lccImpExePath '"', ' -u ', '"' fullfile(lccImpLibDir, 'vl.dll') '"'] ; fprintf('Running:\n> %s\n', cmd) ; curPath = pwd ; try cd(lccImpLibDir) ; [d,w] = system(cmd) ; if d, error(w); end cd(curPath) ; catch cd(curPath) ; error(lasterr) ; end end % Compile each mex file ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ for i = 1:length(subDirs) thisDir = fullfile(toolboxDir, subDirs{i}) ; fileNames = ls(fullfile(thisDir, '*.c')); for f = 1:size(fileNames,1) fileName = fileNames(f, :) ; sp = strfind(fileName, ' '); if length(sp) > 0, fileName = fileName(1:sp-1); end filePath = fullfile(thisDir, fileName); fprintf('MEX %s\n', filePath); dot = strfind(fileName, '.'); mexFile = fullfile(mexwDir, [fileName(1:dot) 'dll']); if exist(mexFile) delete(mexFile) end cmd = {['-I' toolboxDir], ... ['-I' vlDir], ... '-O', ... '-outdir', mexwDir, ... filePath } ; if useLcc cmd{end+1} = lccImpLibPath ; else cmd{end+1} = impLibPath ; end mex(cmd{:}) ; end end % -------------------------------------------------------------------- function cp(src,dst) % -------------------------------------------------------------------- if ~exist(dst,'file') fprintf('Copying ''%s'' to ''%s''.\n', src,dst) ; copyfile(src,dst) ; end % -------------------------------------------------------------------- function mkd(dst) % -------------------------------------------------------------------- if ~exist(dst, 'dir') fprintf('Creating directory ''%s''.', dst) ; mkdir(dst) ; end
github
rising-turtle/slam_matlab-master
vl_noprefix.m
.m
slam_matlab-master/SIFT/vlfeat-0.9.16/toolbox/vl_noprefix.m
1,875
utf_8
97d8755f0ba139ac1304bc423d3d86d3
function vl_noprefix % VL_NOPREFIX Create a prefix-less version of VLFeat commands % VL_NOPREFIX() creats prefix-less stubs for VLFeat functions % (e.g. SIFT for VL_SIFT). This function is seldom used as the stubs % are included in the VLFeat binary distribution anyways. Moreover, % on UNIX platforms, the stubs are generally constructed by the % Makefile. % % See also: VL_COMPILE(), VL_HELP(). % Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. % All rights reserved. % % This file is part of the VLFeat library and is made available under % the terms of the BSD license (see the COPYING file). root = fileparts(which(mfilename)) ; list = listMFilesX(root); outDir = fullfile(root, 'noprefix') ; if ~exist(outDir, 'dir') mkdir(outDir) ; end for li = 1:length(list) name = list(li).name(1:end-2) ; % remove .m nname = name(4:end) ; % remove vl_ stubPath = fullfile(outDir, [nname '.m']) ; fout = fopen(stubPath, 'w') ; fprintf('Creating stub %s for %s\n', stubPath, nname) ; fprintf(fout, 'function varargout = %s(varargin)\n', nname) ; fprintf(fout, '%% %s Stub for %s\n', upper(nname), upper(name)) ; fprintf(fout, '[varargout{1:nargout}] = %s(varargin{:})\n', name) ; fclose(fout) ; end end function list = listMFilesX(root) list = struct('name', {}, 'path', {}) ; files = dir(root) ; for fi = 1:length(files) name = files(fi).name ; if files(fi).isdir if any(regexp(name, '^(\.|\.\.|noprefix)$')) continue ; else tmp = listMFilesX(fullfile(root, name)) ; list = [list, tmp] ; end end if any(regexp(name, '^vl_(demo|test).*m$')) continue ; elseif any(regexp(name, '^vl_(demo|setup|compile|help|root|noprefix)\.m$')) continue ; elseif any(regexp(name, '\.m$')) list(end+1) = struct(... 'name', {name}, ... 'path', {fullfile(root, name)}) ; end end end
github
rising-turtle/slam_matlab-master
vl_override.m
.m
slam_matlab-master/SIFT/vlfeat-0.9.16/toolbox/misc/vl_override.m
4,654
utf_8
e233d2ecaeb68f56034a976060c594c5
function config = vl_override(config,update,varargin) % VL_OVERRIDE Override structure subset % CONFIG = VL_OVERRIDE(CONFIG, UPDATE) copies recursively the fileds % of the structure UPDATE to the corresponding fields of the % struture CONFIG. % % Usually CONFIG is interpreted as a list of paramters with their % default values and UPDATE as a list of new paramete values. % % VL_OVERRIDE(..., 'Warn') prints a warning message whenever: (i) % UPDATE has a field not found in CONFIG, or (ii) non-leaf values of % CONFIG are overwritten. % % VL_OVERRIDE(..., 'Skip') skips fields of UPDATE that are not found % in CONFIG instead of copying them. % % VL_OVERRIDE(..., 'CaseI') matches field names in a % case-insensitive manner. % % Remark:: % Fields are copied at the deepest possible level. For instance, % if CONFIG has fields A.B.C1=1 and A.B.C2=2, and if UPDATE is the % structure A.B.C1=3, then VL_OVERRIDE() returns a strucuture with % fields A.B.C1=3, A.B.C2=2. By contrast, if UPDATE is the % structure A.B=4, then the field A.B is copied, and VL_OVERRIDE() % returns the structure A.B=4 (specifying 'Warn' would warn about % the fact that the substructure B.C1, B.C2 is being deleted). % % Remark:: % Two fields are matched if they correspond exactly. Specifically, % two fileds A(IA).(FA) and B(IA).FB of two struct arrays A and B % match if, and only if, (i) A and B have the same dimensions, % (ii) IA == IB, and (iii) FA == FB. % % See also: VL_ARGPARSE(), VL_HELP(). % Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. % All rights reserved. % % This file is part of the VLFeat library and is made available under % the terms of the BSD license (see the COPYING file). warn = false ; skip = false ; err = false ; casei = false ; if length(varargin) == 1 & ~ischar(varargin{1}) % legacy warn = 1 ; end if ~warn & length(varargin) > 0 for i=1:length(varargin) switch lower(varargin{i}) case 'warn' warn = true ; case 'skip' skip = true ; case 'err' err = true ; case 'argparse' argparse = true ; case 'casei' casei = true ; otherwise error(sprintf('Unknown option ''%s''.',varargin{i})) ; end end end % if CONFIG is not a struct array just copy UPDATE verbatim if ~isstruct(config) config = update ; return ; end % if CONFIG is a struct array but UPDATE is not, no match can be % established and we simply copy UPDATE verbatim if ~isstruct(update) config = update ; return ; end % if CONFIG and UPDATE are both struct arrays, but have different % dimensions then nom atch can be established and we simply copy % UPDATE verbatim if numel(update) ~= numel(config) config = update ; return ; end % if CONFIG and UPDATE are both struct arrays of the same % dimension, we override recursively each field for idx=1:numel(update) fields = fieldnames(update) ; for i = 1:length(fields) updateFieldName = fields{i} ; if casei configFieldName = findFieldI(config, updateFieldName) ; else configFieldName = findField(config, updateFieldName) ; end if ~isempty(configFieldName) config(idx).(configFieldName) = ... vl_override(config(idx).(configFieldName), ... update(idx).(updateFieldName)) ; else if warn warning(sprintf('copied field ''%s'' which is in UPDATE but not in CONFIG', ... updateFieldName)) ; end if err error(sprintf('The field ''%s'' is in UPDATE but not in CONFIG', ... updateFieldName)) ; end if skip if warn warning(sprintf('skipping field ''%s'' which is in UPDATE but not in CONFIG', ... updateFieldName)) ; end continue ; end config(idx).(updateFieldName) = update(idx).(updateFieldName) ; end end end % -------------------------------------------------------------------- function field = findFieldI(S, matchField) % -------------------------------------------------------------------- field = '' ; fieldNames = fieldnames(S) ; for fi=1:length(fieldNames) if strcmpi(fieldNames{fi}, matchField) field = fieldNames{fi} ; end end % -------------------------------------------------------------------- function field = findField(S, matchField) % -------------------------------------------------------------------- field = '' ; fieldNames = fieldnames(S) ; for fi=1:length(fieldNames) if strcmp(fieldNames{fi}, matchField) field = fieldNames{fi} ; end end
github
rising-turtle/slam_matlab-master
vl_quickvis.m
.m
slam_matlab-master/SIFT/vlfeat-0.9.16/toolbox/quickshift/vl_quickvis.m
3,696
utf_8
27f199dad4c5b9c192a5dd3abc59f9da
function [Iedge dists map gaps] = vl_quickvis(I, ratio, kernelsize, maxdist, maxcuts) % VL_QUICKVIS Create an edge image from a Quickshift segmentation. % IEDGE = VL_QUICKVIS(I, RATIO, KERNELSIZE, MAXDIST, MAXCUTS) creates an edge % stability image from a Quickshift segmentation. RATIO controls the tradeoff % between color consistency and spatial consistency (See VL_QUICKSEG) and % KERNELSIZE controls the bandwidth of the density estimator (See VL_QUICKSEG, % VL_QUICKSHIFT). MAXDIST is the maximum distance between neighbors which % increase the density. % % VL_QUICKVIS takes at most MAXCUTS thresholds less than MAXDIST, forming at % most MAXCUTS segmentations. The edges between regions in each of these % segmentations are labeled in IEDGE, where the label corresponds to the % largest DIST which preserves the edge. % % [IEDGE,DISTS] = VL_QUICKVIS(I, RATIO, KERNELSIZE, MAXDIST, MAXCUTS) also % returns the DIST thresholds that were chosen. % % IEDGE = VL_QUICKVIS(I, RATIO, KERNELSIZE, DISTS) will use the DISTS % specified % % [IEDGE,DISTS,MAP,GAPS] = VL_QUICKVIS(I, RATIO, KERNELSIZE, MAXDIST, MAXCUTS) % also returns the MAP and GAPS from VL_QUICKSHIFT. % % See Also: VL_QUICKSHIFT(), VL_QUICKSEG(), VL_HELP(). % Copyright (C) 2007-12 Andrea Vedaldi and Brian Fulkerson. % All rights reserved. % % This file is part of the VLFeat library and is made available under % the terms of the BSD license (see the COPYING file). if nargin == 4 dists = maxdist; maxdist = max(dists); [Iseg labels map gaps E] = vl_quickseg(I, ratio, kernelsize, maxdist); else [Iseg labels map gaps E] = vl_quickseg(I, ratio, kernelsize, maxdist); dists = unique(floor(gaps(:))); dists = dists(2:end-1); % remove the inf thresh and the lowest level thresh if length(dists) > maxcuts ind = round(linspace(1,length(dists), maxcuts)); dists = dists(ind); end end [Iedge dists] = mapvis(map, gaps, dists); function [Iedge dists] = mapvis(map, gaps, maxdist, maxcuts) % MAPVIS Create an edge image from a Quickshift segmentation. % IEDGE = MAPVIS(MAP, GAPS, MAXDIST, MAXCUTS) creates an edge % stability image from a Quickshift segmentation. MAXDIST is the maximum % distance between neighbors which increase the density. % % MAPVIS takes at most MAXCUTS thresholds less than MAXDIST, forming at most % MAXCUTS segmentations. The edges between regions in each of these % segmentations are labeled in IEDGE, where the label corresponds to the % largest DIST which preserves the edge. % % [IEDGE,DISTS] = MAPVIS(MAP, GAPS, MAXDIST, MAXCUTS) also returns the DIST % thresholds that were chosen. % % IEDGE = MAPVIS(MAP, GAPS, DISTS) will use the DISTS specified % % See Also: VL_QUICKVIS, VL_QUICKSHIFT, VL_QUICKSEG if nargin == 3 dists = maxdist; maxdist = max(dists); else dists = unique(floor(gaps(:))); dists = dists(2:end-1); % remove the inf thresh and the lowest level thresh % throw away min region size instead of maxdist? ind = find(dists < maxdist); dists = dists(ind); if length(dists) > maxcuts ind = round(linspace(1,length(dists), maxcuts)); dists = dists(ind); end end Iedge = zeros(size(map)); for i = 1:length(dists) s = find(gaps >= dists(i)); mapdist = map; mapdist(s) = s; [mapped labels] = vl_flatmap(mapdist); fprintf('%d/%d %d regions\n', i, length(dists), length(unique(mapped))) borders = getborders(mapped); Iedge(borders) = dists(i); %Iedge(borders) = Iedge(borders) + 1; %Iedge(borders) = i; end %%%%%%%%% GETBORDERS function borders = getborders(map) dx = conv2(map, [-1 1], 'same'); dy = conv2(map, [-1 1]', 'same'); borders = find(dx ~= 0 | dy ~= 0);