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
fitline3d.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/fitline3d.m
1,200
utf_8
3ca7a782577d8447e17c36ccf25f3d59
% FITLINE3D - Fits a line to a set of 3D points % % Usage: [L] = fitline3d(XYZ) % % Where: XYZ - 3xNpts array of XYZ coordinates % [x1 x2 x3 ... xN; % y1 y2 y3 ... yN; % z1 z2 z3 ... zN] % % Returns: L - 3x2 matrix consisting of the two endpoints of the line % that fits the points. The line is centered about the % mean of the points, and extends in the directions of the % principal eigenvectors, with scale determined by the % eigenvalues. % % Author: Felix Duvallet (CMU) % August 2006 function L = fitline3d(XYZ) % Since the covariance matrix should be 3x3 (not NxN), need % to take the transpose of the points. XYZ = XYZ'; % find mean of the points mu = mean(XYZ, 1); % covariance matrix C = cov(XYZ); % get the eigenvalues and eigenvectors [V, D] = eig(C); % largest eigenvector is in the last column col = size(V, 2); %get the number of columns % get the last eigenvector column and the last eigenvalue eVec = V(:, col); eVal = D(col, col); % start point - center about mean and scale eVector by eValue L(:, 1) = mu' - sqrt(eVal)*eVec; % end point L(:, 2) = mu' + sqrt(eVal)*eVec;
github
rising-turtle/slam_matlab-master
ransac_plane.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/ransac_plane.m
9,877
utf_8
6161d8cc1a602a9c2796433f55d7b6dd
% RANSAC - Robustly fits a model to data with the RANSAC algorithm % % Usage: % % [M, inliers] = ransac(x, fittingfn, distfn, degenfn s, t, feedback, ... % maxDataTrials, maxTrials) % % Arguments: % x - Data sets to which we are seeking to fit a model M % It is assumed that x is of size [d x Npts] % where d is the dimensionality of the data and Npts is % the number of data points. % % fittingfn - Handle to a function that fits a model to s % data from x. It is assumed that the function is of the % form: % M = fittingfn(x) % Note it is possible that the fitting function can return % multiple models (for example up to 3 fundamental matrices % can be fitted to 7 matched points). In this case it is % assumed that the fitting function returns a cell array of % models. % If this function cannot fit a model it should return M as % an empty matrix. % % distfn - Handle to a function that evaluates the % distances from the model to data x. % It is assumed that the function is of the form: % [inliers, M] = distfn(M, x, t) % This function must evaluate the distances between points % and the model returning the indices of elements in x that % are inliers, that is, the points that are within distance % 't' of the model. Additionally, if M is a cell array of % possible models 'distfn' will return the model that has the % most inliers. If there is only one model this function % must still copy the model to the output. After this call M % will be a non-cell object representing only one model. % % degenfn - Handle to a function that determines whether a % set of datapoints will produce a degenerate model. % This is used to discard random samples that do not % result in useful models. % It is assumed that degenfn is a boolean function of % the form: % r = degenfn(x) % It may be that you cannot devise a test for degeneracy in % which case you should write a dummy function that always % returns a value of 1 (true) and rely on 'fittingfn' to return % an empty model should the data set be degenerate. % % s - The minimum number of samples from x required by % fittingfn to fit a model. % % t - The distance threshold between a data point and the model % used to decide whether the point is an inlier or not. % % feedback - An optional flag 0/1. If set to one the trial count and the % estimated total number of trials required is printed out at % each step. Defaults to 0. % % maxDataTrials - Maximum number of attempts to select a non-degenerate % data set. This parameter is optional and defaults to 100. % % maxTrials - Maximum number of iterations. This parameter is optional and % defaults to 1000. % % Returns: % M - The model having the greatest number of inliers. % inliers - An array of indices of the elements of x that were % the inliers for the best model. % % For an example of the use of this function see RANSACFITHOMOGRAPHY or % RANSACFITPLANE % References: % M.A. Fishler and R.C. Boles. "Random sample concensus: A paradigm % for model fitting with applications to image analysis and automated % cartography". Comm. Assoc. Comp, Mach., Vol 24, No 6, pp 381-395, 1981 % % Richard Hartley and Andrew Zisserman. "Multiple View Geometry in % Computer Vision". pp 101-113. Cambridge University Press, 2001 % Copyright (c) 2003-2006 Peter Kovesi % School of Computer Science & Software Engineering % The University of Western Australia % pk at csse uwa edu au % http://www.csse.uwa.edu.au/~pk % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal % in the Software without restriction, subject to the following conditions: % % The above copyright notice and this permission notice shall be included in % all copies or substantial portions of the Software. % % The Software is provided "as is", without warranty of any kind. % % May 2003 - Original version % February 2004 - Tidied up. % August 2005 - Specification of distfn changed to allow model fitter to % return multiple models from which the best must be selected % Sept 2006 - Random selection of data points changed to ensure duplicate % points are not selected. % February 2007 - Jordi Ferrer: Arranged warning printout. % Allow maximum trials as optional parameters. % Patch the problem when non-generated data % set is not given in the first iteration. % August 2008 - 'feedback' parameter restored to argument list and other % breaks in code introduced in last update fixed. % December 2008 - Octave compatibility mods % June 2009 - Argument 'MaxTrials' corrected to 'maxTrials'! function [M, inliers] = ransac(x, fittingfn, distfn, degenfn, s, t, feedback, ... maxDataTrials, maxTrials) Octave = exist('OCTAVE_VERSION') ~= 0; % Test number of parameters error ( nargchk ( 6, 9, nargin ) ); if nargin < 9; maxTrials = 1000; end; if nargin < 8; maxDataTrials = 100; end; if nargin < 7; feedback = 0; end; [rows, npts] = size(x); p = 0.99; % Desired probability of choosing at least one sample % free from outliers bestM = NaN; % Sentinel value allowing detection of solution failure. trialcount = 0; bestscore = 0; N = 1; % Dummy initialisation for number of trials. while N > trialcount % Select at random s datapoints to form a trial model, M. % In selecting these points we have to check that they are not in % a degenerate configuration. degenerate = 1; count = 1; while degenerate % Generate s random indicies in the range 1..npts % (If you do not have the statistics toolbox, or are using Octave, % use the function RANDOMSAMPLE from my webpage) if Octave | ~exist('randsample.m') ind = randomsample(npts, s); else ind = randsample(npts, s); end % Test that these points are not a degenerate configuration. degenerate = feval(degenfn, x(:,ind)); if ~degenerate % Fit model to this random selection of data points. % Note that M may represent a set of models that fit the data in % this case M will be a cell array of models M = feval(fittingfn, x(:,ind)); % Depending on your problem it might be that the only way you % can determine whether a data set is degenerate or not is to % try to fit a model and see if it succeeds. If it fails we % reset degenerate to true. if isempty(M) degenerate = 1; end end % Safeguard against being stuck in this loop forever count = count + 1; if count > maxDataTrials warning('Unable to select a nondegenerate data set'); break end end % Once we are out here we should have some kind of model... % Evaluate distances between points and model returning the indices % of elements in x that are inliers. Additionally, if M is a cell % array of possible models 'distfn' will return the model that has % the most inliers. After this call M will be a non-cell object % representing only one model. [inliers, M] = feval(distfn, M, x, t); % Find the number of inliers to this model. ninliers = length(inliers); if ninliers > bestscore % Largest set of inliers so far... bestscore = ninliers; % Record data for this model bestinliers = inliers; bestM = M; % Update estimate of N, the number of trials to ensure we pick, % with probability p, a data set with no outliers. fracinliers = ninliers/npts; pNoOutliers = 1 - fracinliers^s; pNoOutliers = max(eps, pNoOutliers); % Avoid division by -Inf pNoOutliers = min(1-eps, pNoOutliers);% Avoid division by 0. N = log(1-p)/log(pNoOutliers); end trialcount = trialcount+1; if feedback fprintf('trial %d out of %d \r',trialcount, ceil(N)); end % Safeguard against being stuck in this loop forever if trialcount > maxTrials warning( ... sprintf('ransac reached the maximum number of %d trials',... maxTrials)); break end end fprintf('\n'); if ~isnan(bestM) % We got a solution M = bestM; inliers = bestinliers; else M = []; inliers = []; error('ransac was unable to find a useful solution'); end
github
rising-turtle/slam_matlab-master
Kabsch.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/Kabsch.m
22,003
utf_8
d9ea79a024f3c2dd185841ba44642f29
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="X-UA-Compatible" content="IE=8" /> <script type="text/javascript" src="/includes_content/nextgen/scripts/jquery/jquery-latest.js"></script> <!-- START OF GLOBAL NAV --> <link rel="stylesheet" href="/matlabcentral/css/sitewide.css" type="text/css" /> <link rel="stylesheet" href="/matlabcentral/css/mlc.css" type="text/css" /> <!--[if lt IE 7]> <link href="/matlabcentral/css/ie6down.css" type="text/css" rel="stylesheet"> <![endif]--> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <meta name="keywords" content="file exchange, matlab answers, newsgroup access, link exchange, matlab blog, matlab central, simulink blog, matlab community, matlab and simulink community" /> <meta name="description" content="File exchange, MATLAB Answers, newsgroup access, Links, and Blogs for the MATLAB &amp; Simulink user community" /> <link rel="stylesheet" href="/matlabcentral/css/fileexchange.css" type="text/css" /> <link rel="stylesheet" type="text/css" media="print" href="/matlabcentral/css/print.css" /> <title>Kabsch algorithm: Kabsch(P, Q, m) - File Exchange - MATLAB Central</title> <script src="/matlabcentral/fileexchange/javascripts/prototype.js?1333472917" type="text/javascript"></script> <script src="/matlabcentral/fileexchange/javascripts/effects.js?1333472917" type="text/javascript"></script> <script src="/matlabcentral/fileexchange/javascripts/dragdrop.js?1333472917" type="text/javascript"></script> <script src="/matlabcentral/fileexchange/javascripts/controls.js?1333472917" type="text/javascript"></script> <script src="/matlabcentral/fileexchange/javascripts/application.js?1333472917" type="text/javascript"></script> <script src="/matlabcentral/fileexchange/javascripts/searchfield.js?1333472917" type="text/javascript"></script> <link href="/matlabcentral/fileexchange/stylesheets/application.css?1333472917" media="screen" rel="stylesheet" type="text/css" /> <link rel="search" type="application/opensearchdescription+xml" title="Search File Exchange" href="/matlabcentral/fileexchange/search.xml" /> </head> <body> <div id="header"> <div class="wrapper"> <!--put nothing in left div - only 11px wide shadow --> <div class="main"> <div id="logo"><a href="/matlabcentral/" title="MATLAB Central Home"><img src="/matlabcentral/images/mlclogo-whitebgd.gif" alt="MATLAB Central" /></a></div> <div id="headertools"> <script language="JavaScript1.3" type="text/javascript"> function submitForm(query){ choice = document.forms['searchForm'].elements['search_submit'].value; if (choice == "entire1" || choice == "contest" || choice == "matlabcentral" || choice == "blogs"){ var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "q"; newElem.value = query.value; document.forms['searchForm'].appendChild(newElem); submit_action = '/searchresults/'; } switch(choice){ case "matlabcentral": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "c[]"; newElem.value = "matlabcentral"; document.forms['searchForm'].appendChild(newElem); selected_index = 0; break case "fileexchange": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "term"; newElem.value = query.value; newElem.classname = "formelem"; document.forms['searchForm'].appendChild(newElem); submit_action = "/matlabcentral/fileexchange/"; selected_index = 1; break case "answers": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "term"; newElem.value = query.value; newElem.classname = "formelem"; document.forms['searchForm'].appendChild(newElem); submit_action = "/matlabcentral/answers/"; selected_index = 2; break case "cssm": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "search_string"; newElem.value = query.value; newElem.classname = "formelem"; document.forms['searchForm'].appendChild(newElem); submit_action = "/matlabcentral/newsreader/search_results"; selected_index = 3; break case "linkexchange": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "term"; newElem.value = query.value; newElem.classname = "formelem"; document.forms['searchForm'].appendChild(newElem); submit_action = "/matlabcentral/linkexchange/"; selected_index = 4; break case "blogs": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "c[]"; newElem.value = "blogs"; document.forms['searchForm'].appendChild(newElem); selected_index = 5; break case "trendy": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "search"; newElem.value = query.value; newElem.classname = "formelem"; document.forms['searchForm'].appendChild(newElem); submit_action = "/matlabcentral/trendy"; selected_index = 6; break case "cody": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "term"; newElem.value = query.value; newElem.classname = "formelem"; document.forms['searchForm'].appendChild(newElem); submit_action = "/matlabcentral/cody/"; selected_index = 7; break case "contest": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "c[]"; newElem.value = "contest"; document.forms['searchForm'].appendChild(newElem); selected_index = 8; break case "entire1": var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "c[]"; newElem.value = "entiresite"; document.forms['searchForm'].appendChild(newElem); selected_index = 9; break default: var newElem = document.createElement("input"); newElem.type = "hidden"; newElem.name = "c[]"; newElem.value = "entiresite"; document.forms['searchForm'].appendChild(newElem); selected_index = 9; break } document.forms['searchForm'].elements['search_submit'].selectedIndex = selected_index; document.forms['searchForm'].elements['query'].value = query.value; document.forms['searchForm'].action = submit_action; } </script> <form name="searchForm" method="GET" action="" style="margin:0px; margin-top:5px; font-size:90%" onsubmit="submitForm(query)"> <label for="search">Search: </label> <select name="search_submit" style="font-size:9px "> <option value="matlabcentral">MATLAB Central</option> <option value="fileexchange" selected>&nbsp;&nbsp;&nbsp;File Exchange</option> <option value="answers">&nbsp;&nbsp;&nbsp;Answers</option> <option value="cssm">&nbsp;&nbsp;&nbsp;Newsgroup</option> <option value="linkexchange">&nbsp;&nbsp;&nbsp;Link Exchange</option> <option value="blogs">&nbsp;&nbsp;&nbsp;Blogs</option> <option value="trendy">&nbsp;&nbsp;&nbsp;Trendy</option> <option value="cody">&nbsp;&nbsp;&nbsp;Cody</option> <option value="contest">&nbsp;&nbsp;&nbsp;Contest</option> <option value="entire1">MathWorks.com</option> </select> <input type="text" name="query" size="10" class="formelem" value="" /> <input type="submit" value="Go" class="formelem gobutton" /> </form> <ol id="access2"> <li class="first"> Amirhossein Tamjidi </li> <li><a href="/accesslogin/editCommunityProfile.do?uri=/matlabcentral/fileexchange/25746-kabsch-algorithm/content/Kabsch.m">Create Community Profile</a></li> <li><a href="https://www.mathworks.com/accesslogin/logout.do?uri=http://www.mathworks.com/matlabcentral/fileexchange/25746-kabsch-algorithm/content/Kabsch.m">Log Out</a></li> </ol> </div> <div id="globalnav"> <!-- from includes/global_nav.html --> <ol> <li class="active"> <a href="/matlabcentral/fileexchange/">File Exchange</a> </li> <li class=";"> <a href="/matlabcentral/answers/">Answers</a> </li> <li class=";"> <a href="/matlabcentral/newsreader/">Newsgroup</a> </li> <li class=";"> <a href="/matlabcentral/linkexchange/">Link Exchange</a> </li> <li class=";"> <a href="http://blogs.mathworks.com/">Blogs</a> </li> <li class=";"> <a href="/matlabcentral/trendy">Trendy</a> </li> <li class=";"> <a href="/matlabcentral/cody">Cody</a> </li> <li class=";"> <a href="/matlabcentral/contest/">Contest</a> </li> <li class="icon mathworks"> <a href="/">MathWorks.com</a> </li> </ol> </div> </div> </div> </div> <div id="middle"> <div class="wrapper"> <div id="mainbody" class="columns2"> <div class="manifest"> <div class="ctaBtn ctaBlueBtn btnSmall"> <div class="btnCont"> <div class="btn download"> <a href="http://www.mathworks.com/matlabcentral/fileexchange/25746-kabsch-algorithm?controller=file_infos&amp;download=true" title="Download Now">Download All</a> </div> </div> </div> <p class="license"> Code covered by the <a href="/matlabcentral/fileexchange/view_license?file_info_id=25746" onclick="window.open(this.href,'new_window','height=500,width=640,scrollbars=yes');return false;">BSD License</a> <a href="/matlabcentral/fileexchange/help_license#bsd" class="info notext" onclick="window.open(this.href,'small','toolbar=no,resizable=yes,status=yes,menu=no,scrollbars=yes,width=600,height=550');return false;">&nbsp;</a> </p> <h3 class="highlights_title"> Highlights from<br/> <a href="http://www.mathworks.com/matlabcentral/fileexchange/25746-kabsch-algorithm" class="manifest_title">Kabsch algorithm</a> </h3> <ul class="manifest"> <li class="manifest"> <a href="http://www.mathworks.com/matlabcentral/fileexchange/25746-kabsch-algorithm/content/Kabsch.m" class="function" title="Function">Kabsch(P, Q, m)</a> <span class="description">Find the Least Root Mean Square between two sets of N points in D dimensions</span> </li> <li class="manifest_allfiles"> <a href="http://www.mathworks.com/matlabcentral/fileexchange/25746-kabsch-algorithm/all_files">View all files</a></li> </ul> </div> <table cellpadding="0" cellspacing="0" class="details file"> <tr> <th class="maininfo"> <div id="details" class="content_type_details"> from <a href="/matlabcentral/fileexchange/file_infos/25746-kabsch-algorithm" class="content_type_author">Kabsch algorithm</a></h2> by <a href="/matlabcentral/fileexchange/authors/75295">Ehud Schreiber</a> <br/>Find the rigid transformation & Least Root Mean Square distance between two paired sets of points </p> </div> </th> </tr> <tr> <td class="file"> <table cellpadding="0" cellspacing="0" border="0" class="fileview section"> <tr class="title"> <th><span class="heading">Kabsch(P, Q, m)</span></th> </tr> <tr> <td> <div class="codecontainer"><pre class="matlab-code">% Find the Least Root Mean Square between two sets of N points in D dimensions % and the rigid transformation (i.e. translation and rotation) % to employ in order to bring one set that close to the other, % Using the Kabsch (1976) algorithm. % Note that the points are paired, i.e. we know which point in one set % should be compared to a given point in the other set. % % References: % 1) Kabsch W. A solution for the best rotation to relate two sets of vectors. Acta Cryst A 1976;32:9223. % 2) Kabsch W. A discussion of the solution for the best rotation to relate two sets of vectors. Acta Cryst A 1978;34:8278. % 3) http://cnx.org/content/m11608/latest/ % 4) http://en.wikipedia.org/wiki/Kabsch_algorithm % % We slightly generalize, allowing weights given to the points. % Those weights are determined a priori and do not depend on the distances. % % We work in the convention that points are column vectors; % some use the convention where they are row vectors instead. % % Input variables: % P : a D*N matrix where P(a,i) is the a-th coordinate of the i-th point % in the 1st representation % Q : a D*N matrix where Q(a,i) is the a-th coordinate of the i-th point % in the 2nd representation % m : (Optional) a row vector of length N giving the weights, i.e. m(i) is % the weight to be assigned to the deviation of the i-th point. % If not supplied, we take by default the unweighted (or equal weighted) % m(i) = 1/N. % The weights do not have to be normalized; % we divide by the sum to ensure sum_{i=1}^N m(i) = 1. % The weights must be non-negative with at least one positive entry. % Output variables: % U : a proper orthogonal D*D matrix, representing the rotation % r : a D-dimensional column vector, representing the translation % lrms: the Least Root Mean Square % % Details: % If p_i, q_i are the i-th point (as a D-dimensional column vector) % in the two representations, i.e. p_i = P(:,i) etc., and for % p_i' = U p_i + r (' does not stand for transpose!) % we have p_i' ~ q_i, that is, % lrms = sqrt(sum_{i=1}^N m(i) (p_i' - q_i)^2) % is the minimal rms when going over the possible U and r. % (assuming the weights are already normalized). % function[U, r, lrms] = Kabsch(P, Q, m) sz1 = size(P) ; sz2 = size(Q) ; if (length(sz1) ~= 2 || length(sz2) ~= 2) error 'P and Q must be matrices' ; end if (any(sz1 ~= sz2)) error 'P and Q must be of same size' ; end D = sz1(1) ; % dimension of space N = sz1(2) ; % number of points if (nargin &gt;= 3) if (~isvector(m) || any(size(m) ~= [1 N])) error 'm must be a row vector of length N' ; end if (any(m &lt; 0)) error 'm must have non-negative entries' ; end msum = sum(m) ; if (msum == 0) error 'm must contain some positive entry' ; end m = m / msum ; % normalize so that weights sum to 1 else % m not supplied - use default m = ones(1,N)/N ; end p0 = P*m' ; % the centroid of P q0 = Q*m' ; % the centroid of Q v1 = ones(1,N) ; % row vector of N ones P = P - p0*v1 ; % translating P to center the origin Q = Q - q0*v1 ; % translating Q to center the origin % C is a covariance matrix of the coordinates % C = P*diag(m)*Q' % but this is inefficient, involving an N*N matrix, while typically D &lt;&lt; N. % so we use another way to compute Pdm = P*diag(m) Pdm = zeros(D,N) ; for i=1:N Pdm(:,i) = m(i)*P(:,i) ; end C = Pdm*Q' ; % C = P*Q' / N ; % (for the non-weighted case) [V,S,W] = svd(C) ; % singular value decomposition I = eye(D) ; if (det(C) &lt; 0) I(D,D) = -1 ; end U = W*I*V' ; r = q0 - U*p0 ; Diff = U*P - Q ; % P, Q already centered % lrms = sqrt(sum(sum(Diff.*Diff))/N) ; % (for the non-weighted case) lrms = 0 ; for i=1:N lrms = lrms + m(i)*Diff(:,i)'*Diff(:,i) ; end lrms = sqrt(lrms) ; end </pre></div> </td> </tr> </table> </td> </tr> </table> <p id="contactus">Contact us at <a href="mailto:[email protected]">[email protected]</a></p> </div> <div class="clearboth">&nbsp;</div> </div> </div> <!-- footer.html --> <!-- START OF FOOTER --> <div id="mlc-footer"> <script type="text/javascript"> function clickDynamic(obj, target_url, tracking_code) { var pos=target_url.indexOf("?"); if (pos<=0) { var linkComponents = target_url + tracking_code; obj.href=linkComponents; } } </script> <div class="wrapper"> <div> <ul id="matlabcentral"> <li class="copyright first">&copy; 1994-2012 The MathWorks, Inc.</li> <li class="first"><a href="/help.html" title="Site Help">Site Help</a></li> <li><a href="/company/aboutus/policies_statements/patents.html" title="patents" rel="nofollow">Patents</a></li> <li><a href="/company/aboutus/policies_statements/trademarks.html" title="trademarks" rel="nofollow">Trademarks</a></li> <li><a href="/company/aboutus/policies_statements/" title="privacy policy" rel="nofollow">Privacy Policy</a></li> <li><a href="/company/aboutus/policies_statements/piracy.html" title="preventing piracy" rel="nofollow">Preventing Piracy</a></li> <li class="last"><a href="/matlabcentral/termsofuse.html" title="Terms of Use" rel="nofollow">Terms of Use</a></li> <li class="icon"><a href="/company/rss/" title="RSS" class="rssfeed" rel="nofollow"><span class="text">RSS</span></a></li> <li class="icon"><a href="http://www.mathworks.com/programs/bounce_hub_generic.html?s_cid=mlc_fbk&url=http://www.facebook.com/MATLAB" title="Facebook" class="facebook" rel="nofollow"><span class="text">Facebook</span></a></li> <li class="last icon"><a href="http://www.mathworks.com/programs/bounce_hub_generic.html?s_cid=mlc_twt&url=http://www.twitter.com/MATLAB" title="Twitter" class="twitter" rel="nofollow"><span class="text">Twitter</span></a></li> </ul> <ul id="mathworks"> <li class="first sectionhead">Featured MathWorks.com Topics:</li> <li class="first"><a href="/products/new_products/latest_features.html" onclick="clickDynamic(this, this.href, '?s_cid=MLC_new')">New Products</a></li> <li><a href="/support/" title="support" onclick="clickDynamic(this, this.href, '?s_cid=MLC_support')">Support</a></li> <li><a href="/help" title="documentation" onclick="clickDynamic(this, this.href, '?s_cid=MLC_doc')">Documentation</a></li> <li><a href="/services/training/" title="training" onclick="clickDynamic(this, this.href, '?s_cid=MLC_training')">Training</a></li> <li><a href="/company/events/webinars/" title="Webinars" onclick="clickDynamic(this, this.href, '?s_cid=MLC_webinars')">Webinars</a></li> <li><a href="/company/newsletters/" title="newsletters" onclick="clickDynamic(this, this.href, '?s_cid=MLC_newsletters')">Newsletters</a></li> <li><a href="/programs/trials/trial_request.html?prodcode=ML&s_cid=MLC_trials" title="MATLAB Trials">MATLAB Trials</a></li> <li class="last"><a href="/company/jobs/opportunities/index_en_US.html" title="Careers" onclick="clickDynamic(this, this.href, '?s_cid=MLC_careers')">Careers</a></li> </ul> </div> </div> </div> <!-- END OF FOOTER --> <!-- SiteCatalyst code version: H.4. --> <script language="JavaScript" type="text/javascript" src="/includes_content/jscript/omniture/s_code.js"></script> <script language="JavaScript" type="text/javascript"><!-- s.pageName=document.title s.eVar13='Version B'; //code for testing two versions of the intro text on the homepage products tab /************* DO NOT ALTER ANYTHING BELOW THIS LINE ! **************/ var s_code=s.t();if(s_code)document.write(s_code)//--></script> <script language="JavaScript" type="text/javascript"><!-- if(navigator.appVersion.indexOf('MSIE')>=0)document.write(unescape('%3C')+'\!-'+'-') //--></script><!--/DO NOT REMOVE/--> <!-- End SiteCatalyst code version: H.4. --> <!--JF: Jai and I added the following code for GA to test mobile devices. 12/23/10 --> <script type="text/javascript"> var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-7506924-7']); _gaq.push(['_setDomainName', 'none']); _gaq.push(['_setAllowLinker', true]); var whichSection = location.href.split("/"); if ((whichSection[3]) && (whichSection[3].lastIndexOf(".html") == -1)) { _gaq.push(['_setCustomVar', 1, 'Section1', whichSection[3], 3]); // alert(whichSection[3]); } if ((whichSection[4]) && (whichSection[4].lastIndexOf(".html") == -1)) { whichSectionCombined = whichSection[3] + "/" + whichSection[4]; _gaq.push(['_setCustomVar', 2, 'Section2', whichSectionCombined, 3]); // alert(whichSectionCombined); } if ((whichSection[5]) && (whichSection[5].lastIndexOf(".html") == -1)) { whichSectionCombined = whichSection[3] + "/" + whichSection[4] + "/" + whichSection[5]; _gaq.push(['_setCustomVar', 3, 'Section3', whichSectionCombined, 3]); //alert(whichSectionCombined); } _gaq.push(['_trackPageview']); (function() { var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); })(); </script> </body> </html>
github
rising-turtle/slam_matlab-master
fitplane.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/fitplane.m
1,694
utf_8
a058a2453754cff9ea42776f1034436a
% FITPLANE - solves coefficients of plane fitted to 3 or more points % % Usage: B = fitplane(XYZ) % % Where: XYZ - 3xNpts array of xyz coordinates to fit plane to. % If Npts is greater than 3 a least squares solution % is generated. % % Returns: B - 4x1 array of plane coefficients in the form % b(1)*X + b(2)*Y +b(3)*Z + b(4) = 0 % The magnitude of B is 1. % % See also: RANSACFITPLANE % Copyright (c) 2003-2005 Peter Kovesi % School of Computer Science & Software Engineering % The University of Western Australia % http://www.csse.uwa.edu.au/ % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal % in the Software without restriction, subject to the following conditions: % % The above copyright notice and this permission notice shall be included in % all copies or substantial portions of the Software. % % The Software is provided "as is", without warranty of any kind. % June 2003 function B = fitplane(XYZ) [rows,npts] = size(XYZ); if rows ~=3 error('data is not 3D'); end if npts < 3 error('too few points to fit plane'); end % Set up constraint equations of the form AB = 0, % where B is a column vector of the plane coefficients % in the form b(1)*X + b(2)*Y +b(3)*Z + b(4) = 0. A = [XYZ' ones(npts,1)]; % Build constraint matrix if npts == 3 % Pad A with zeros A = [A; zeros(1,4)]; end [u d v] = svd(A); % Singular value decomposition. B = v(:,4); % Solution is last column of v.
github
rising-turtle/slam_matlab-master
iscolinear.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/iscolinear.m
2,318
utf_8
65025b7413f8f6b4cb16dd1689a5900f
% ISCOLINEAR - are 3 points colinear % % Usage: r = iscolinear(p1, p2, p3, flag) % % Arguments: % p1, p2, p3 - Points in 2D or 3D. % flag - An optional parameter set to 'h' or 'homog' % indicating that p1, p2, p3 are homogneeous % coordinates with arbitrary scale. If this is % omitted it is assumed that the points are % inhomogeneous, or that they are homogeneous with % equal scale. % % Returns: % r = 1 if points are co-linear, 0 otherwise % Copyright (c) 2004-2005 Peter Kovesi % School of Computer Science & Software Engineering % The University of Western Australia % http://www.csse.uwa.edu.au/ % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal % in the Software without restriction, subject to the following conditions: % % The above copyright notice and this permission notice shall be included in % all copies or substantial portions of the Software. % % The Software is provided "as is", without warranty of any kind. % February 2004 % January 2005 - modified to allow for homogeneous points of arbitrary % scale (thanks to Michael Kirchhof) function r = iscolinear(p1, p2, p3, flag) if nargin == 3 % Assume inhomogeneous coords flag = 'inhomog'; end if ~all(size(p1)==size(p2)) | ~all(size(p1)==size(p3)) | ... ~(length(p1)==2 | length(p1)==3) error('points must have the same dimension of 2 or 3'); end % If data is 2D, assume they are 2D inhomogeneous coords. Make them % homogeneous with scale 1. if length(p1) == 2 p1(3) = 1; p2(3) = 1; p3(3) = 1; end if flag(1) == 'h' % Apply test that allows for homogeneous coords with arbitrary % scale. p1 X p2 generates a normal vector to plane defined by % origin, p1 and p2. If the dot product of this normal with p3 % is zero then p3 also lies in the plane, hence co-linear. r = abs(dot(cross(p1, p2),p3)) < eps; else % Assume inhomogeneous coords, or homogeneous coords with equal % scale. r = norm(cross(p2-p1, p3-p1)) < eps; end
github
rising-turtle/slam_matlab-master
testfitplane.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/testfitplane.m
3,367
utf_8
422156cc86a4f56b427ec295e9306b63
% TESTFITPLANE - demonstrates RANSAC plane fitting % % Usage: testfitplane(outliers, sigma, t, feedback) % % Arguments: % outliers - Fraction specifying how many points are to be % outliers. % sigma - Standard deviation of inlying points from the % true plane. % t - Distance threshold to be used by the RANSAC % algorithm for deciding whether a point is an % inlier. % feedback - Optional flag 0 or 1 to turn on RANSAC feedback % information. % % Try using: testfitplane(0.3, 0.05, 0.05) % % See also: RANSACFITPLANE, FITPLANE % Copyright (c) 2003-2005 Peter Kovesi % School of Computer Science & Software Engineering % The University of Western Australia % http://www.csse.uwa.edu.au/ % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal % in the Software without restriction, subject to the following conditions: % % The above copyright notice and this permission notice shall be included in % all copies or substantial portions of the Software. % % The Software is provided "as is", without warranty of any kind. % June 2003 function testfitplane(outliers, sigma, t, feedback) if nargin == 3 feedback = 0; end % Hard wire some constants - vary these as you wish npts = 100; % Number of 3D data points % Define a plane ax + by + cz + d = 0 a = 10; b = -3; c = 5; d = 1; B = [a b c d]'; B = B/norm(B); outsigma = 30*sigma; % outlying points have a distribution that is % 30 times as spread as the inlying points vpts = round((1-outliers)*npts); % No of valid points opts = npts - vpts; % No of outlying points % Generate npts points in the plane X = rand(1,npts); Y = rand(1,npts); Z = (-a*X -b*Y -d)/c; XYZ = [X Y Z]; % Add uniform noise of +/-sigma XYZ = XYZ + (2*rand(size(XYZ))-1)*sigma; % Generate opts random outliers n = length(XYZ); ind = randperm(n); % get a random set of point indices ind = ind(1:opts); % ... of length opts % Add uniform noise of outsigma to the points chosen to be outliers. % XYZ(:,ind) = XYZ(:,ind) + (2*rand(3,opts)-1)*outsigma; XYZ(:,ind) = XYZ(:,ind) + sign(rand(3,opts)-.5).*(rand(3,opts)+1)*outsigma; % Display the cloud of points figure(1), clf, plot3(XYZ(1,:),XYZ(2,:),XYZ(3,:), 'r*'); % Perform RANSAC fitting of the plane [Bfitted, P, inliers] = ransacfitplane(XYZ, t, feedback); fprintf('Original plane coefficients: '); fprintf('%8.3f ',B); fprintf('\nFitted plane coefficients: '); fprintf('%8.3f ',Bfitted); fprintf('\n'); % Display the triangular patch formed by the 3 points that gave the % plane of maximum consensus patch(P(1,:), P(2,:), P(3,:), 'g') box('on'), grid('on'), rotate3d('on') fprintf('\nRotate image so that planar patch is seen edge on\n'); fprintf('If the fit has been successful the inlying points should\n'); fprintf('form a line\n\n');
github
rising-turtle/slam_matlab-master
ransacfitplane.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/ransacfitplane.m
4,285
utf_8
3a8b352c171a4ca6acb11d45a6c10caf
% RANSACFITPLANE - fits plane to 3D array of points using RANSAC % % Usage [B, P, inliers] = ransacfitplane(XYZ, t, feedback) % % This function uses the RANSAC algorithm to robustly fit a plane % to a set of 3D data points. % % Arguments: % XYZ - 3xNpts array of xyz coordinates to fit plane to. % t - The distance threshold between data point and the plane % used to decide whether a point is an inlier or not. % feedback - Optional flag 0 or 1 to turn on RANSAC feedback % information. % % Returns: % B - 4x1 array of plane coefficients in the form % b(1)*X + b(2)*Y +b(3)*Z + b(4) = 0 % The magnitude of B is 1. % This plane is obtained by a least squares fit to all the % points that were considered to be inliers, hence this % plane will be slightly different to that defined by P below. % P - The three points in the data set that were found to % define a plane having the most number of inliers. % The three columns of P defining the three points. % inliers - The indices of the points that were considered % inliers to the fitted plane. % % See also: RANSAC, FITPLANE % Copyright (c) 2003-2008 Peter Kovesi % School of Computer Science & Software Engineering % The University of Western Australia % http://www.csse.uwa.edu.au/ % % Permission is hereby granted, free of charge, to any person obtaining a copy % of this software and associated documentation files (the "Software"), to deal % in the Software without restriction, subject to the following conditions: % % The above copyright notice and this permission notice shall be included in % all copies or substantial portions of the Software. % % The Software is provided "as is", without warranty of any kind. % June 2003 - Original version. % Feb 2004 - Modified to use separate ransac function % Aug 2005 - planeptdist modified to fit new ransac specification % Dec 2008 - Much faster distance calculation in planeptdist (thanks to % Alastair Harrison) function [B, P, inliers] = ransacfitplane(XYZ, t, feedback) if nargin == 2 feedback = 0; end [rows, npts] = size(XYZ); if rows ~=3 error('data is not 3D'); end if npts < 3 error('too few points to fit plane'); end s = 3; % Minimum No of points needed to fit a plane. fittingfn = @defineplane; distfn = @planeptdist; degenfn = @isdegenerate; [P, inliers] = ransac_plane(XYZ, fittingfn, distfn, degenfn, s, t, feedback); % Perform least squares fit to the inlying points B = fitplane(XYZ(:,inliers)); %------------------------------------------------------------------------ % Function to define a plane given 3 data points as required by % RANSAC. In our case we use the 3 points directly to define the plane. function P = defineplane(X); P = X; %------------------------------------------------------------------------ % Function to calculate distances between a plane and a an array of points. % The plane is defined by a 3x3 matrix, P. The three columns of P defining % three points that are within the plane. function [inliers, P] = planeptdist(P, X, t) n = cross(P(:,2)-P(:,1), P(:,3)-P(:,1)); % Plane normal. n = n/norm(n); % Make it a unit vector. npts = length(X); d = zeros(npts,1); % d will be an array of distance values. % The following loop builds up the dot product between a vector from P(:,1) % to every X(:,i) with the unit plane normal. This will be the % perpendicular distance from the plane for each point for i=1:3 d = d + (X(i,:)'-P(i,1))*n(i); end inliers = find(abs(d) < t); %------------------------------------------------------------------------ % Function to determine whether a set of 3 points are in a degenerate % configuration for fitting a plane as required by RANSAC. In this case % they are degenerate if they are colinear. function r = isdegenerate(X) % The three columns of X are the coords of the 3 points. r = iscolinear(X(:,1),X(:,2),X(:,3));
github
rising-turtle/slam_matlab-master
evaluate_result.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/evaluate_result.m
1,659
utf_8
e5ce33520dfb03572fe195820d79fe85
function evaluate_result % de_y = get_y_error(); % fe = get_final_error(); [de_y,fe,fe_norm,fe_perecent,ye_percent,path] = get_error() end function [de_y,fe,fe_norm,fe_perecent,ye_percent,path] = get_error() legend('off') grid off axis off h = gcf; axesObjs = get(h, 'Children'); dataObjs = get(axesObjs(1), 'Children'); objTypes = get(dataObjs(1), 'Type'); xdata1 = get(dataObjs(1), 'XData'); ydata1 = get(dataObjs(1), 'YData'); zdata1 = get(dataObjs(1), 'ZData'); path1 = 0; for i =1:length(xdata1)-1 path1 = path1 + norm([xdata1(i+1);ydata1(i+1);zdata1(i+1)]-[xdata1(i);ydata1(i);zdata1(i)] ); end xdata2 = get(dataObjs(2), 'XData'); ydata2 = get(dataObjs(2), 'YData'); zdata2 = get(dataObjs(2), 'ZData'); path2 = 0; for i =1:length(xdata2)-1 path2 = path2 + norm([xdata2(i+1);ydata2(i+1);zdata2(i+1)]-[xdata2(i);ydata2(i);zdata2(i)] ); end % figure;plot(abs(ydata1),'r');hold on;plot(abs(ydata2),'b') de_y(1) = mean(abs(ydata1)); de_y(2) = mean(abs(ydata2)); fe(1,:) = [xdata1(end);ydata1(end);zdata1(end)]'; fe(2,:) = [xdata2(end);ydata2(end);zdata2(end)]'; fe_norm(1) = norm([xdata1(end);ydata1(end);zdata1(end)]); fe_norm(2) = norm([xdata2(end);ydata2(end);zdata2(end)]); fe_perecent(1) = fe_norm(1)/min(path1,path2)*100; fe_perecent(2) = fe_norm(2)/min(path1,path2)*100; ye_percent(1) = de_y(1)/path1*100; ye_percent(2) = de_y(1)/path2*100; path(1)=path1; path(2)=path2; end % function fe = get_final_error() % h = gcf; % axesObjs = get(h, 'Children'); % dataObjs = get(axesObjs, 'Children'); % objTypes = get(dataObjs, 'Type'); % xdata = get(dataObjs, 'XData'); % ydata = get(dataObjs, 'YData'); % zdata = get(dataObjs, 'ZData'); % end
github
rising-turtle/slam_matlab-master
test_the_effect_of_orinetation_.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/test_the_effect_of_orinetation_.m
3,784
utf_8
080623a148f01b9929a71b510bfa1461
function [angle1,angle2,angle3,xx,trajectory,cov_info]=test_the_effect_of_orinetation_(snapshot_step,h_figure) config_file_for_orientation global myCONFIG % create_step_in_source(2500) if nargin==0 close all snapshot_step = 700 h_figure = figure end VRO_result_file = [myCONFIG.PATH.SOURCE_FOLDER,'VRO_result/VRO_result.mat']; PM_result_file = [myCONFIG.PATH.SOURCE_FOLDER,'PM_result/VRO_result.mat']; nFiles = data_file_counting(myCONFIG.PATH.SOURCE_FOLDER,'d1')-1; if ~exist(VRO_result_file,'file') [xx,varargout] = Test_RANSAC_dead_reckoning_dr_ye(1,nFiles) save(VRO_result_file,'xx') else load(VRO_result_file) end if ~exist(PM_result_file,'file') i=5; while (i)<nFiles [x_k_k,p_k_k,dT1,dq1,q_expected] = read_snapshot(i); trajectory(:,i) = x_k_k; cov_info(:,:,i) = p_k_k; i = i+1 end save(PM_result_file,'trajectory','cov_info'); else load(PM_result_file) end % % % % % % % % % % figure;plot3(trajectory(1,4:snapshot_step-1),... % % % % % % % % % % trajectory(2,4:snapshot_step-1),... % % % % % % % % % % trajectory(3,4:snapshot_step-1),'b') % % % % % % % % % % hold on; % % % % % % % % % % plot3(xx(1,4:snapshot_step-1),... % % % % % % % % % % xx(2,4:snapshot_step-1),... % % % % % % % % % % xx(3,4:snapshot_step-1),'r') % % % % % % % % % % axis equal % % % % % % % % % % grid on % % % % % % % % % % legend('proposed method','VRO') % % % % % % % % % % figure(h_figure) % draw_camera( [trajectory(1:3,snapshot_step); trajectory(4:7,snapshot_step)], 'r' );hold on; % draw_camera( [xx(1:3,snapshot_step); xx(4:7,snapshot_step)], 'b' ); % % % % % % % % % draw_camera( [[0;0;0]; trajectory(4:7,snapshot_step-1)], 'b' );hold on; % % % % % % % % % draw_camera( [[0;0;0]; xx(4:7,snapshot_step-1)], 'r' ); % draw_camera( [[0;0;0]; [1;0;0;0]], 'g' ); % % % % % % % % % % axis equal % % % % % % % % % % grid on % legend('a','b') % % % % % % % % % % legend('PM','VRO') % first plane R_PM = q2r(trajectory(4:7,snapshot_step-1)); p1_1 = [0 0 0];p2_1= [1 0 0];p3_1= [0 0 1]; [ a_0, b_0, c_0, d_0 ] = plane_exp2imp_3d ( p1_1, p2_1, p3_1 ); %%% normalize the representation norm1 = norm([a_0,b_0,c_0]); a_0 = a_0/norm1; b_0 = b_0/norm1; c_0 = c_0/norm1; d_0 = d_0/norm1; f1 = R_PM(1,3); g1 = R_PM(2,3); h1 = R_PM(3,3); angle1 = planes_imp_angle_line_3d ( a_0, b_0, c_0, d_0, f1, g1, h1 )*(180/pi); %%% R_VRO = q2r(xx(4:7,snapshot_step-1)); f2 = R_VRO(1,3); g2 = R_VRO(2,3); h2 = R_VRO(3,3); angle2 = planes_imp_angle_line_3d ( a_0, b_0, c_0, d_0, f2, g2, h2 )*(180/pi); [R_PF,T_PF] = plane_fit_to_data_save(snapshot_step); R_PF = R_PF'; f3 = R_PF(1,3); g3 = R_PF(2,3); h3 = R_PF(3,3); OUTPUT=SpinCalc('DCMtoEA231',R_PM,0.01,1); temp = (180/pi)*normilize_angle_(OUTPUT*(pi/180)) R_compensate = e2r([0 OUTPUT(1)*pi/180 0]); angle3 = planes_imp_angle_line_3d ( a_0, b_0, c_0, d_0, f3, g3, h3 )*(180/pi); % % % % % % % % % % drawSpan(R_compensate'*R_PF(:,[1,3]), 'g'); disp('-------------') disp(['proposed method = ',num2str(angle1)]) disp(['VRO = ',num2str(angle2)]) disp(['Plane fitting = ',num2str(angle3)]) % OUTPUT=SpinCalc('DCMtoEA123',R_VRO,0.01,1) % OUTPUT=SpinCalc('DCMtoEA231',R_VRO,0.01,1) % OUTPUT=SpinCalc('DCMtoEA213',R_VRO,0.01,1) % OUTPUT=SpinCalc('DCMtoEA321',R_VRO,0.01,1) end function p = normilize_angle_(p) for i=1:length(p) if p(i)>pi p(i) = p(i) - 2*pi; end end end % [cov_pose_shift,q_dpose,T_pose] = bootstrap_cov_calc(100,103); % [d_euler,E] = q2eG(q_dpose,cov_pose_shift(4:7,4:7)); % euler_cov = (sqrt(diag(E))*180/pi); % t_cov = sqrt(diag(cov_pose_shift(1:3,1:3))); % disp((180/pi)*d_euler') % disp(euler_cov') % % disp(T_pose') % disp(t_cov') % close all;test_the_effect_of_orinetation(120,figure)
github
rising-turtle/slam_matlab-master
scrollplot.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/scrollplot.m
59,195
utf_8
224671d57c562973a15b560590589614
function scrollHandles = scrollplot(varargin) %SCROLLPLOT add scroll sub-window to the supplied plot handle % % scrollplot adds a scroll sub-window to any supplied plot handle(s). % The user may specify initial view window parameters or use defaults. % Dragging the side-bars or central patch modifies the respective parent % axes limits interactively. Conversely, modifying the parent axes % limits (with zoom, pan or programatically) modifies the corresponding % scroll patch(es) accordingly. Works ok with log and reverse axes. % Both X & Y scrolling are possible. % % Syntax: % scrollHandles = scrollplot(plotHandles, propName,propValue,...) % % scrollplot(plotHandles) adds a scroll sub-window to the supplied % plotHandles using default property values (see below). % plotHandles may be any combination of axes and line/data handles. % If plotHandles is not supplied then the current axes (<a href="matlab:help gca">gca</a>) is used. % % scrollplot(..., propName,propValue, ...) sets the property value(s) % for the initial scroll view window. Property specification order does % not matter. The following properties are supported (case-insensitive): % - 'Axis' : string (default = 'X'; accepted values: 'X','Y','XY') % - 'Min' : number (default = minimal value of actual plot data) % sets the same value for both 'MinX' & 'MinY' % - 'Max' : number (default = maximal value of actual plot data) % sets the same value for both 'MaxX' & 'MaxY' % - 'MinX','MinY': number (same as 'Min', but only for X or Y axis) % - 'MaxX','MaxY': number (same as 'Max', but only for X or Y axis) % - 'WindowSize' : number (default = entire range of actual plot data) % sets the same value for 'WindowSizeX' & 'WindowSizeY' % - 'WindowSizeX': number (same as 'WindowSize' but only for X axis) % - 'WindowSizeY': number (same as 'WindowSize' but only for Y axis) % % scrollHandles = scrollplot(...) returns handle(s) to the scroll axes. % The returned handles are regular axes with a few additional read-only % properties: % - 'ScrollSideBarHandles' - array of 2 handles to the scroll side-bars % - 'ScrollPatchHandle' - handle to the central scroll patch % - 'ScrollAxesHandle' - handle to the scroll axes =double(scrollHandles) % - 'ParentAxesHandle' - handle to the parent axes % - 'ScrollMin' - number % - 'ScrollMax' - number % % Examples: % scrollplot; % add scroll sub-window to the current axes (gca) % scrollplot(plot(xdata,ydata), 'WindowSize',50); % plot with initial zoom % scrollplot('Min',20, 'windowsize',70); % add x-scroll to current axes % scrollplot([h1,h2], 'axis','xy'); % scroll both X&Y of 2 plot axes % scrollplot('axis','xy', 'minx',20, 'miny',10); % separate scroll minima % % Notes: % 1. Matlab 5: scrollplot might NOT work on Matlab versions earlier than 6 (R12) % 2. Matlab 6: scrollplot is not interactive in zoom mode (ok in Matlab 7+) % 3. Matlab 6: warnings are disabled as a side-effect (not in Matlab 7+) % 4. scrollplot modifies the figure's WindowButtonMotionFcn callback % 5. scrollplot works on 3D plots, but only X & Y axis are scrollable % % Warning: % This code relies in [small] part on undocumented and unsupported % Matlab functionality. It works on Matlab 6+, but use at your own risk! % % Bugs and suggestions: % Please send to Yair Altman (altmany at gmail dot com) % % Change log: % 2007-Jun-14: Enabled image exploration per suggestion by Joe Lotz; improved log axis-scaling behavior per suggestion by Fredric Moisy; added scroll visibility & deletion handlers; fixed minor error handling bug % 2007-May-15: Added 'MinX' etc. params; clarified error msgs; added 'ParentAxesHandle' special prop; fixed 'xy' bugs % 2007-May-14: Set focus on parent axes after scroll-axes creation; added special scroll props; allowed 'Axis'='xy' % 2007-May-13: First version posted on MathWorks file exchange: <a href="http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14984">http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14984</a> % % See also: % plot, gca % Programming notes: % 1. Listeners are set on parent axes's properties so that whenever % any of them (xlim,ylim,parent,units,position) is modified, then % so are the corresponding scroll axes properties. % 2. To bypass the mode managers' (zoom, pan, ...) "hijack" of the % WindowButtonUpFcn callback, we use the non-supported JavaFrame's % AxisComponent MouseReleasedCallback: this doesn't work in Matlab 6 % so scrollplot is non-interactive in Matlab 6 during zoom mode. % 3. To bypass the mode managers over the scroll axes (to ignore zoom/ % pan), we use the little-known 'ButtonDownFilter' mode property. % 4. The special read-only properties in the returned scrollHandles were % added using the undocumented schema.prop interface. Since these % properties are not viewable (only accessible) in the regular axes % handle but only in the handle(scrollHandles), the latter form is % returned. If you need the regular (numeric) form, use either % double(scrollHandles) or the new 'ScrollAxesHandle' read-only prop. % License to use and modify this code is granted freely without warranty to all, as long as the original author is % referenced and attributed as such. The original author maintains the right to be solely associated with this work. % Programmed and Copyright by Yair M. Altman: altmany(at)gmail.com % $Revision: 1.2 $ $Date: 2007/05/15 12:28:27 $ try % Note: on some systems with Matlab 6, an OpenGL warning is displayed due to semi- % transparent scroll patch. This may be safely ignored. Unfortunately, specific warning % disabling was not yet available in Matlab 6 so we must turn off all warnings... v = version; if v(1)<='6' warning off; %#ok for Matlab 6 compatibility else % Temporarily turn off log-axis warnings oldWarn = warning('off','MATLAB:Axes:NegativeDataInLogAxis'); end % Args check [plotHandles, pvPairs] = parseparams(varargin); if iscell(plotHandles) plotHandles = [plotHandles{:}]; % cell2mat is not supported on old Matlab versions... end if isempty(plotHandles) plotHandles = gca; else plotHandles = plotHandles(:); % ensure 1-D array of handles end % Ensure that all supplied handles are valid HG handles if isempty(plotHandles) | ~all(ishandle(plotHandles)) %#ok for Matlab 6 compatibility (note that Matlab 6 did not have ishghandle()) myError('YMA:scrollplot:invalidHandle','invalid plot handle(s) passed to scrollplot'); end % Get the list of axes handles (supplied handles may be axes or axes children) validHandles = []; try for hIdx = 1 : length(plotHandles) thisHandle = plotHandles(hIdx); if ~strcmpi(get(thisHandle,'type'),'axes') thisHandle = get(thisHandle,'Parent'); % old Matlab versions don't have ancestor()... end if ~strcmpi(get(thisHandle,'type'),'axes') myError('YMA:scrollplot:invalidHandle','invalid plot handle passed to scrollplot - must be an axes or line/data handle'); end validHandles = [validHandles, thisHandle]; %#ok mlint - preallocate end validHandles = unique(validHandles); catch % Probably not a valid axes/line, without a 'type' property (see isprop) myError('YMA:scrollplot:invalidHandle','invalid plot handle(s) passed to scrollplot - must be an axes or line/data handle'); end % Pre-process args necessary for creating the scroll-plots, if supplied [pvPairs, axName] = preProcessArgs(pvPairs); % For each unique axes, add the relevant scroll sub-plot %try scrollplotHandles = handle([]); % Loop over all specified/inferred parent axes for hIdx = 1 : length(validHandles) % Loop over all requested scroll axes (x,y, or x&y) for this parent axes hAx = validHandles(hIdx); for axisIdx = 1 : length(axName) % Add the new scroll plot axes scrollplotHandles(end+1) = addScrollPlot(hAx,axName(axisIdx)); %#ok mlint - preallocate % Process args, if supplied processArgs(pvPairs,scrollplotHandles(end)); end % Set the focus on the parent axes axes(hAx); end %catch % Probably not a valid axes handle %myError('YMA:scrollplot:invalidHandle','invalid plot handle(s) passed to scrollplot - must be an axes or line/data handle'); %end % If return scrollHandles was requested if nargout % Return the list of all scroll handles scrollHandles = scrollplotHandles; end catch v = version; if v(1)<='6' err.message = lasterr; % no lasterror function... else err = lasterror; end try err.message = regexprep(err.message,'Error using ==> [^\n]+\n',''); catch try % Another approach, used in Matlab 6 (where regexprep is unavailable) startIdx = findstr(err.message,'Error using ==> '); stopIdx = findstr(err.message,char(10)); for idx = length(startIdx) : -1 : 1 idx2 = min(find(stopIdx > startIdx(idx))); %#ok ML6 err.message(startIdx(idx):stopIdx(idx2)) = []; end catch % never mind... end end if isempty(findstr(mfilename,err.message)) % Indicate error origin, if not already stated within the error message err.message = [mfilename ': ' err.message]; end if v(1)<='6' while err.message(end)==char(10) err.message(end) = []; % strip excessive Matlab 6 newlines end error(err.message); else rethrow(err); end end % Restore original warnings (if available/possible) try warning(oldWarn); catch % never mind... end %end % scrollplot %#ok for Matlab 6 compatibility %% Set-up a new scroll sub-plot window to the supplied axes handle function hScroll = addScrollPlot(hAx,axName) % Before modifying the original axes position, we must fix the labels (esp. xlabel) hLabel = get(hAx, [axName 'Label']); set(hLabel, 'units','normalized'); % Set a new scroll sub-plot in the bottom 10% of the original axes height axPos = get(hAx,'position'); axVis = get(hAx,'visible'); axUnits = get(hAx,'units'); scaleStr = [axName 'Scale']; dirStr = [axName 'Dir']; limStr = [axName 'Lim']; if strcmpi(axName,'x') newScrollPos = axPos .* [1, 1, 1, 0.10]; newPlotPos = axPos .* [1, 1, 1, 0.80] + [0, 0.20*axPos(4), 0, 0]; specialStr = {'YTick',[]}; colStr = 'YColor'; % =axis line to hide rotation = 0; else % Y scroll newScrollPos = [axPos(1)+axPos(3)*0.85, axPos(2), axPos(3)*0.1, axPos(4)]; newPlotPos = axPos .* [1, 1, 0.80, 1]; specialStr = {'XTick',[], 'YAxisLocation','right'}; colStr = 'XColor'; % =axis line to hide rotation = 90; end hScroll = axes('units',axUnits, 'position',newScrollPos, 'visible',axVis, scaleStr,get(hAx,scaleStr), dirStr,get(hAx,dirStr), 'NextPlot','add', 'Box','off', specialStr{:}, 'FontSize',7, 'Tag','scrollAx', 'UserData',axName, 'DeleteFcn',@deleteScrollAx); GRAY = 0.8 * [1,1,1]; try bgColor = get(get(hAx,'parent'),'Color'); set(hScroll, colStr,bgColor); catch % Maybe the axes is contained in something without a 'Color' property set(hScroll, colStr,GRAY); end %axis(hScroll, 'off'); set(hAx, 'position',newPlotPos); % Store the parent axes in the scroll axes's appdata setappdata(hScroll, 'parent',hAx); % Set the scroll limits & data based on the original axes's data % Note: use any axes child xdata to set the scroll limits, but % ^^^^ only plot line children (not scatter/bar/polar etc) axLines = get(hAx,'children'); %lim = [Inf, -Inf]; lim = get(hAx,limStr); if isinf(lim(1)), lim(1)=+inf; end if isinf(lim(2)), lim(2)=-inf; end for lineIdx = 1 : length(axLines) try hLine = axLines(lineIdx); xdata = get(hLine,'XData'); ydata = get(hLine,'YData'); try name = get(hLine,'DisplayName'); catch % Matlab 6 did not have 'DisplayName' property (used by legend) - never mind... name = ''; end if strcmpi(axName,'x'), data=xdata(1,:); else data=ydata(1,:); end lim = [min(lim(1),min(data)), max(lim(2),max(data))]; linType = get(hLine,'type'); if strcmpi(linType,'line') % Add plot line child if and only if it's a line lineColor = GRAY; %=get(hLine,'color'); %orig color looks bad in scroll axes hLine2 = plot(xdata, ydata, 'Parent',hScroll, 'color',lineColor, 'tag','scrollDataLine', 'HitTest','off'); if ~isempty(name) set(hLine2, 'DisplayName',name); end % 2007-Jun-14: Enabled image exploration per suggestion by Joe Lotz elseif strcmpi(linType,'image') % Add miniature version of the main image hLine2 = image(get(hLine,'CData'), 'Parent',hScroll); %#ok hLine2 used for debug set(hScroll,'YDir','Reverse','XLim',get(hLine,'XData'),'YLim',get(hLine,'YData')); end catch % Probably some axes child without data - skip it... end end if lim(1) > lim(2) curLim = get(hScroll, limStr); if isinf(lim(1)), lim(1) = curLim(1); end if isinf(lim(2)), lim(2) = curLim(2); end end if ~isempty(axLines) & lim(1) < lim(2) %#ok for Matlab 6 compatibility set(hScroll, limStr,lim); end % Get the figure handle hFig = ancestor(hAx,'figure'); % Prevent flicker on axes update set(hFig, 'DoubleBuffer','on'); % Ensure that the axis component has a handle with callbacks % Note: this is determined by the first invocation, so ensure we're the first... axisComponent = getAxisComponent(hFig); %#ok unused % Set the scroll handle-bars xlim = get(hScroll, 'XLim'); ylim = get(hScroll, 'YLim'); hPatch = patch(xlim([1,1,2,2]), ylim([1,2,2,1]), 'b', 'FaceAlpha',.15, 'EdgeColor','w', 'EdgeAlpha',.15, 'ButtonDownFcn',@mouseDownCallback, 'tag','scrollPatch', 'userdata',axName); %Note: FaceAlpha causes an OpenGL warning in Matlab 6 commonProps = {'Parent',hScroll, 'LineWidth',3, 'ButtonDownFcn',@mouseDownCallback, 'tag','scrollBar'}; smallDelta = 0.01 * diff(lim); % don't use eps if strcmpi(axName,'x') hBars(1) = plot(xlim([1,1]), ylim, '-b', commonProps{:}); hBars(2) = plot(xlim([2,2]), ylim, '-b', commonProps{:}); else % Y scroll hBars(1) = plot(xlim, ylim([1,1])+smallDelta, '-b', commonProps{:}); hBars(2) = plot(xlim, ylim([2,2])-smallDelta, '-b', commonProps{:}); end try set(hBars(1), 'DisplayName','Min'); set(hBars(2), 'DisplayName','Max'); catch % Matlab 6 did not have 'DisplayName' property (used by legend) - never mind... end % TODO: maybe add a blue diamond or a visual handle in center of hBars? set(hScroll, limStr,lim+smallDelta*[-1.2,1.2]); % Help messages msg = {'drag blue side-bars to zoom', 'drag central patch to pan'}; xText = getCenterCoord(hScroll, 'x'); yText = getCenterCoord(hScroll, 'y'); hText = text(xText,yText,msg, 'Color','r', 'Rotation',rotation, 'HorizontalAlignment','center', 'FontSize',9, 'FontWeight','bold', 'EraseMode','xor', 'HitTest','off', 'tag','scrollHelp'); %#ok ret val used for debug hMenu = uicontextmenu; set(hScroll, 'UIContextMenu',hMenu); uimenu(hMenu, 'Label',msg{1}, 'Callback',@moveCursor, 'UserData',hBars(2)); uimenu(hMenu, 'Label',msg{2}, 'Callback',@moveCursor, 'UserData',hPatch); % Set the mouse callbacks winFcn = get(hFig,'WindowButtonMotionFcn'); if ~isempty(winFcn) & ~isequal(winFcn,@mouseMoveCallback) & (~iscell(winFcn) | ~isequal(winFcn{1},@mouseMoveCallback)) %#ok for Matlab 6 compatibility setappdata(hFig, 'scrollplot_oldButtonMotionFcn',winFcn); end set(hFig,'WindowButtonMotionFcn',@mouseMoveCallback); % Fix label position(s) oldPos = get(hLabel, 'position'); if strcmpi(axName,'x') if ~isempty(oldPos) & oldPos(2)<0 %#ok for Matlab 6 compatibility % Only fix if the X label is on the bottom (usually yes) set(hLabel, 'position',oldPos-[0,.20/.80,0]); end else % Y scroll if ~isempty(oldPos) & oldPos(1)>0 %#ok for Matlab 6 compatibility % Only fix if the Y label is on the right side (usually not) set(hLabel, 'position',oldPos+[.20/.80,0,0]); end end % Add property listeners listenedPropNames = {'XLim','YLim','XDir','YDir','XScale','YScale','Position','Units','Parent'}; listeners = addPropListeners(hFig, hAx, hScroll, hPatch, hBars, listenedPropNames); setappdata(hScroll, 'scrollplot_listeners',listeners); % These will be destroyed with hScroll so no need to un-listen upon hScroll deletion % Add special properties addSpecialProps(hAx, hScroll, hPatch, hBars, axName); % Convert to handle object, so that the special properties become visible hScroll = handle(hScroll); return; % debug point %end % addScrollPlot %#ok for Matlab 6 compatibility %% Add parent axes listener function listeners = addPropListeners(hFig, hAx, hScroll, hPatch, hBars, propNames) % Listeners on parent axes properties hhAx = handle(hAx); for propIdx = 1 : length(propNames) callback = {@parentAxesChanged, hFig, hAx, hPatch, hBars, propNames{propIdx}}; prop = findprop(hhAx, propNames{propIdx}); listeners(propIdx) = handle.listener(hhAx, prop, 'PropertyPostSet', callback); %#ok mlint - preallocate end % Listeners on scroll axes properties hhScroll = handle(hScroll); prop = findprop(hhScroll, 'Visible'); listeners(end+1) = handle.listener(hhScroll, prop, 'PropertyPostSet', {@updateParentPos,hScroll}); %end % addPropListeners %#ok for Matlab 6 compatibility %% Add special scrollplot properties to the hScroll axes function addSpecialProps(hAx, hScroll, hPatch, hBars, axName) try hhScroll = handle(hScroll); % Read-only props addNewProp(hhScroll,'ParentAxesHandle', hAx,1); addNewProp(hhScroll,'ScrollAxesHandle', double(hScroll),1); addNewProp(hhScroll,'ScrollPatchHandle', hPatch,1); addNewProp(hhScroll,'ScrollSideBarHandles',hBars, 1); % Note: setting the property's GetFunction is much cleaner but doesn't work in Matlab 6... dataStr = [axName,'Data']; addNewProp(hhScroll,'ScrollMin',unique(get(hBars(1),dataStr)),1); %,{@getBarVal,hBars(1),dataStr}); addNewProp(hhScroll,'ScrollMax',unique(get(hBars(2),dataStr)),1); %,{@getBarVal,hBars(2),dataStr}); catch % Never mind... end %end % addSpecialProps %#ok for Matlab 6 compatibility %% Add new property to supplied handle function addNewProp(hndl,propName,initialValue,readOnlyFlag,getFunc,setFunc) sp = schema.prop(hndl,propName,'mxArray'); set(hndl,propName,initialValue); if nargin>3 & ~isempty(readOnlyFlag) & readOnlyFlag %#ok for Matlab 6 compatibility set(sp,'AccessFlags.PublicSet','off'); % default='on' end if nargin>4 & ~isempty(getFunc) %#ok for Matlab 6 compatibility set(sp,'GetFunction',getFunc); % unsupported in Matlab 6 end if nargin>5 & ~isempty(setFunc) %#ok for Matlab 6 compatibility set(sp,'SetFunction',setFunc); % unsupported in Matlab 6 end %end % addNewProp %#ok for Matlab 6 compatibility %% Callback for getting side-bar value function propValue = getBarVal(object,propValue,varargin) %#ok object & propValue are unused propValue = unique(get(varargin{:})); %end % getBarVal %#ok for Matlab 6 compatibility %% Pre-process args necessary for creating the scroll-plots, if supplied function [pvPairs, axName] = preProcessArgs(pvPairs) % Default axes is 'X' axName = 'x'; % Special check for invalid format if ~isempty(pvPairs) & ischar(pvPairs{end}) & any(strcmpi(pvPairs{end},{'axis','axes'})) %#ok for Matlab 6 compatibility myError('YMA:scrollplot:invalidProperty','No data specified for scrollplot property ''Axis'''); end % Loop over all supplied P-V pairs to pre-process the parameters idx = 1; while idx < length(pvPairs) paramName = pvPairs{idx}; if ~ischar(paramName), idx=idx+1; continue; end switch lower(paramName) % Get the last axes requested by the user (if any) % Check for 'axis' or 'axes' ('axes' is a typical typo of 'axis') case {'axis','axes'} axName = pvPairs{idx+1}; % Ensure we got a valid axis name: 'x','y','xy' or 'yx' if ~ischar(axName) | ~any(strcmpi(axName,{'x','y','xy','yx'})) %#ok for Matlab 6 compatibility myError('YMA:scrollplot:invalidProperty','Invalid scrollplot ''Axis'' property value: only ''x'',''y'' & ''xy'' are accepted'); end % Remove from the PV pairs list and move on axName = lower(axName); pvPairs(idx:idx+1) = []; % Placeholder for possible future pre-processed args otherwise % Skip... idx = idx + 1; end end %end % preProcessArgs %#ok for Matlab 6 compatibility %% Process P-V argument pairs function processArgs(pvPairs,hScroll) try minLim = []; maxLim = []; hScroll = double(hScroll); % Matlab 6 could not use findall with handle objects... axName = get(hScroll, 'userdata'); if strcmpi(axName,'x') otherAxName = 'y'; %#ok mlint mistaken warning - used below else % Y scroll otherAxName = 'x'; %#ok mlint mistaken warning - used below end dataStr = [axName 'Data']; limStr = [axName 'Lim']; while ~isempty(pvPairs) % Ensure basic format is valid paramName = ''; if ~ischar(pvPairs{1}) myError('YMA:scrollplot:invalidProperty','Invalid property passed to scrollplot'); elseif length(pvPairs) == 1 myError('YMA:scrollplot:invalidProperty',['No data specified for property ''' pvPairs{1} '''']); end % Process parameter values paramName = pvPairs{1}; paramValue = pvPairs{2}; pvPairs(1:2) = []; hScrollBars = unique(findall(hScroll, 'tag','scrollBar')); hScrollPatches = unique(findall(hScroll, 'tag','scrollPatch')); switch lower(paramName) case {'min',['min' axName]} set(hScrollBars(1:2:end), dataStr,paramValue([1,1])); for patchIdx = 1 : length(hScrollPatches) thisPatch = hScrollPatches(patchIdx); data = get(thisPatch, dataStr); if strcmpi(axName,'x') set(thisPatch, dataStr,[paramValue([1;1]); data([4,4])]); else % Y scroll set(thisPatch, dataStr,[paramValue(1); data([2,2]); paramValue(1)]); end % Update the parent axes with the new limit hAx = getappdata(get(thisPatch,'Parent'), 'parent'); lim = get(hAx, limStr); set(hAx, limStr,[paramValue,lim(2)]); end minLim = paramValue; case {'max',['max' axName]} set(hScrollBars(2:2:end), dataStr,paramValue([1,1])); for patchIdx = 1 : length(hScrollPatches) thisPatch = hScrollPatches(patchIdx); data = get(thisPatch, dataStr); if strcmpi(axName,'x') set(thisPatch, dataStr,[data([1,1]); paramValue([1;1])]); else % Y scroll set(thisPatch, dataStr,[data(1); paramValue([1;1]); data(1)]); end % Update the parent axes with the new limit hAx = getappdata(get(thisPatch,'Parent'), 'parent'); lim = get(hAx, limStr); set(hAx, limStr,[lim(1),paramValue]); end maxLim = paramValue; case {'windowsize',['windowsize' axName]} if isempty(pvPairs) % No min,max after this param, so act based on data so far if ~isempty(minLim) if ~isempty(maxLim) & abs(maxLim-minLim-paramValue(1))>eps %#ok for Matlab 6 compatibility myError('YMA:scrollplot:invalidWindowSize','Specified WindowSize value conflicts with earlier values specified for Min,Max'); end pvPairs = {'Max', minLim+paramValue(1), pvPairs{:}}; % note: can't do [...,pvPairs] because of a Matlab6 bug when pvPairs={} elseif ~isempty(maxLim) % Only max was specified... pvPairs = {'Min', maxLim-paramValue(1), pvPairs{:}}; else % No min,max: act based on actual min for each axes seperately for scrollIdx = 1 : length(hScroll) % Update the right side bar thisScroll = hScroll(scrollIdx); hScrollBars = unique(findall(thisScroll, 'tag','scrollBar')); maxLim = get(hScrollBars(1), dataStr) + paramValue(1); set(hScrollBars(2), dataStr,maxLim); % Now update the patch thisPatch = unique(findall(thisScroll, 'tag','scrollPatch')); data = get(thisPatch, dataStr); if strcmpi(axName,'x') set(thisPatch, dataStr,[data([1,1]); maxLim']); else % Y scroll set(thisPatch, dataStr,[data(1); maxLim'; data(1)]); end % Finally, update the parent axes with the new limit hAx = getappdata(thisScroll, 'parent'); lim = get(hAx, limStr); set(hAx, limStr,[lim(1),maxLim(1)]); end end else % Push this P-V pair to the end of the params list (after min,max) pvPairs = {pvPairs{:}, paramName, paramValue(1)}; end % Not a good idea to let users play with position so easily... %case 'position' % set(hScroll, 'position',paramValue); case {'axis','axes'} % Do nothing (should never get here: should have been stripped by preProcessArgs()!) case {['min' otherAxName], ['max' otherAxName], ['windowsize' otherAxName]} % Do nothing (pass to other axes for processing) otherwise myError('YMA:scrollplot:invalidProperty','Unsupported property'); end % switch paramName end % loop pvPairs catch if ~isempty(paramName), paramName = [' ''' paramName '''']; end myError('YMA:scrollplot:invalidHandle',['Error setting scrollplot property' paramName ':' char(10) lasterr]); end %end % processArgs %#ok for Matlab 6 compatibility %% Internal error processing function myError(id,msg) v = version; if (v(1) >= '7') error(id,msg); else % Old Matlab versions do not have the error(id,msg) syntax... error(msg); end %end % myError %#ok for Matlab 6 compatibility %% Get ancestor figure - used for old Matlab versions that don't have a built-in ancestor() function hObj = ancestor(hObj,type) if ~isempty(hObj) & ishandle(hObj) %#ok for Matlab 6 compatibility %if ~isa(handle(hObj),type) % this is best but always returns 0 in Matlab 6! if ~strcmpi(get(hObj,'type'),type) hObj = ancestor(get(handle(hObj),'parent'),type); end end %end % ancestor %#ok for Matlab 6 compatibility %% Helper function to extract first data value(s) from an array function data = getFirstVals(vals) if isempty(vals) data = []; elseif iscell(vals) for idx = 1 : length(vals) thisVal = vals{idx}; data(idx) = thisVal(1); %#ok mlint - preallocate end else data = vals(:,1); end %end % getFirstVal %#ok for Matlab 6 compatibility %% Mouse movement outside the scroll patch area function mouseOutsidePatch(hFig,inDragMode,hAx) %#ok Hax is unused try % Restore the original figure pointer (probably 'arrow', but not necessarily) % On second thought, it should always be 'arrow' since zoom/pan etc. are disabled within hScroll %if ~isempty(hAx) % Only modify this within hScroll (outside the patch area) - not in other axes set(hFig, 'Pointer','arrow'); %end oldPointer = getappdata(hFig, 'scrollplot_oldPointer'); if ~isempty(oldPointer) %set(hFig, oldPointer{:}); % see comment above drawnow; rmappdataIfExists(hFig, 'scrollplot_oldPointer'); if isappdata(hFig, 'scrollplot_mouseUpPointer') setappdata(hFig, 'scrollplot_mouseUpPointer',oldPointer); end end % Restore the original ButtonUpFcn callback if isappdata(hFig, 'scrollplot_oldButtonUpFcn') oldButtonUpFcn = getappdata(hFig, 'scrollplot_oldButtonUpFcn'); axisComponent = getappdata(hFig, 'scrollplot_oldButtonUpObj'); if ~isempty(axisComponent) set(axisComponent, 'MouseReleasedCallback',oldButtonUpFcn); else set(hFig, 'WindowButtonUpFcn',oldButtonUpFcn); end rmappdataIfExists(hFig, 'scrollplot_oldButtonUpFcn'); end % Additional cleanup rmappdataIfExists(hFig, 'scrollplot_mouseDownPointer'); if ~inDragMode rmappdataIfExists(hFig, 'scrollplot_originalX'); rmappdataIfExists(hFig, 'scrollplot_originalLimits'); end catch % never mind... disp(lasterr); end %end % outsideScrollCleanup %#ok for Matlab 6 compatibility %% Mouse movement within the scroll patch area function mouseWithinPatch(hFig,inDragMode,hAx,scrollPatch,cx,isOverBar) try % Separate actions for X,Y scrolling axName = get(hAx, 'userdata'); if strcmpi(axName,'x') shapeStr = 'lrdrag'; else shapeStr = 'uddrag'; end dataStr = [axName 'Data']; limStr = [axName 'Lim']; % If we have entered the scroll patch area for the first time axisComponent = getAxisComponent(hFig); if ~isempty(axisComponent) winUpFcn = get(axisComponent,'MouseReleasedCallback'); else winUpFcn = get(hFig,'WindowButtonUpFcn'); end if isempty(winUpFcn) | (~isequal(winUpFcn,@mouseUpCallback) & (~iscell(winUpFcn) | ~isequal(winUpFcn{1},@mouseUpCallback))) %#ok for Matlab 6 compatibility % Set the ButtonUpFcn callbacks if ~isempty(winUpFcn) setappdata(hFig, 'scrollplot_oldButtonUpFcn',winUpFcn); setappdata(hFig, 'scrollplot_oldButtonUpObj',axisComponent); end if ~isempty(axisComponent) set(axisComponent, 'MouseReleasedCallback',{@mouseUpCallback,hFig}); else set(hFig, 'WindowButtonUpFcn',@mouseUpCallback); end % Clear up potential junk that might confuse us later rmappdataIfExists(hFig, 'scrollplot_clickedBarIdx'); end % If this is a drag movement (i.e., mouse button is clicked) if inDragMode % Act according to the dragged object if isempty(scrollPatch) scrollPatch = findobj(hAx, 'tag','scrollPatch'); end scrollBarIdx = getappdata(hFig, 'scrollplot_clickedBarIdx'); scrollBars = sort(findobj(hAx, 'tag','scrollBar')); %barsXs = cellfun(@(c)c(1),get(scrollBars,dataStr)); % cellfun is very limited on Matlab 6... barsXs = getFirstVals(get(scrollBars,dataStr)); if barsXs(1)>barsXs(2) % happens after dragging one bar beyond the other scrollBarIdx = 3 - scrollBarIdx; % []=>[], 1=>2, 2=>1 scrollBars = scrollBars([2,1]); end oldPatchXs = get(scrollPatch, dataStr); axLimits = get(hAx, limStr); cx = min(max(cx,axLimits(1)),axLimits(2)); if isempty(scrollBarIdx) % patch drag originalX = getappdata(hFig, 'scrollplot_originalX'); originalLimits = getappdata(hFig, 'scrollplot_originalLimits'); if ~isempty(originalLimits) allowedDelta = [min(0,axLimits(1)-originalLimits(1)), max(0,axLimits(2)-originalLimits(2))]; deltaX = min(max(cx-originalX, allowedDelta(1)), allowedDelta(2)); if strcmpi(get(hAx,[axName 'Scale']), 'log') newLimits = 10.^(log10(originalLimits) + deltaX); else % linear axis scale newLimits = originalLimits + deltaX; end %fprintf('%.3f ',[cx-originalX, deltaX, originalLimits(1), newLimits(1), allowedDelta]) %fprintf('\n'); if strcmpi(axName,'x') set(scrollPatch, dataStr,newLimits([1,1,2,2])); else set(scrollPatch, dataStr,newLimits([1,2,2,1])); end set(scrollBars(1), dataStr,newLimits([1,1])); set(scrollBars(2), dataStr,newLimits([2,2])); setappdata(hFig, 'scrollplot_originalLimits', newLimits); setappdata(hFig, 'scrollplot_originalX', cx); if deltaX ~= 0 delete(findall(0,'tag','scrollHelp')); end end elseif (scrollBarIdx == 1) % left/bottom bar drag set(scrollBars(scrollBarIdx), dataStr,[cx,cx]); if strcmpi(axName,'x') set(scrollPatch, dataStr,[cx,cx, max(oldPatchXs)*[1,1]]); else set(scrollPatch, dataStr,[cx, max(oldPatchXs)*[1,1], cx]); end delete(findall(0,'tag','scrollHelp')); else % right/top bar drag set(scrollBars(scrollBarIdx), dataStr,[cx,cx]); if strcmpi(axName,'x') set(scrollPatch, dataStr,[min(oldPatchXs)*[1,1], cx,cx]); else set(scrollPatch, dataStr,[cx, min(oldPatchXs)*[1,1], cx]); end delete(findall(0,'tag','scrollHelp')); end % Modify the parent axes accordingly parentAx = getappdata(hAx, 'parent'); newXLim = unique(get(scrollPatch,dataStr)); if length(newXLim) == 2 % might be otherwise if bars merge! set(parentAx, limStr,newXLim); end % Mode managers (zoom/pan etc.) modify the cursor shape, so we need to force ours... newPtr = getappdata(hFig, 'scrollplot_mouseDownPointer'); if ~isempty(newPtr) setptr(hFig, newPtr); end else % Normal mouse movement (no drag) % Modify the cursor shape oldPointer = getappdata(hFig, 'scrollplot_oldPointer'); if isempty(oldPointer) % Preserve original pointer shape for future use setappdata(hFig, 'scrollplot_oldPointer',getptr(hFig)); end if isOverBar setptr(hFig, shapeStr); setappdata(hFig, 'scrollplot_mouseDownPointer',shapeStr); else setptr(hFig, 'hand'); setappdata(hFig, 'scrollplot_mouseDownPointer','closedhand'); end end drawnow; catch % never mind... disp(lasterr); end %end % mouseWithinPatch %#ok for Matlab 6 compatibility %% Mouse movement callback function function mouseMoveCallback(varargin) try try % Temporarily turn off log-axis warnings oldWarn = warning('off','MATLAB:Axes:NegativeDataInLogAxis'); catch % never mind... end % Get the figure's current axes hFig = gcbf; if isempty(hFig) | ~ishandle(hFig), return; end %#ok just in case.. %hAx = get(hFig,'currentAxes'); hAx = getCurrentScrollAx(hFig); inDragMode = isappdata(hFig, 'scrollplot_clickedBarIdx'); % Exit if already in progress - don't want to mess everything... if isappdata(hFig,'scrollBar_inProgress'), return; end % Fix case of Mode Managers (pan, zoom, ...) try modeMgr = get(hFig,'ModeManager'); hMode = modeMgr.CurrentMode; set(hMode,'ButtonDownFilter',@shouldModeBeInactiveFcn); catch % Never mind - either an old Matlab (no mode managers) or no mode currently active end % If mouse pointer is not currently over any scroll axes if isempty(hAx) %& ~inDragMode %#ok for Matlab 6 compatibility % Perform cleanup mouseOutsidePatch(hFig,inDragMode,hAx); else % Check whether the curser is over any side bar scrollPatch = findobj(hAx, 'tag','scrollPatch'); isOverBar = 0; cx = []; if ~isempty(scrollPatch) scrollPatch = scrollPatch(1); axName = get(hAx,'userdata'); cp = get(hAx,'CurrentPoint'); cx = cp(1,1); cy = cp(1,2); xlim = get(hAx,'Xlim'); ylim = get(hAx,'Ylim'); limits = get(hAx,[axName 'Lim']); barXs = unique(get(scrollPatch,[axName 'Data'])); if strcmpi(get(hAx,[axName 'Scale']), 'log') fuzz = 0.01 * diff(log(abs(limits))); % tolerances (1%) in axes units barXs = log10(barXs); if strcmpi(axName,'x') cx = log10(cx); else cy = log10(cy); end else fuzz = 0.01 * diff(limits); % tolerances (1%) in axes units end if isempty(barXs), return; end %disp(abs(cy-barXs)') if strcmpi(axName,'x') inXTest = any(barXs-fuzz < cx) & any(cx < barXs+fuzz); inYTest = (ylim(1) < cy) & (cy < ylim(2)); isOverBar = any(abs(cx-barXs)<fuzz); %(barXs-fuzz < cx) & (cx < barXs+fuzz)); else % Y scroll inXTest = (xlim(1) < cx) & (cx < xlim(2)); inYTest = any(barXs-fuzz < cy) & any(cy < barXs+fuzz); isOverBar = any(abs(cy-barXs)<fuzz); %(barXs-fuzz < cy) & (cy < barXs+fuzz)); cx = cy; % for use in mouseWithinPatch below end scrollPatch = scrollPatch(inXTest & inYTest); if strcmpi(get(hAx,[axName 'Scale']), 'log') cx = 10^cx; % used below end end % From this moment on, don't allow any interruptions setappdata(hFig,'scrollBar_inProgress',1); % If we're within the scroll patch area if ~isempty(scrollPatch) | inDragMode %#ok for Matlab 6 compatibility mouseWithinPatch(hFig,inDragMode,hAx,scrollPatch,cx,isOverBar); else % Perform cleanup mouseOutsidePatch(hFig,inDragMode,hAx); end end % Try to chain the original WindowButtonMotionFcn (if available) try hgfeval(getappdata(hFig, 'scrollplot_oldButtonMotionFcn')); catch % Never mind... end catch % Never mind... disp(lasterr); end rmappdataIfExists(hFig,'scrollBar_inProgress'); % Restore original warnings (if available/possible) try warning(oldWarn); catch % never mind... end %end % mouseMoveCallback %#ok for Matlab 6 compatibility %% Mouse click down callback function function mouseDownCallback(varargin) try % Modify the cursor shape (close hand) hFig = gcbf; %varargin{3}; if isempty(hFig) & ~isempty(varargin) %#ok for Matlab 6 compatibility hFig = ancestor(varargin{1},'figure'); end if isempty(hFig) | ~ishandle(hFig), return; end %#ok just in case.. setappdata(hFig, 'scrollplot_mouseUpPointer',getptr(hFig)); newPtr = getappdata(hFig, 'scrollplot_mouseDownPointer'); if ~isempty(newPtr) setptr(hFig, newPtr); end % Determine the clicked object: patch, left bar or right bar hAx = get(hFig,'currentAxes'); if isempty(hAx), return; end axName = get(hAx,'userdata'); limits = get(hAx,[axName 'Lim']); cp = get(hAx,'CurrentPoint'); % Check whether the curser is over any side bar barXs = [-inf,inf]; scrollBarIdx = []; scrollPatch = findobj(hAx, 'tag','scrollPatch'); if ~isempty(scrollPatch) scrollPatch = scrollPatch(1); dataStr = [axName 'Data']; barXs = unique(get(scrollPatch,dataStr)); if isempty(barXs), return; end if strcmpi(axName,'x') cx = cp(1,1); else % Y scroll cx = cp(1,2); % actually, this gets the y value... end if strcmpi(get(hAx,[axName 'Scale']), 'log') fuzz = 0.01 * diff(log(abs(limits))); % tolerances (1%) in axes units barXs = log10(barXs); cx = log10(cx); else fuzz = 0.01 * diff(limits); % tolerances (1%) in axes units end inTest = abs(cx-barXs)<fuzz; %(barXs-fuzz < cx) & (cx < barXs+fuzz); scrollBarIdx = find(inTest); scrollBarIdx = scrollBarIdx(min(1:end)); %#ok - find(x,1) is unsupported on Matlab 6! if strcmpi(get(hAx,[axName 'Scale']), 'log') cx = 10^cx; % used below barXs = 10.^barXs; % used below end % Re-sort side bars (might have been dragged one over the other...) scrollBars = sort(findobj(hAx, 'tag','scrollBar')); %barsXs = cellfun(@(c)c(1),get(scrollBars,'xdata')); % cellfun is very limited on Matlab 6... barsXs = getFirstVals(get(scrollBars,dataStr)); if barsXs(1)>barsXs(2) % happens after dragging one bar beyond the other set(scrollBars(1), dataStr,barsXs(2)*[1,1]); set(scrollBars(2), dataStr,barsXs(1)*[1,1]); end end setappdata(hFig, 'scrollplot_clickedBarIdx',scrollBarIdx); setappdata(hFig, 'scrollplot_originalX',cx); setappdata(hFig, 'scrollplot_originalLimits',barXs); catch % Never mind... disp(lasterr); end %end % mouseDownCallback %#ok for Matlab 6 compatibility %% Mouse click up callback function function mouseUpCallback(varargin) try % Restore the previous (pre-click) cursor shape hFig = gcbf; %varargin{3}; if isempty(hFig) & ~isempty(varargin) %#ok for Matlab 6 compatibility hFig = varargin{3}; if isempty(hFig) hFig = ancestor(varargin{1},'figure'); end end if isempty(hFig) | ~ishandle(hFig), return; end %#ok just in case.. if isappdata(hFig, 'scrollplot_mouseUpPointer') mouseUpPointer = getappdata(hFig, 'scrollplot_mouseUpPointer'); set(hFig,mouseUpPointer{:}); rmappdata(hFig, 'scrollplot_mouseUpPointer'); end % Cleanup data no longer needed rmappdataIfExists(hFig, 'scrollplot_clickedBarIdx'); rmappdataIfExists(hFig, 'scrollplot_originalX'); rmappdataIfExists(hFig, 'scrollplot_originalLimits'); % Try to chain the original WindowButtonUpFcn (if available) oldFcn = getappdata(hFig, 'scrollplot_oldButtonUpFcn'); if ~isempty(oldFcn) & ~isequal(oldFcn,@mouseUpCallback) & (~iscell(oldFcn) | ~isequal(oldFcn{1},@mouseUpCallback)) %#ok for Matlab 6 compatibility hgfeval(oldFcn); end catch % Never mind... disp(lasterr); end %end % mouseUpCallback %#ok for Matlab 6 compatibility %% Remove appdata if available function rmappdataIfExists(handle, name) if isappdata(handle, name) rmappdata(handle, name) end %end % rmappdataIfExists %#ok for Matlab 6 compatibility %% Get the figure's java axis component function axisComponent = getAxisComponent(hFig) try if isappdata(hFig, 'scrollplot_axisComponent') axisComponent = getappdata(hFig, 'scrollplot_axisComponent'); else axisComponent = []; javaFrame = get(hFig,'JavaFrame'); axisComponent = get(javaFrame,'AxisComponent'); axisComponent = handle(axisComponent, 'CallbackProperties'); if ~isprop(axisComponent,'MouseReleasedCallback') axisComponent = []; % wrong axisComponent... else setappdata(hFig, 'scrollplot_axisComponent',axisComponent); end end catch % never mind... end %end % getAxisComponent %#ok for Matlab 6 compatibility %% Get the scroll axes that the mouse is currently over function hAx = getCurrentScrollAx(hFig) try hAx = []; scrollAxes = findall(hFig, 'tag','scrollAx'); if isempty(scrollAxes), return; end % should never happen... for axIdx = 1 : length(scrollAxes) scrollPos(axIdx,:) = getPixelPos(scrollAxes(axIdx)); %#ok mlint - preallocate end cp = get(hFig, 'CurrentPoint'); % in Matlab pixels inXTest = (scrollPos(:,1) <= cp(1)) & (cp(1) <= scrollPos(:,1)+scrollPos(:,3)); inYTest = (scrollPos(:,2) <= cp(2)) & (cp(2) <= scrollPos(:,2)+scrollPos(:,4)); hAx = scrollAxes(inXTest & inYTest); hAx = hAx(min(1:end)); % ensure we return no more than asingle hAx! catch % never mind... disp(lasterr); end %end % getCurrentScrollAx %#ok for Matlab 6 compatibility %% Get pixel position of an HG object function pos = getPixelPos(hObj) try % getpixelposition is unvectorized unfortunately! pos = getpixelposition(hObj); catch % Matlab 6 did not have getpixelposition nor hgconvertunits so use the old way... pos = getPos(hObj,'pixels'); end %end % getPixelPos %#ok for Matlab 6 compatibility %% Get position of an HG object in specified units function pos = getPos(hObj,units) % Matlab 6 did not have hgconvertunits so use the old way... oldUnits = get(hObj,'units'); if strcmpi(oldUnits,units) % don't modify units unless we must! pos = get(hObj,'pos'); else set(hObj,'units',units); pos = get(hObj,'pos'); set(hObj,'units',oldUnits); end %end % getPos %#ok for Matlab 6 compatibility %% Temporary setting property value for a read-only property function setOnce(hndl,propName,propValue) try prop = findprop(hndl,propName); oldSetState = get(prop,'AccessFlags.PublicSet'); set(prop,'AccessFlags.PublicSet','on'); set(hndl,propName,propValue); set(prop,'AccessFlags.PublicSet',oldSetState); catch % Never mind... end %end % setOnce %#ok for Matlab 6 compatibility %% Callback for parent axes property changes function parentAxesChanged(schemaProp, eventData, hFig, hAx, hScrollPatch, hScrollBars, propName) %#ok - first 2 are unused try if isempty(hFig) | ~ishandle(hFig), return; end %#ok just in case.. newPropVal = get(hAx,propName); hScroll = get(hScrollPatch, 'Parent'); axName = get(hScroll, 'userdata'); if isappdata(hFig,'scrollBar_inProgress') % Update the special prop values if strcmpi(propName,[axName,'Lim']) setOnce(handle(hScroll),'ScrollMin',newPropVal(1)); setOnce(handle(hScroll),'ScrollMax',newPropVal(2)); end return; end switch propName case 'XLim' if strcmpi(axName,'x') set(hScrollPatch, 'XData',newPropVal([1,1,2,2])); set(hScrollBars(1), 'Xdata',newPropVal([1,1])); set(hScrollBars(2), 'Xdata',newPropVal([2,2])); setOnce(handle(hScroll),'ScrollMin',newPropVal(1)); setOnce(handle(hScroll),'ScrollMax',newPropVal(2)); end case 'YLim' if strcmpi(axName,'y') set(hScrollPatch, 'YData',newPropVal([1,2,2,1])); set(hScrollBars(1), 'Ydata',newPropVal([1,1])); set(hScrollBars(2), 'Ydata',newPropVal([2,2])); setOnce(handle(hScroll),'ScrollMin',newPropVal(1)); setOnce(handle(hScroll),'ScrollMax',newPropVal(2)); end case 'Position' if strcmpi(axName,'x') newScrollPos = newPropVal .* [1, 1, 1, 0.10/0.80]; newScrollPos = newScrollPos - [0, 0.20/0.80*newPropVal(4), 0, 0]; else % Y scroll newScrollPos = newPropVal .* [1, 1, 0.10/0.80, 1]; newScrollPos = newScrollPos + [(1+0.05/0.80)*newPropVal(3), 0, 0, 0]; end axUnits = get(hAx, 'Units'); % units might be modified by Mode Managers bypassing listeners! set(hScroll, 'Units',axUnits, 'Position',newScrollPos); case {'Units','Parent','XDir','YDir','XScale','YScale'} set(hScroll, propName,newPropVal); otherwise % Do nothing... end catch % never mind... disp(lasterr); end %end % parentAxesChanged %#ok for Matlab 6 compatibility %% Determine whether a current mode manager should be active or not (filtered) function shouldModeBeInactive = shouldModeBeInactiveFcn(hObj, eventData) %#ok - eventData is unused try shouldModeBeInactive = 0; hFig = ancestor(hObj,'figure'); hScrollAx = getCurrentScrollAx(hFig); shouldModeBeInactive = ~isempty(hScrollAx); catch % never mind... disp(lasterr); end %end % shouldModeBeActiveFcn %#ok for Matlab 6 compatibility %% hgfeval replacement for Matlab 6 compatibility function hgfeval(fcn,varargin) if isempty(fcn), return; end if iscell(fcn) feval(fcn{1},varargin{:},fcn{2:end}); elseif ischar(fcn) evalin('base', fcn); else feval(fcn,varargin{:}); end %end % hgfeval %#ok for Matlab 6 compatibility %% Axis to screen coordinate transformation function T = axis2Screen(ax) % computes a coordinate transformation T = [xo,yo,rx,ry] that % relates the normalized axes coordinates [xa,ya] of point [xo,yo] % to its screen coordinate [xs,ys] (in the root units) by: % xs = xo + rx * xa % ys = yo + ry * ya % % See also SISOTOOL % % Note: this is a modified internal function within moveptr() % Get axes normalized position in figure T = getPos(ax,'normalized'); % Loop all the way up the hierarchy to the root % Note: this fixes a bug in Matlab 7's moveptr implementation parent = get(ax,'Parent'); while ~isempty(parent) % Transform norm. axis coord -> parent coord. if isequal(parent,0) parentPos = get(0,'ScreenSize'); % Preserve screen units else parentPos = getPos(parent, 'normalized'); % Normalized units end T(1:2) = parentPos(1:2) + parentPos(3:4) .* T(1:2); T(3:4) = parentPos(3:4) .* T(3:4); parent = get(parent,'Parent'); end %end % axis2Screen %#ok for Matlab 6 compatibility %% Get centran axis location function axisCoord = getCenterCoord(hAx, axName) limits = get(hAx, [axName 'Lim']); if strcmpi(get(hAx,[axName 'Scale']), 'log') axisCoord = sqrt(abs(prod(limits))); %=10^mean(log10(abs(limits))); else axisCoord = mean(limits); end %end %getCenterCoord %#ok for Matlab 6 compatibility %% Get normalized axis coordinates function normCoord = getNormCoord(hAx, axName, curPos) limits = get(hAx, [axName 'Lim']); if strcmpi(get(hAx,[axName 'Scale']), 'log') normCoord = (log2(curPos) - log2(limits(1))) / diff(log2(limits)); else normCoord = (curPos-limits(1)) / diff(limits); end %end % getNormCoord %#ok for Matlab 6 compatibility %% moveptr replacement for Matlab 6 compatibility function moveptr(hAx, x, y) % Compute normalized axis coordinates NormX = getNormCoord(hAx, 'x', x); NormY = getNormCoord(hAx, 'y', y); % Compute the new coordinates in screen units Transform = axis2Screen(hAx); NewLoc = Transform(1:2) + Transform(3:4) .* [NormX NormY]; % Move the pointer set(0,'PointerLocation',NewLoc); %end % moveptr %#ok for Matlab 6 compatibility %% UiContextMenu callback - Move cursor to center of requested element function moveCursor(varargin) try % Get the x,y location of the center of the requested object hScroll = handle(gca); hObj = get(gcbo,'UserData'); x = mean(get(hObj,'XData')); y = mean(get(hObj,'YData')); % Move the mouse pointer to that location % Note: Matlab 6 did not have moveptr() so we use a local version above %moveptr(hScroll, 'init'); %moveptr(hScroll, 'move', x, y); moveptr(hScroll, x, y); % Call mouseMoveCallback to update the pointer shape mouseMoveCallback; drawnow; catch % Never mind... disp(lasterr); end %end % moveCursor %#ok for Matlab 6 compatibility %% Callback when scroll axes are deleted function deleteScrollAx(varargin) try % Update the parent Axes position hScroll = varargin{1}; updateParentPos([],[],hScroll,'off'); % Note: no need to remove hAx listeners since these are destroyed along with hScroll catch % Never mind - continue deletion process... end %end % deleteScrollAx %#ok for Matlab 6 compatibility %% Update parent figure position based on scroll axes visibility function updateParentPos(schemaProp, eventData, hScroll,scrollVisibility) %#ok first 2 params are unused try if nargin<4 scrollVisibility = get(hScroll, 'visible'); end % Update the parent Axes position hAx = get(hScroll, 'ParentAxesHandle'); axPos = get(hAx,'position'); axName = get(hScroll, 'userdata'); hLabel = get(hAx, [axName 'Label']); set(hLabel, 'units','normalized'); oldPos = get(hLabel, 'position'); % Get the label position before the axes change if strcmpi(scrollVisibility,'off') ax_dy1 = 1/0.80; ax_dy2 = -1/0.80; label_delta = 0.20/0.80; else %'on' ax_dy1 = 0.80; ax_dy2 = 1; label_delta = -0.20/0.80; end if strcmpi(axName,'x') newPlotPos = axPos .* [1, 1, 1, ax_dy1] + [0, 0.20*axPos(4)*ax_dy2, 0, 0]; else % Y scroll newPlotPos = axPos .* [1, 1, ax_dy1, 1]; end set(hAx, 'Position',newPlotPos); % Fix label position(s) if strcmpi(axName,'x') if ~isempty(oldPos) & oldPos(2)<0 %#ok for Matlab 6 compatibility % Only fix if the X label is on the bottom (usually yes) set(hLabel, 'position',oldPos+[0,label_delta,0]); end else % Y scroll if ~isempty(oldPos) & oldPos(1)>0 %#ok for Matlab 6 compatibility % Only fix if the Y label is on the right side (usually not) set(hLabel, 'position',oldPos-[label_delta,0,0]); end end % Show/hide all the axes children (scroll patch, side-bars, text) set(findall(hScroll), 'Visible',scrollVisibility); % axisComponent gets re-created, so clear the cache hFig = ancestor(hScroll,'figure'); rmappdata(hFig, 'scrollplot_axisComponent'); catch % Never mind... end %end % updateParentPos %#ok for Matlab 6 compatibility %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% TODO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % - maybe add a blue diamond or a visual handle in center of side-bars? % - fix or bypass Matlab 6 OpenGL warning due to patch FaceAlpha property
github
rising-turtle/slam_matlab-master
plotframe.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/plotframe.m
1,677
utf_8
40c9bb130ec46ca33912f804e87f2eac
% PLOTFRAME - plots a coordinate frame specified by a homogeneous transform % % Usage: function plotframe(T, len, label) % % Arguments: % T - 4x4 homogeneous transform % len - length of axis arms to plot (defaults to 1) % label - text string to append to x,y,z labels on axes % % len and label are optional and default to 1 and '' respectively % % See also: ROTX, ROTY, ROTZ, TRANS, INVHT % Copyright (c) 2001 Peter Kovesi % School of Computer Science & Software Engineering % The University of Western Australia % pk at csse uwa edu au % http://www.csse.uwa.edu.au/ function plotframe(T, len, label, colr) if ~all(size(T) == [4,4]) error('plotframe: matrix is not 4x4') end if ~exist('len','var') len = 1; end if ~exist('label','var') label = ''; end if ~exist('colr','var') colr = [0 0 1]; end % Assume scale specified by T(4,4) == 1 origin = T(1:3, 4); % 1st three elements of 4th column X = origin + len*T(1:3, 1); % point 'len' units out along x axis Y = origin + len*T(1:3, 2); % point 'len' units out along y axis Z = origin + len*T(1:3, 3); % point 'len' units out along z axis line([origin(1),X(1)], [origin(2), X(2)], [origin(3), X(3)], 'color', colr); line([origin(1),Y(1)], [origin(2), Y(2)], [origin(3), Y(3)], 'color', colr); line([origin(1),Z(1)], [origin(2), Z(2)], [origin(3), Z(3)], 'color', colr); text(X(1), X(2), X(3), ['x' label], 'color', colr); text(Y(1), Y(2), Y(3), ['y' label], 'color', colr); text(Z(1), Z(2), Z(3), ['z' label], 'color', colr);
github
rising-turtle/slam_matlab-master
compensate_badpixel_soonhac.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/compensate_badpixel_soonhac.m
2,255
utf_8
c10f2a65debeca406e3c75b955e4e84c
% 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_soonhac(img, x, y, z, c, confidence_cut_off) e_index = c < confidence_cut_off; x_median=medfilt2(x, [3 3],'symmetric'); y_median=medfilt2(y, [3 3],'symmetric'); z_median=medfilt2(z, [3 3],'symmetric'); image_median=medfilt2(img, [3 3],'symmetric'); z(e_index) = z_median(e_index); x(e_index) = x_median(e_index); y(e_index) = y_median(e_index); img(e_index) = image_median(e_index); % % % % % % 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
fn_structdisp.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/fn_structdisp.m
2,279
utf_8
7abee2d7e63975b016be8f923567bc05
function fn_structdisp(Xname) % function fn_structdisp Xname % function fn_structdisp(X) %--- % Recursively display the content of a structure and its sub-structures % % Input: % - Xname/X one can give as argument either the structure to display or % or a string (the name in the current workspace of the % structure to display) % % A few parameters can be adjusted inside the m file to determine when % arrays and cell should be displayed completely or not % Thomas Deneux % Copyright 2005-2012 if ischar(Xname) X = evalin('caller',Xname); else X = Xname; Xname = inputname(1); end if ~isstruct(X), error('argument should be a structure or the name of a structure'), end rec_structdisp(Xname,X) %--------------------------------- function rec_structdisp(Xname,X) %--- %-- PARAMETERS (Edit this) --% ARRAYMAXROWS = 10; ARRAYMAXCOLS = 10; ARRAYMAXELEMS = 30; CELLMAXROWS = 10; CELLMAXCOLS = 10; CELLMAXELEMS = 30; CELLRECURSIVE = false; %----- PARAMETERS END -------% disp([Xname ':']) disp(X) %fprintf('\b') if isstruct(X) || isobject(X) F = fieldnames(X); nsub = length(F); Y = cell(1,nsub); subnames = cell(1,nsub); for i=1:nsub f = F{i}; Y{i} = X.(f); subnames{i} = [Xname '.' f]; end elseif CELLRECURSIVE && iscell(X) nsub = numel(X); s = size(X); Y = X(:); subnames = cell(1,nsub); for i=1:nsub inds = s; globind = i-1; for k=1:length(s) inds(k) = 1+mod(globind,s(k)); globind = floor(globind/s(k)); end subnames{i} = [Xname '{' num2str(inds,'%i,')]; subnames{i}(end) = '}'; end else return end for i=1:nsub a = Y{i}; if isstruct(a) || isobject(a) if length(a)==1 rec_structdisp(subnames{i},a) else for k=1:length(a) rec_structdisp([subnames{i} '(' num2str(k) ')'],a(k)) end end elseif iscell(a) if size(a,1)<=CELLMAXROWS && size(a,2)<=CELLMAXCOLS && numel(a)<=CELLMAXELEMS rec_structdisp(subnames{i},a) end elseif size(a,1)<=ARRAYMAXROWS && size(a,2)<=ARRAYMAXCOLS && numel(a)<=ARRAYMAXELEMS disp([subnames{i} ':']) disp(a) end end
github
rising-turtle/slam_matlab-master
cov_pose_shift_calc.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/cov_pose_shift_calc.m
1,718
utf_8
6f51efd75828bc2370303048442bade9
function cov_pose_shift = cov_pose_shift_calc(Ya,Yb,R,T) q_ab = R2q(R); cov_pose_shift = zeros(7,7); for i=1:size(Ya,2) f_p = Ya(:,i); f_n = Yb(:,i); % cov_f_p = calc_cov_point(f_p); % cov_f_n = calc_cov_point(f_n); d2E_dX2_value = d2E_dX2_4cov(f_p,f_n,q_ab,T); d2E_dFdX_value = [d2E_dfp_dX_4cov(f_p,f_n,q_ab,T) d2E_dfn_dX_4cov(f_p,f_n,q_ab,T)]; [cov_cart_f_p,tt,ttt] = calc_point_cov_jacobian(f_p); [cov_cart_f_n,tt,ttt] = calc_point_cov_jacobian(f_n); try J_X2F = -pinv(d2E_dX2_value)*d2E_dFdX_value; catch disp('J_X2F calculation failed ! \n') end cov_pose_shift = cov_pose_shift + J_X2F*blkdiag(cov_cart_f_p,cov_cart_f_n)*J_X2F'; end end function [cov_cart,J_sph2cart,cov_spher] = calc_point_cov_jacobian(point) [azimuth,elevation,r] = cart2sph(point(1),point(2),point(3)); x = r .* cos(elevation) .* cos(azimuth); y = r .* cos(elevation) .* sin(azimuth); z = r .* sin(elevation); %%% check correctness if norm([x,y,z]-[point(1),point(2),point(3)])>0.000000001 disp('ERROR OCCURRED IN SHP<-->CART CONVERISON') end J_sph2cart = [cos(elevation) * cos(azimuth) -r * cos(elevation) * sin(azimuth) -r * sin(elevation) * cos(azimuth);... cos(elevation) * sin(azimuth) r * cos(elevation) * cos(azimuth) -r * sin(elevation) * sin(azimuth);... sin(elevation) 0 r .* cos(elevation) ]; cov_spher = diag( [ (0.01/3)^2 , (0.24*pi/180/10)^2 .* [ 1 1 ] ] ); %%% uncertaint of the range is 1cm and I assume the uncertsainty of the azimuth and elevation is equal %%% to sensor's angular resolution (0.24 degrees) cov_cart = J_sph2cart*cov_spher*J_sph2cart'; end
github
rising-turtle/slam_matlab-master
test_orientation_observation.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/test_orientation_observation.m
3,049
utf_8
ce9f7def042bcd152cd6df91afcdd3b9
function com_error = test_orientation_observation(snap_step) global myCONFIG config_file % snap_step =1; [x_k_k,p_k_k,q_expected] = read_snapshot(snap_step) [T,q,R,varargout]=Calculate_V_Omega_RANSAC_dr_ye(snap_step-1,snap_step) com_error = calc_orientation_error(x_k_k,snap_step,q_expected); R_expected = q2R(q_expected); R_estimated = q2R(x_k_k(4:7)); [m_, a_] = find_angle_bw_2_vecs(R_expected(:,2), R_estimated(:,2)); display_angles(m_, a_); end function [x_k_k,p_k_k,q_expected] = read_snapshot(snap_step) global myCONFIG load([myCONFIG.PATH.DATA_FOLDER,'DataSnapshots/','snapshot',num2str(snap_step),'.mat']) features_info = eval(['snapshot',num2str(snap_step),'.features_info']); filter = eval(['snapshot',num2str(snap_step),'.filter']); [R,T] = plane_fit_to_data(snap_step); x_k_k = get_x_k_k(filter); p_k_k = get_p_k_k(filter); q_expected = R2q(R'); x_k_k = x_k_k(1:7); p_k_k = p_k_k (1:7,1:7); end function com_error = calc_orientation_error(x_k_k,snap_step,q_expected) vect_est = q2R(x_k_k(4:7))*[0; 0 ;1]; vect_gt = q2R(q_expected)*[0; 0 ;1]; % com_error = euler_vec' - [zeros(size(gt_pan),1),gt_pan,zeros(size(gt_pan),1)]; [m_, a_] = find_angle_bw_2_vecs(vect_est, vect_gt); display_angles(m_, a_); h3 = mArrow3([0;0;0],vect_est,'color',[1 0 0]); h4 = mArrow3([0;0;0],vect_gt,'color',[0 1 0]); % if i~=size(euler_vec,2) delete(h3) delete(h4) % end % com_error(i,:) = R2e(e2R(euler_vec(:,i))*(e2R([0 gt_pan(i) 0]))'); com_error = a_(7) ; end % load([myCONFIG.PATH.DATA_FOLDER,'DataSnapshots/','snapshot',num2str(myCONFIG.STEP.END-1),'.mat']) % features_info = eval(['snapshot',num2str(myCONFIG.STEP.END-1),'.features_info']); % filter = eval(['snapshot',num2str(myCONFIG.STEP.END-1),'.filter']); % if step==initIm+1 % [R,T] = plane_fit_to_data(myCONFIG.STEP.END-1); % R=eye(3); % end % x_k_k_temp(1:7) % x_k_k_temp = get_x_k_k(filter); % stacked_x_k_k(:,step) = [R'*x_k_k_temp(1:3); R2q(R'*q2R( x_k_k_temp(4:7))) ]; % % [V,q]=calc_gt_in_1pointRANSAC(1,step); % % [V,q,time_gt]=get_gt_time(initIm,step); % % q=q';%% temperorily % % GroundTruth(:,step - initIm) = [V;q']; % trajectory(:,step - initIm) = [R'*x_k_k_temp(1:3); R2q(R'*q2R( x_k_k_temp(4:7)))]; % % time_vector(step - initIm)=time_gt; % p_k_k_temp = get_p_k_k(filter); % stacked_p_k_k(:,:,step) = p_k_k_temp(1:7,1:7); % step % % NormError(step - initIm)=norm(x_k_k_temp(1:3)-V); % % % for i=1:size(euler_vec,2) % vect_est = q2R(xx(4:7,i))*[1; 1 ;1]; % vect_gt = e2R([0 gt_pan(i)*pi/180 0])*[0; 0 ;1]; % % % % com_error = euler_vec' - [zeros(size(gt_pan),1),gt_pan,zeros(size(gt_pan),1)]; % [m_, a_] = find_angle_bw_2_vecs(vect_est, vect_gt); % display_angles(m_, a_); % % h3 = mArrow3([0;0;0],vect_est,'color',[1 0 0]); % % h4 = mArrow3([0;0;0],vect_gt,'color',[0 1 0]); % if i~=size(euler_vec,2) % delete(h3) % delete(h4) % end % % com_error(i,:) = R2e(e2R(euler_vec(:,i))*(e2R([0 gt_pan(i) 0]))'); % com_error(i,:) = a_(7) ; % end
github
rising-turtle/slam_matlab-master
dispMEq.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/drawLA/dispMEq.m
8,277
utf_8
1e3bbf518742830f3c041b1d1c5c171b
function dispMEq(eq, varargin) % Formatted display of a matrix equation % % Usage: dispEq(eq, arg) % dispEq(eq, arg1, arg2, ...) % dispEq(eq, arg1, arg2, ..., 'PropertyName', PropertyValue) % % INPUT: % eq - character string defining a matrix equation, e.g., 'A*x=b' % allowed arithmetical operations are: [+, -, *, / , \, =, ;] % arg{1,2,...} - matrices corresponding to their symbolic definition in the equation, % can be NaN (see the last 4 examples) % % (optional parameters) % PropertyName: PropertyValue % 'format' - a cell array with the formats for the text output. May be of 4 types: % 1) a string specifying the num2str conversion format, % see help to num2str for details; % 2) 'elems' - output is symbolic, elementwise (default); % 3) 'cols' - output is symbolic, grouped by colums; % 4) 'rows' - output is symbolic, grouped by rows. % % OUTPUT: % none % % Examples: % A = rand(5); figure(1);clf; dispMEq('A', A); % A = rand(5); figure(1);clf; dispMEq('A', A, 'format', {'%1.1f'}); % A = randn(5,3); x=rand(3,1); figure(1); clf; dispMEq('A*x=b', A, x, A*x); % A = rand(5); [L,U]=lu(A); figure(1);clf; dispMEq('A=L*U',A,L,U); % A = nan(5); figure(1);clf; dispMEq('A',A); % A = nan(5); figure(1);clf; dispMEq('A',A,'format',{'cols'}); % A = nan(3,2); B = nan(2,4); figure(1);clf; dispMEq('A*B',A,B,'format',{'rows','cols'}); % y = {'\alpha' '\beta' '\gamma';'bla' 'bla' 'bla'}; figure(1);clf; dispMEq('y',y, 'format',{'rows'}); % % See also: . % Copyright (c) 2009, Dr. Vladimir Bondarenko <http://sites.google.com/site/bondsite> % Check input: error(nargchk(2,15,nargin)); if ~ischar(eq), error('The equation argument must be a string.'); end; % Defaults: global maxEntry minEntry txtFormat = '%-5.2f'; % Default text format % Parse Input: regexprep(eq, ' ', ''); % remove white spaces % ix = regexp(eq, '[=,+,\-,*,\\,/,;]'); % find arithmetic operations ix = regexp(eq, '[=,+,\-,*,/,;]'); % find arithmetic operations nOp = length(ix); ix = [0 ix length(eq)+1]; if nargin<nOp+2, error('Number of numeric arguments is less then defined in the equation.');end; for ii=1:nOp+1 if ~isnumeric(varargin{ii}) if iscell(varargin{ii}) A(ii).data = nan(size(varargin{ii})); A(ii).max = nan; A(ii).min = nan; A(ii).userText = varargin{ii}; A(ii).txtFormat = txtFormat; A(ii).m = size(A(ii).data,1); A(ii).n = size(A(ii).data,2); A(ii).symName = eq(ix(ii)+1:ix(ii+1)-1); else error('Error in the assignment of numeric arguments.'); end else A(ii).data = varargin{ii}; A(ii).max = max(A(ii).data(:)); A(ii).min = min(A(ii).data(:)); A(ii).m = size(A(ii).data,1); A(ii).n = size(A(ii).data,2); A(ii).symName = eq(ix(ii)+1:ix(ii+1)-1); A(ii).txtFormat = txtFormat; A(ii).userText = []; end end maxEntry = max([A(:).max]); minEntry = min([A(:).min]); % Parse optional arguments: if nargin > nOp+2 for ii=nOp+2:2:nargin-1 switch lower(varargin{ii}) case 'format' txtFormat = varargin{ii+1}; if ~iscell(txtFormat), error('Format parameter must be a cell array.');end dum = length(txtFormat); if (dum>1)&&(dum~=nOp+1), error('Number of formats must either 1 or equal to the number of arguments.');end for jj=1:nOp+1 if ~isempty(txtFormat{ (dum>1)*jj + (dum==1) }) A(jj).txtFormat = txtFormat{(dum>1)*jj + (dum==1)}; end end otherwise error(['Unknown input parameter: ' varargin{ii}]); end end end % MAIN sc = 3; % column scaling factor for the subplots dum1 = sum([A(:).n])*sc + nOp; % overall number of subplots dum2 = cumsum([A(:).n]*sc) + (0:nOp); % overall number of columns % Display matrices for ii=1:nOp+1 hsp(ii) = subplot(1,dum1,[(dum2(ii)-A(ii).n*sc+1) dum2(ii)]); if max(A(ii).m,A(ii).n)<=20 % Display text if max dimension does not exceed 20. dispMatrix(A(ii).data, A(ii).txtFormat); dispText(A(ii)); else imagesc(A(ii).data(1:min(A(ii).m,30),1:min(A(ii).n,30)), [minEntry maxEntry]); axis equal tight off title(A(ii).symName, 'FontSize', 16); end end % Display arithmetic operations for ii=1:nOp op = eq(ix(ii+1)); % if strcmp(op, '*'), op='\times'; end; if strcmp(op, '*'), op='x'; end; % subplot(1,dum1, dum2(ii)+1); pos1 = get(hsp(ii) , 'position'); pos2 = get(hsp(ii+1), 'position'); w = pos2(1)-(pos1(1)+pos1(3)); h = pos1(4); subplot('position',[pos1(1)+pos1(3) pos1(2) w h]) text(.3,.5,op, 'FontUnits', 'normalized', 'FontSize', 0.05); axis equal tight off end set(gcf, 'color', 'w'); end %% Subfunctions: %% function dispMatrix(A,txtFormat) % Plot matrix array to the current plot global maxEntry minEntry [m, n] = size(A); if isnan(A) switch lower(txtFormat) case 'cols' dum = 1:n; A = dum(ones(m,1),:); minEntry = 0; maxEntry = n; case 'rows' dum = (1:m)'; A = dum(:,ones(n,1)); minEntry = 0; maxEntry = m; case 'elem' A = reshape(1:m*n, m, n); minEntry = 0; maxEntry = m*n; case 'user' A = nan(m,n); otherwise end end % Display matrix if isnan(A), minEntry = 0; maxEntry = 1;end; imagesc(A, [minEntry maxEntry]); cmap = colormap(jet(128)); colormap(cmap(30:end-10,:)); axis equal tight set(gca, 'XTick',[], 'YTick', []); end %% function dispText(A) [m, n] = size(A.data); m1 = m; n1 = n; % Convert matrix to string if ~isempty(A.userText) txt = char(A.userText); fcolor = 'k'; else [txt, fcolor] = matrix2str(A.data, A.symName, A.txtFormat); end % Display text title(A.symName, 'FontSize', 16); axPos = get(gca, 'position'); [ii,jj] = meshgrid(1:n,1:m); fsz = .45*max([axPos(3) axPos(4)])/max([m1 n1]); ii = ii - .4*(m1/m); jj = jj + .1; text(ii(:),jj(:),txt, 'FontUnits', 'normalized',... 'FontSize', fsz,... 'Color', fcolor); end %% function [txt,fcolor] = matrix2str(M,symName,txtFormat) [m, n] = size(M); [ii,jj] = meshgrid(1:n,1:m); switch lower(txtFormat) case 'cols' if isscalar(M)==1 txt = symName; % No indices for 1-by-1 matrices, i.e., for scalars. else if n==1 dum = lower(symName); txt = dum(ones(m,1),:); else txt = strcat(lower(symName), '_{', num2str(ii(:)), '}'); end dum1 = ceil(m/2); dum2 = reshape(1:m*n,m,n); ix = dum2([1:dum1-1,dum1+1:end],:); txt(ix(:),:) = ' '; end fcolor = 'k'; case 'rows' if isscalar(M) txt = symName; % No indices for 1-by-1 matrices, i.e., for scalars. else if m==1 dum = lower(symName); txt = dum(ones(n,1),:); else txt = strcat(lower(symName), '^{', num2str(jj(:)), '}'); end dum1 = ceil(n/2); dum2 = reshape(1:m*n,m,n); ix = dum2(:,[1:dum1-1,dum1+1:end]); txt(ix(:),:) = ' '; end fcolor = 'k'; otherwise if isnan(M) % Non-numeric input fcolor = 'w'; if isscalar(M) txt = symName; % No indices for 1-by-1 matrices, i.e., for scalars. else txt = strcat(symName, '_{', num2str(jj(:)), num2str(ii(:)), '}'); end else % Numerical input fcolor = 'k'; if abs(M-round(M))<realmin, txtFormat = '%-5.0f'; end % No fractional part for integers. txt = num2str(M(:), txtFormat); end end end
github
rising-turtle/slam_matlab-master
drawCircle.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/drawLA/drawCircle.m
3,103
utf_8
488a37088332d5ce21c6b8df98889e42
function drawCircle(varargin) % Draw circle(s) in the xy-plane. % % Usage: drawCircle % drawCircle(xc,yc,r) % drawCircle(xc,yc,r, 'lType') % % INPUT: % (optional) % xc,yc - n-by-m matrices with (x,y) coordinates of the center(s) % of n*m circles. Default: (0, 0). % r - either a scalar or an n-by-m matrix of circle(s) radii. % Default: 1. % 'lType' - a string defining the line style and width (e.g., '2r-.'). % Default: 'b-'. % % OUTPUT: % none % % Examples in 2D: % clf; drawCircle; % clf; drawCircle(3, 2, '2r-.'); % clf; x = randn(2,3); y = randn(2,3); r = rand(2,3); drawCircle(x,y,r,'gs'); % Examples in 3D: % clf; drawVector([1 1 2]); hold on; drawCircle([0 1], [0 -1], [1,.5], '2r-'); hold off; % % See also: drawSphere, drawPlane, drawVector, drawLine, drawXLine, drawYLine. % Copyright (c) 2009, Dr. Vladimir Bondarenko <http://sites.google.com/site/bondsite> % Check input: error(nargchk(0,4,nargin)); % Defaults: N = 100; k = 0:N; % Number of points on the circle(s) xc = 0; yc = 0; r = 1; % Center coordinates and radius. lType = 'k-'; % Parse input: for ii=1:nargin if ischar(varargin{ii}) lType = varargin{ii}; elseif isscalar(varargin{ii}) if nargin==1 r = varargin{ii}; elseif ii==1 xc = varargin{ii}; elseif ii==2 yc = varargin{ii}; end else if ii==1 xc = varargin{ii}; elseif ii==2 yc = varargin{ii}; else r = varargin{ii}; end end end % Check input if ~all(size(xc)==size(yc)), error('Dimensions of xc and yc must be equal.'); end; if ~isscalar(r)&&~all(size(xc)==size(r)) error('Wrong dimensions of r. Must be scalar or matrix with dimensins of xc and yc'); end; % Parse the line parameters [lStyle,lWidth,lColor, lMarker] = parseLineType(lType); % MAIN: holdon = get(gca, 'NextPlot'); % Capture the NextPlot property for ii=1:size(xc,1) for jj = 1:size(xc,2) xy = r(ii,jj)*exp(2*pi*1i*k./N) + xc(ii,jj) + 1i*yc(ii,jj); x = real(xy); y = imag(xy); line(x, y, 'LineStyle', lStyle, ... 'LineWidth', lWidth, ... 'Color' , lColor, ... 'Marker' , lMarker ); hold on; end end axis equal set(gca, 'NextPlot', holdon); % restore the NextPlot property function [lStyle,lWidth,lColor, lMarker] = parseLineType(lType) % Parse the line type % get line style lStyles = '--|:|-\.|-'; [dum1,dum2,dum3, lStyle] = regexp(lType, lStyles, 'once'); if isempty(lStyle), lStyle = 'none'; end % get width [dum1,dum2,dum3, lWidth] = regexp(lType, '\d*', 'once'); if isempty(lWidth), lWidth = 1; else lWidth = str2double(lWidth); end % get color lColors = 'y|m|c|r|g|b|w|k'; [dum1,dum2,dum3, lColor] = regexp(lType, lColors, 'once'); if isempty(lColor), lColor = 'k'; end % get marker lMarkers = '\+|o|\*|\.|x|s|d|\^|>|<|v|p|h|'; [dum1,dum2,dum3, lMarker] = regexp(lType, lMarkers, 'once'); if isempty(lMarker), lMarker = 'none'; end
github
rising-turtle/slam_matlab-master
efficient_pnp_gauss.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/EPnP_matlab/EPnP/efficient_pnp_gauss.m
7,985
utf_8
361396729ae9c9291df547c60c062e74
function [R,T,Xc,best_solution,opt]=efficient_pnp_gauss(x3d_h,x2d_h,A) % EFFICIENT_PNP_GAUSS Main Function to solve the PnP problem % as described in: % % Francesc Moreno-Noguer, Vincent Lepetit, Pascal Fua. % Accurate Non-Iterative O(n) Solution to the PnP Problem. % In Proceedings of ICCV, 2007. % % Note: In this version of the software we perform a final % optimization using Gauss-Newton,which is not described in the % paper. % % x3d_h: homogeneous coordinates of the points in world reference % x2d_h: homogeneous position of the points in the image plane % A: intrincic camera parameters % R: Rotation of the camera system wrt world reference % T: Translation of the camera system wrt world reference % Xc: Position of the points in the camera reference % best solution: dimension of the kernel for the best solution % (before applying Gauss Newton). % opt: some parameters of the optimization process % % Copyright (C) <2007> <Francesc Moreno-Noguer, Vincent Lepetit, Pascal Fua> % % This program is free software: you can redistribute it and/or modify % it under the terms of the version 3 of the GNU General Public License % as published by the Free Software Foundation. % % This program 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 this program. If not, see <http://www.gnu.org/licenses/>. % % Francesc Moreno-Noguer, CVLab-EPFL, October 2007. % [email protected], http://cvlab.epfl.ch/~fmoreno/ Xw=x3d_h(:,1:3); U=x2d_h(:,1:2); THRESHOLD_REPROJECTION_ERROR=20;%error in degrees of the basis formed by the control points. %If we have a larger error, we will compute the solution using a larger %number of vectors in the kernel %define control points in a world coordinate system (centered on the 3d %points centroid) Cw=define_control_points(); %compute alphas (linear combination of the control points to represent the 3d %points) Alph=compute_alphas(Xw,Cw); %Compute M M=compute_M_ver2(U,Alph,A); %Compute kernel M Km=kernel_noise(M,4); %in matlab we have directly the funcion km=null(M); %1.-Solve assuming dim(ker(M))=1. X=[Km_end];------------------------------ dim_kerM=1; X1=Km(:,end); [Cc,Xc,sc]=compute_norm_sign_scaling_factor(X1,Cw,Alph,Xw); [R,T]=getrotT(Xw,Xc); %solve exterior orientation err(1)=reprojection_error_usingRT(Xw,U,R,T,A); sol(1).Xc=Xc; sol(1).Cc=Cc; sol(1).R=R; sol(1).T=T; sol(1).error=err(1); sol(1).betas=[1]; sol(1).sc=sc; sol(1).Kernel=X1; %2.-Solve assuming dim(ker(M))=2------------------------------------------ Km1=Km(:,end-1); Km2=Km(:,end); %control points distance constraint D=compute_constraint_distance_2param_6eq_3unk(Km1,Km2); dsq=define_distances_btw_control_points(); betas_=inv(D'*D)*D'*dsq; beta1=sqrt(abs(betas_(1))); beta2=sqrt(abs(betas_(3)))*sign(betas_(2))*sign(betas_(1)); X2=beta1*Km1+beta2*Km2; [Cc,Xc,sc]=compute_norm_sign_scaling_factor(X2,Cw,Alph,Xw); [R,T]=getrotT(Xw,Xc); %solve exterior orientation err(2)=reprojection_error_usingRT(Xw,U,R,T,A); sol(2).Xc=Xc; sol(2).Cc=Cc; sol(2).R=R; sol(2).T=T; sol(2).error=err(2); sol(2).betas=[beta1,beta2]; sol(2).sc=sc; sol(2).Kernel=[Km1,Km2]; %3.-Solve assuming dim(ker(M))=3------------------------------------------ if min(err)>THRESHOLD_REPROJECTION_ERROR %just compute if we do not have good solution in the previus cases Km1=Km(:,end-2); Km2=Km(:,end-1); Km3=Km(:,end); %control points distance constraint D=compute_constraint_distance_3param_6eq_6unk(Km1,Km2,Km3); dsq=define_distances_btw_control_points(); betas_=inv(D)*dsq; beta1=sqrt(abs(betas_(1))); beta2=sqrt(abs(betas_(4)))*sign(betas_(2))*sign(betas_(1)); beta3=sqrt(abs(betas_(6)))*sign(betas_(3))*sign(betas_(1)); X3=beta1*Km1+beta2*Km2+beta3*Km3; [Cc,Xc,sc]=compute_norm_sign_scaling_factor(X3,Cw,Alph,Xw); [R,T]=getrotT(Xw,Xc); %solve exterior orientation err(3)=reprojection_error_usingRT(Xw,U,R,T,A); sol(3).Xc=Xc; sol(3).Cc=Cc; sol(3).R=R; sol(3).T=T; sol(3).error=err(3); sol(3).betas=[beta1,beta2,beta3]; sol(3).sc=sc; sol(3).Kernel=[Km1,Km2,Km3]; end %4.-Solve assuming dim(ker(M))=4------------------------------------------ if min(err)>THRESHOLD_REPROJECTION_ERROR %just compute if we do not have good solution in the previus cases Km1=Km(:,end-3); Km2=Km(:,end-2); Km3=Km(:,end-1); Km4=Km(:,end); D=compute_constraint_distance_orthog_4param_9eq_10unk(Km1,Km2,Km3,Km4); dsq=define_distances_btw_control_points(); lastcolumn=[-dsq',0,0,0]'; D_=[D,lastcolumn]; Kd=null(D_); P=compute_permutation_constraint4(Kd); lambdas_=kernel_noise(P,1); lambda(1)=sqrt(abs(lambdas_(1))); lambda(2)=sqrt(abs(lambdas_(6)))*sign(lambdas_(2))*sign(lambdas_(1)); lambda(3)=sqrt(abs(lambdas_(10)))*sign(lambdas_(3))*sign(lambdas_(1)); lambda(4)=sqrt(abs(lambdas_(13)))*sign(lambdas_(4))*sign(lambdas_(1)); lambda(5)=sqrt(abs(lambdas_(15)))*sign(lambdas_(5))*sign(lambdas_(1)); betass_=lambda(1)*Kd(:,1)+lambda(2)*Kd(:,2)+lambda(3)*Kd(:,3)+lambda(4)*Kd(:,4)+lambda(5)*Kd(:,5); beta1=sqrt(abs(betass_(1))); beta2=sqrt(abs(betass_(5)))*sign(betass_(2)); beta3=sqrt(abs(betass_(8)))*sign(betass_(3)); beta4=sqrt(abs(betass_(10)))*sign(betass_(4)); X4=beta1*Km1+beta2*Km2+beta3*Km3+beta4*Km4; [Cc,Xc,sc]=compute_norm_sign_scaling_factor(X4,Cw,Alph,Xw); [R,T]=getrotT(Xw,Xc); %solve exterior orientation err(4)=reprojection_error_usingRT(Xw,U,R,T,A); sol(4).Xc=Xc; sol(4).Cc=Cc; sol(4).R=R; sol(4).T=T; sol(4).error=err(4); sol(4).betas=[beta1,beta2,beta3,beta4]; sol(4).sc=sc; sol(4).Kernel=[Km1,Km2,Km3,Km4]; end %5.-Gauss Newton Optimization------------------------------------------------------ [min_err,best_solution]=min(err); Xc=sol(best_solution).Xc; R=sol(best_solution).R; T=sol(best_solution).T; Betas=sol(best_solution).betas; sc=sol(best_solution).sc; Kernel=sol(best_solution).Kernel; if best_solution==1 Betas=[0,0,0,Betas]; elseif best_solution==2 Betas=[0,0,Betas]; elseif best_solution==3 Betas=[0,Betas]; end Km1=Km(:,end-3); Km2=Km(:,end-2); Km3=Km(:,end-1); Km4=Km(:,end); Kernel=[Km1,Km2,Km3,Km4]; %refine the solution iterating over the betas Beta0=Betas/sc; [Xc_opt,R_opt,T_opt,err_opt,iter]=optimize_betas_gauss_newton(Kernel,Cw,Beta0,Alph,Xw,U,A); %Just update R,T,Xc if Gauss Newton improves results (which is almost %always) if err_opt<min_err R=R_opt; T=T_opt; Xc=Xc_opt; end opt.Beta0=Beta0; opt.Kernel=Kernel; opt.iter=iter; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [R, T]=getrotT(wpts,cpts) % This routine solves the exterior orientation problem for a point cloud % given in both camera and world coordinates. % wpts = 3D points in arbitrary reference frame % cpts = 3D points in camera reference frame n=size(wpts,1); M=zeros(3); ccent=mean(cpts); wcent=mean(wpts); for i=1:3 cpts(:,i)=cpts(:,i)-ccent(i)*ones(n,1); wpts(:,i)=wpts(:,i)-wcent(i)*ones(n,1); end for i=1:n M=M+cpts(i,:)'*wpts(i,:); end [U S V]=svd(M); R=U*V'; if det(R)<0 R=-R; end T=ccent'-R*wcent'; % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [err,Urep]=reprojection_error_usingRT(Xw,U,R,T,A) %clear all; close all; load reprojection_error_usingRT; n=size(Xw,1); P=A*[R,T]; Xw_h=[Xw,ones(n,1)]; Urep_=(P*Xw_h')'; %project reference points into the image plane Urep=zeros(n,2); Urep(:,1)=Urep_(:,1)./Urep_(:,3); Urep(:,2)=Urep_(:,2)./Urep_(:,3); %reprojection error err_=sqrt((U(:,1)-Urep(:,1)).^2+(U(:,2)-Urep(:,2)).^2); err=sum(err_)/n;
github
rising-turtle/slam_matlab-master
efficient_pnp.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/EPnP_matlab/EPnP/efficient_pnp.m
6,550
utf_8
b1b02989deb052da7480f60d06be7010
function [R,T,Xc,best_solution]=efficient_pnp(x3d_h,x2d_h,A) % EFFICIENT_PNP Main Function to solve the PnP problem % as described in: % % Francesc Moreno-Noguer, Vincent Lepetit, Pascal Fua. % Accurate Non-Iterative O(n) Solution to the PnP Problem. % In Proceedings of ICCV, 2007. % % x3d_h: homogeneous coordinates of the points in world reference % x2d_h: homogeneous position of the points in the image plane % A: intrincic camera parameters % R: Rotation of the camera system wrt world reference % T: Translation of the camera system wrt world reference % Xc: Position of the points in the camera reference % % Copyright (C) <2007> <Francesc Moreno-Noguer, Vincent Lepetit, Pascal Fua> % % This program is free software: you can redistribute it and/or modify % it under the terms of the version 3 of the GNU General Public License % as published by the Free Software Foundation. % % This program 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 this program. If not, see <http://www.gnu.org/licenses/>. % % Francesc Moreno-Noguer, CVLab-EPFL, September 2007. % [email protected], http://cvlab.epfl.ch/~fmoreno/ Xw=x3d_h(:,1:3); U=x2d_h(:,1:2); THRESHOLD_REPROJECTION_ERROR=20;%error in degrees of the basis formed by the control points. %If we have a larger error, we will compute the solution using a larger %number of vectors in the kernel %define control points in a world coordinate system (centered on the 3d %points centroid) Cw=define_control_points(); %compute alphas (linear combination of the control points to represent the 3d %points) Alph=compute_alphas(Xw,Cw); %Compute M M=compute_M_ver2(U,Alph,A); %Compute kernel M Km=kernel_noise(M,4); %in matlab we have directly the funcion km=null(M); %1.-Solve assuming dim(ker(M))=1. X=[Km_end];------------------------------ dim_kerM=1; X1=Km(:,end); [Cc,Xc]=compute_norm_sign_scaling_factor(X1,Cw,Alph,Xw); [R,T]=getrotT(Xw,Xc); %solve exterior orientation err(1)=reprojection_error_usingRT(Xw,U,R,T,A); sol(1).Xc=Xc; sol(1).Cc=Cc; sol(1).R=R; sol(1).T=T; sol(1).error=err(1); %2.-Solve assuming dim(ker(M))=2------------------------------------------ Km1=Km(:,end-1); Km2=Km(:,end); %control points distance constraint D=compute_constraint_distance_2param_6eq_3unk(Km1,Km2); dsq=define_distances_btw_control_points(); betas_=inv(D'*D)*D'*dsq; beta1=sqrt(abs(betas_(1))); beta2=sqrt(abs(betas_(3)))*sign(betas_(2))*sign(betas_(1)); X2=beta1*Km1+beta2*Km2; [Cc,Xc]=compute_norm_sign_scaling_factor(X2,Cw,Alph,Xw); [R,T]=getrotT(Xw,Xc); %solve exterior orientation err(2)=reprojection_error_usingRT(Xw,U,R,T,A); sol(2).Xc=Xc; sol(2).Cc=Cc; sol(2).R=R; sol(2).T=T; sol(2).error=err(2); %3.-Solve assuming dim(ker(M))=3------------------------------------------ if min(err)>THRESHOLD_REPROJECTION_ERROR %just compute if we do not have good solution in the previus cases Km1=Km(:,end-2); Km2=Km(:,end-1); Km3=Km(:,end); %control points distance constraint D=compute_constraint_distance_3param_6eq_6unk(Km1,Km2,Km3); dsq=define_distances_btw_control_points(); betas_=inv(D)*dsq; beta1=sqrt(abs(betas_(1))); beta2=sqrt(abs(betas_(4)))*sign(betas_(2))*sign(betas_(1)); beta3=sqrt(abs(betas_(6)))*sign(betas_(3))*sign(betas_(1)); X3=beta1*Km1+beta2*Km2+beta3*Km3; [Cc,Xc]=compute_norm_sign_scaling_factor(X3,Cw,Alph,Xw); [R,T]=getrotT(Xw,Xc); %solve exterior orientation err(3)=reprojection_error_usingRT(Xw,U,R,T,A); sol(3).Xc=Xc; sol(3).Cc=Cc; sol(3).R=R; sol(3).T=T; sol(3).error=err(3); end %4.-Solve assuming dim(ker(M))=4------------------------------------------ if min(err)>THRESHOLD_REPROJECTION_ERROR %just compute if we do not have good solution in the previus cases Km1=Km(:,end-3); Km2=Km(:,end-2); Km3=Km(:,end-1); Km4=Km(:,end); D=compute_constraint_distance_orthog_4param_9eq_10unk(Km1,Km2,Km3,Km4); dsq=define_distances_btw_control_points(); lastcolumn=[-dsq',0,0,0]'; D_=[D,lastcolumn]; Kd=null(D_); P=compute_permutation_constraint4(Kd); lambdas_=kernel_noise(P,1); lambda(1)=sqrt(abs(lambdas_(1))); lambda(2)=sqrt(abs(lambdas_(6)))*sign(lambdas_(2))*sign(lambdas_(1)); lambda(3)=sqrt(abs(lambdas_(10)))*sign(lambdas_(3))*sign(lambdas_(1)); lambda(4)=sqrt(abs(lambdas_(13)))*sign(lambdas_(4))*sign(lambdas_(1)); lambda(5)=sqrt(abs(lambdas_(15)))*sign(lambdas_(5))*sign(lambdas_(1)); betass_=lambda(1)*Kd(:,1)+lambda(2)*Kd(:,2)+lambda(3)*Kd(:,3)+lambda(4)*Kd(:,4)+lambda(5)*Kd(:,5); beta1=sqrt(abs(betass_(1))); beta2=sqrt(abs(betass_(5)))*sign(betass_(2)); beta3=sqrt(abs(betass_(8)))*sign(betass_(3)); beta4=sqrt(abs(betass_(10)))*sign(betass_(4)); X4=beta1*Km1+beta2*Km2+beta3*Km3+beta4*Km4; [Cc,Xc]=compute_norm_sign_scaling_factor(X4,Cw,Alph,Xw); [R,T]=getrotT(Xw,Xc); %solve exterior orientation err(4)=reprojection_error_usingRT(Xw,U,R,T,A); sol(4).Xc=Xc; sol(4).Cc=Cc; sol(4).R=R; sol(4).T=T; sol(4).error=err(4); end [min_err,best_solution]=min(err); Xc=sol(best_solution).Xc; R=sol(best_solution).R; T=sol(best_solution).T; %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [R, T]=getrotT(wpts,cpts) % This routine solves the exterior orientation problem for a point cloud % given in both camera and world coordinates. % wpts = 3D points in arbitrary reference frame % cpts = 3D points in camera reference frame n=size(wpts,1); M=zeros(3); ccent=mean(cpts); wcent=mean(wpts); for i=1:3 cpts(:,i)=cpts(:,i)-ccent(i)*ones(n,1); wpts(:,i)=wpts(:,i)-wcent(i)*ones(n,1); end for i=1:n M=M+cpts(i,:)'*wpts(i,:); end [U S V]=svd(M); R=U*V'; if det(R)<0 R=-R; end T=ccent'-R*wcent'; % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [err,Urep]=reprojection_error_usingRT(Xw,U,R,T,A) %clear all; close all; load reprojection_error_usingRT; n=size(Xw,1); P=A*[R,T]; Xw_h=[Xw,ones(n,1)]; Urep_=(P*Xw_h')'; %project reference points into the image plane Urep=zeros(n,2); Urep(:,1)=Urep_(:,1)./Urep_(:,3); Urep(:,2)=Urep_(:,2)./Urep_(:,3); %reprojection error err_=sqrt((U(:,1)-Urep(:,1)).^2+(U(:,2)-Urep(:,2)).^2); err=sum(err_)/n;
github
rising-turtle/slam_matlab-master
robust_dls_pnp.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/dls_pnp_matlab/robust_dls_pnp.m
956
utf_8
884e74eace41c8ba00c468ea725dca02
function [C_est, t_est, cost, flag] = robust_dls_pnp(p, z) R = cat(3, rotx(pi/2), roty(pi/2), rotz(pi/2)); t = mean(p,2); cost = inf; for i = 1:3 % Make a random rotation pp = R(:,:,i) * (p - repmat(t, 1, size(p,2))); [C_est_i, t_est_i, cost_i, flag_i] = dls_pnp(pp, z); for j = 1:length(cost_i) t_est_i(:,j) = t_est_i(:,j) - C_est_i(:,:,j) * R(:,:,i) * t; C_est_i(:,:,j) = C_est_i(:,:,j) * R(:,:,i); end if min(cost_i) < min(cost) C_est = C_est_i; t_est = t_est_i; cost = cost_i; flag = flag_i; end end end function r = rotx(t) ct = cos(t); st = sin(t); r = [1 0 0; 0 ct -st; 0 st ct]; end function r = roty(t) % roty: rotation about y-axi- ct = cos(t); st = sin(t); r = [ct 0 st; 0 1 0; -st 0 ct]; end function r = rotz(t) % rotz: rotation about z-axis ct = cos(t); st = sin(t); r = [ct -st 0 st ct 0 0 0 1]; end
github
rising-turtle/slam_matlab-master
rws.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/dls_pnp_matlab/rws.m
1,946
utf_8
24dabc05143cbf2c126ab352eb83b32f
function [C, t, p, z] = rws(N, sigma) % this function generates a random camera pose, along with N random points, % and also the perspective projections of those points. % Generate a random global-to-camera rotation. This is the orientation of % the global frame expressed in the camera frame of refence. angle = 15; C = rotx(angle * randn * pi/180 ) * roty( angle * randn * pi/180 ); % Generate a random global-to-camera translation. This is the origin of the % global frame expressed in the camera frame. t = randn(3,1); % Create random 3D points within a 45 deg FOV (vertical and horizontal) of % the camera. The points are between 0.5 and 5.5 meters from the camera. Psens = zeros(3,N); theta = (rand(N,1)*45 - 22.5) * pi/180; phi = (rand(N,1)*45 - 22.5) * pi/180; for i = 1:N psens_unit = rotx(theta(i)) * roty(phi(i)) * [0;0;1]; alpha = rand * 5 + 0.5; Psens(:,i) = alpha * psens_unit; end % Express the points in the global frame of reference p = C' *(Psens - repmat(t,1,N)); % Construct the vector of perspective projections (i.e., image % measurements) of the points, z = zeros(2,N); for i = 1:N % create an instance of 2x1 pixel noise noise = sigma * randn(2,1); % You can uncomment the following lines in order to limit the noise to +/- % 3 sigma % % % if abs(noise(1)) > 3 * sigma % noise(1) = sign(noise(1)) * 3 * sigma; % end % if abs(noise(2)) > 3 * sigma % noise(2) = sign(noise(2)) * 3 * sigma; % end % Create the image measurement using the standard pinhole camera model z(:,i) = [ Psens(1,i) / Psens(3,i) ; Psens(2,i) / Psens(3,i)] + noise; end end function r = rotx(t) %rotx: rotation around the x-axis ct = cos(t); st = sin(t); r = [1 0 0; 0 ct -st; 0 st ct]; end function r = roty(t) % roty: rotation about y-axis ct = cos(t); st = sin(t); r = [ct 0 st; 0 1 0; -st 0 ct]; end
github
rising-turtle/slam_matlab-master
dls_pnp.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/dls_pnp_matlab/dls_pnp.m
52,158
utf_8
d6e96e3b74cc29c6f5ddd01bbdb2e1eb
function [C_est, t_est, cost, flag] = dls_pnp(p, z) % DLS-PnP: % % This function performs the DLS-PnP method introduced at ICCV 2011 % Joel A. Hesch and Stergios I. Roumeliotis. "A direct least-squares (dls) % solution for PnP". In Proc. of the Int. Conf. on Computer Vision, % Barcelona, Spain, November 6-13, 2011. % % inputs: % p: 3xN vector of 3D known point features % z: 2xN vector of correpsonding image measurements (calibrated) % Check the inputs if size(z,1) > size(z,2) || size(p,1) > size(p,2) fprintf('Usage: dls_pnp(p,z) \n p: 3xN matrix of 3D points \n z: 2xN matrix of corresponding 2D image measurements (normalized pixel coordinates)') end % make z into unit vectors from normalized pixel coords z = [z; ones(1,size(z,2))]; z = z./ repmat(sqrt(sum(z.*z,1)),3,1); % some preliminaries flag = 0; N = size(z,2); % build coeff matrix % An intermediate matrix, the inverse of what is called "H" in the paper % (see eq. 25) H = zeros(3); for i = 1:N H = H + eye(3) - z(:,i)*z(:,i)'; end A = zeros(3,9); for i = 1:N A = A + (z(:,i)*z(:,i)' - eye(3)) * LeftMultVec(p(:,i)); end A = H\A; D = zeros(9); for i = 1:N D = D + (LeftMultVec(p(:,i)) + A)' * (eye(3) - z(:,i)*z(:,i)') * (LeftMultVec(p(:,i)) + A); end f1coeff = [2*D(1,6) - 2*D(1,8) + 2*D(5,6) - 2*D(5,8) + 2*D(6,1) + 2*D(6,5) + 2*D(6,9) - 2*D(8,1) - 2*D(8,5) - 2*D(8,9) + 2*D(9,6) - 2*D(9,8); % constant term (6*D(1,2) + 6*D(1,4) + 6*D(2,1) - 6*D(2,5) - 6*D(2,9) + 6*D(4,1) - 6*D(4,5) - 6*D(4,9) - 6*D(5,2) - 6*D(5,4) - 6*D(9,2) - 6*D(9,4)); % s1^2 * s2 (4*D(1,7) - 4*D(1,3) + 8*D(2,6) - 8*D(2,8) - 4*D(3,1) + 4*D(3,5) + 4*D(3,9) + 8*D(4,6) - 8*D(4,8) + 4*D(5,3) - 4*D(5,7) + 8*D(6,2) + 8*D(6,4) + 4*D(7,1) - 4*D(7,5) - 4*D(7,9) - 8*D(8,2) - 8*D(8,4) + 4*D(9,3) - 4*D(9,7)); % s1 * s2 (4*D(1,2) - 4*D(1,4) + 4*D(2,1) - 4*D(2,5) - 4*D(2,9) + 8*D(3,6) - 8*D(3,8) - 4*D(4,1) + 4*D(4,5) + 4*D(4,9) - 4*D(5,2) + 4*D(5,4) + 8*D(6,3) + 8*D(6,7) + 8*D(7,6) - 8*D(7,8) - 8*D(8,3) - 8*D(8,7) - 4*D(9,2) + 4*D(9,4)); % s1 * s3 (8*D(2,2) - 8*D(3,3) - 8*D(4,4) + 8*D(6,6) + 8*D(7,7) - 8*D(8,8)); % s2 * s3 (4*D(2,6) - 2*D(1,7) - 2*D(1,3) + 4*D(2,8) - 2*D(3,1) + 2*D(3,5) - 2*D(3,9) + 4*D(4,6) + 4*D(4,8) + 2*D(5,3) + 2*D(5,7) + 4*D(6,2) + 4*D(6,4) - 2*D(7,1) + 2*D(7,5) - 2*D(7,9) + 4*D(8,2) + 4*D(8,4) - 2*D(9,3) - 2*D(9,7)); % s2^2 * s3 (2*D(2,5) - 2*D(1,4) - 2*D(2,1) - 2*D(1,2) - 2*D(2,9) - 2*D(4,1) + 2*D(4,5) - 2*D(4,9) + 2*D(5,2) + 2*D(5,4) - 2*D(9,2) - 2*D(9,4)); % s2^3 (4*D(1,9) - 4*D(1,1) + 8*D(3,3) + 8*D(3,7) + 4*D(5,5) + 8*D(7,3) + 8*D(7,7) + 4*D(9,1) - 4*D(9,9)); % s1 * s3^2 (4*D(1,1) - 4*D(5,5) - 4*D(5,9) + 8*D(6,6) - 8*D(6,8) - 8*D(8,6) + 8*D(8,8) - 4*D(9,5) - 4*D(9,9)); % s1 (2*D(1,3) + 2*D(1,7) + 4*D(2,6) - 4*D(2,8) + 2*D(3,1) + 2*D(3,5) + 2*D(3,9) - 4*D(4,6) + 4*D(4,8) + 2*D(5,3) + 2*D(5,7) + 4*D(6,2) - 4*D(6,4) + 2*D(7,1) + 2*D(7,5) + 2*D(7,9) - 4*D(8,2) + 4*D(8,4) + 2*D(9,3) + 2*D(9,7)); % s3 (2*D(1,2) + 2*D(1,4) + 2*D(2,1) + 2*D(2,5) + 2*D(2,9) - 4*D(3,6) + 4*D(3,8) + 2*D(4,1) + 2*D(4,5) + 2*D(4,9) + 2*D(5,2) + 2*D(5,4) - 4*D(6,3) + 4*D(6,7) + 4*D(7,6) - 4*D(7,8) + 4*D(8,3) - 4*D(8,7) + 2*D(9,2) + 2*D(9,4)); % s2 (2*D(2,9) - 2*D(1,4) - 2*D(2,1) - 2*D(2,5) - 2*D(1,2) + 4*D(3,6) + 4*D(3,8) - 2*D(4,1) - 2*D(4,5) + 2*D(4,9) - 2*D(5,2) - 2*D(5,4) + 4*D(6,3) + 4*D(6,7) + 4*D(7,6) + 4*D(7,8) + 4*D(8,3) + 4*D(8,7) + 2*D(9,2) + 2*D(9,4)); % s2 * s3^2 (6*D(1,6) - 6*D(1,8) - 6*D(5,6) + 6*D(5,8) + 6*D(6,1) - 6*D(6,5) - 6*D(6,9) - 6*D(8,1) + 6*D(8,5) + 6*D(8,9) - 6*D(9,6) + 6*D(9,8)); % s1^2 (2*D(1,8) - 2*D(1,6) + 4*D(2,3) + 4*D(2,7) + 4*D(3,2) - 4*D(3,4) - 4*D(4,3) - 4*D(4,7) - 2*D(5,6) + 2*D(5,8) - 2*D(6,1) - 2*D(6,5) + 2*D(6,9) + 4*D(7,2) - 4*D(7,4) + 2*D(8,1) + 2*D(8,5) - 2*D(8,9) + 2*D(9,6) - 2*D(9,8)); % s3^2 (2*D(1,8) - 2*D(1,6) - 4*D(2,3) + 4*D(2,7) - 4*D(3,2) - 4*D(3,4) - 4*D(4,3) + 4*D(4,7) + 2*D(5,6) - 2*D(5,8) - 2*D(6,1) + 2*D(6,5) - 2*D(6,9) + 4*D(7,2) + 4*D(7,4) + 2*D(8,1) - 2*D(8,5) + 2*D(8,9) - 2*D(9,6) + 2*D(9,8)); % s2^2 (2*D(3,9) - 2*D(1,7) - 2*D(3,1) - 2*D(3,5) - 2*D(1,3) - 2*D(5,3) - 2*D(5,7) - 2*D(7,1) - 2*D(7,5) + 2*D(7,9) + 2*D(9,3) + 2*D(9,7)); % s3^3 (4*D(1,6) + 4*D(1,8) + 8*D(2,3) + 8*D(2,7) + 8*D(3,2) + 8*D(3,4) + 8*D(4,3) + 8*D(4,7) - 4*D(5,6) - 4*D(5,8) + 4*D(6,1) - 4*D(6,5) - 4*D(6,9) + 8*D(7,2) + 8*D(7,4) + 4*D(8,1) - 4*D(8,5) - 4*D(8,9) - 4*D(9,6) - 4*D(9,8)); % s1 * s2 * s3 (4*D(1,5) - 4*D(1,1) + 8*D(2,2) + 8*D(2,4) + 8*D(4,2) + 8*D(4,4) + 4*D(5,1) - 4*D(5,5) + 4*D(9,9)); % s1 * s2^2 (6*D(1,3) + 6*D(1,7) + 6*D(3,1) - 6*D(3,5) - 6*D(3,9) - 6*D(5,3) - 6*D(5,7) + 6*D(7,1) - 6*D(7,5) - 6*D(7,9) - 6*D(9,3) - 6*D(9,7)); % s1^2 * s3 (4*D(1,1) - 4*D(1,5) - 4*D(1,9) - 4*D(5,1) + 4*D(5,5) + 4*D(5,9) - 4*D(9,1) + 4*D(9,5) + 4*D(9,9))]; % s1^3 f2coeff = [- 2*D(1,3) + 2*D(1,7) - 2*D(3,1) - 2*D(3,5) - 2*D(3,9) - 2*D(5,3) + 2*D(5,7) + 2*D(7,1) + 2*D(7,5) + 2*D(7,9) - 2*D(9,3) + 2*D(9,7); % constant term (4*D(1,5) - 4*D(1,1) + 8*D(2,2) + 8*D(2,4) + 8*D(4,2) + 8*D(4,4) + 4*D(5,1) - 4*D(5,5) + 4*D(9,9)); % s1^2 * s2 (4*D(1,8) - 4*D(1,6) - 8*D(2,3) + 8*D(2,7) - 8*D(3,2) - 8*D(3,4) - 8*D(4,3) + 8*D(4,7) + 4*D(5,6) - 4*D(5,8) - 4*D(6,1) + 4*D(6,5) - 4*D(6,9) + 8*D(7,2) + 8*D(7,4) + 4*D(8,1) - 4*D(8,5) + 4*D(8,9) - 4*D(9,6) + 4*D(9,8)); % s1 * s2 (8*D(2,2) - 8*D(3,3) - 8*D(4,4) + 8*D(6,6) + 8*D(7,7) - 8*D(8,8)); % s1 * s3 (4*D(1,4) - 4*D(1,2) - 4*D(2,1) + 4*D(2,5) - 4*D(2,9) - 8*D(3,6) - 8*D(3,8) + 4*D(4,1) - 4*D(4,5) + 4*D(4,9) + 4*D(5,2) - 4*D(5,4) - 8*D(6,3) + 8*D(6,7) + 8*D(7,6) + 8*D(7,8) - 8*D(8,3) + 8*D(8,7) - 4*D(9,2) + 4*D(9,4)); % s2 * s3 (6*D(5,6) - 6*D(1,8) - 6*D(1,6) + 6*D(5,8) - 6*D(6,1) + 6*D(6,5) - 6*D(6,9) - 6*D(8,1) + 6*D(8,5) - 6*D(8,9) - 6*D(9,6) - 6*D(9,8)); % s2^2 * s3 (4*D(1,1) - 4*D(1,5) + 4*D(1,9) - 4*D(5,1) + 4*D(5,5) - 4*D(5,9) + 4*D(9,1) - 4*D(9,5) + 4*D(9,9)); % s2^3 (2*D(2,9) - 2*D(1,4) - 2*D(2,1) - 2*D(2,5) - 2*D(1,2) + 4*D(3,6) + 4*D(3,8) - 2*D(4,1) - 2*D(4,5) + 2*D(4,9) - 2*D(5,2) - 2*D(5,4) + 4*D(6,3) + 4*D(6,7) + 4*D(7,6) + 4*D(7,8) + 4*D(8,3) + 4*D(8,7) + 2*D(9,2) + 2*D(9,4)); % s1 * s3^2 (2*D(1,2) + 2*D(1,4) + 2*D(2,1) + 2*D(2,5) + 2*D(2,9) - 4*D(3,6) + 4*D(3,8) + 2*D(4,1) + 2*D(4,5) + 2*D(4,9) + 2*D(5,2) + 2*D(5,4) - 4*D(6,3) + 4*D(6,7) + 4*D(7,6) - 4*D(7,8) + 4*D(8,3) - 4*D(8,7) + 2*D(9,2) + 2*D(9,4)); % s1 (2*D(1,6) + 2*D(1,8) - 4*D(2,3) + 4*D(2,7) - 4*D(3,2) + 4*D(3,4) + 4*D(4,3) - 4*D(4,7) + 2*D(5,6) + 2*D(5,8) + 2*D(6,1) + 2*D(6,5) + 2*D(6,9) + 4*D(7,2) - 4*D(7,4) + 2*D(8,1) + 2*D(8,5) + 2*D(8,9) + 2*D(9,6) + 2*D(9,8)); % s3 (8*D(3,3) - 4*D(1,9) - 4*D(1,1) - 8*D(3,7) + 4*D(5,5) - 8*D(7,3) + 8*D(7,7) - 4*D(9,1) - 4*D(9,9)); % s2 (4*D(1,1) - 4*D(5,5) + 4*D(5,9) + 8*D(6,6) + 8*D(6,8) + 8*D(8,6) + 8*D(8,8) + 4*D(9,5) - 4*D(9,9)); % s2 * s3^2 (2*D(1,7) - 2*D(1,3) + 4*D(2,6) - 4*D(2,8) - 2*D(3,1) + 2*D(3,5) + 2*D(3,9) + 4*D(4,6) - 4*D(4,8) + 2*D(5,3) - 2*D(5,7) + 4*D(6,2) + 4*D(6,4) + 2*D(7,1) - 2*D(7,5) - 2*D(7,9) - 4*D(8,2) - 4*D(8,4) + 2*D(9,3) - 2*D(9,7)); % s1^2 (2*D(1,3) - 2*D(1,7) + 4*D(2,6) + 4*D(2,8) + 2*D(3,1) + 2*D(3,5) - 2*D(3,9) - 4*D(4,6) - 4*D(4,8) + 2*D(5,3) - 2*D(5,7) + 4*D(6,2) - 4*D(6,4) - 2*D(7,1) - 2*D(7,5) + 2*D(7,9) + 4*D(8,2) - 4*D(8,4) - 2*D(9,3) + 2*D(9,7)); % s3^2 (6*D(1,3) - 6*D(1,7) + 6*D(3,1) - 6*D(3,5) + 6*D(3,9) - 6*D(5,3) + 6*D(5,7) - 6*D(7,1) + 6*D(7,5) - 6*D(7,9) + 6*D(9,3) - 6*D(9,7)); % s2^2 (2*D(6,9) - 2*D(1,8) - 2*D(5,6) - 2*D(5,8) - 2*D(6,1) - 2*D(6,5) - 2*D(1,6) - 2*D(8,1) - 2*D(8,5) + 2*D(8,9) + 2*D(9,6) + 2*D(9,8)); % s3^3 (8*D(2,6) - 4*D(1,7) - 4*D(1,3) + 8*D(2,8) - 4*D(3,1) + 4*D(3,5) - 4*D(3,9) + 8*D(4,6) + 8*D(4,8) + 4*D(5,3) + 4*D(5,7) + 8*D(6,2) + 8*D(6,4) - 4*D(7,1) + 4*D(7,5) - 4*D(7,9) + 8*D(8,2) + 8*D(8,4) - 4*D(9,3) - 4*D(9,7)); % s1 * s2 * s3 (6*D(2,5) - 6*D(1,4) - 6*D(2,1) - 6*D(1,2) - 6*D(2,9) - 6*D(4,1) + 6*D(4,5) - 6*D(4,9) + 6*D(5,2) + 6*D(5,4) - 6*D(9,2) - 6*D(9,4)); % s1 * s2^2 (2*D(1,6) + 2*D(1,8) + 4*D(2,3) + 4*D(2,7) + 4*D(3,2) + 4*D(3,4) + 4*D(4,3) + 4*D(4,7) - 2*D(5,6) - 2*D(5,8) + 2*D(6,1) - 2*D(6,5) - 2*D(6,9) + 4*D(7,2) + 4*D(7,4) + 2*D(8,1) - 2*D(8,5) - 2*D(8,9) - 2*D(9,6) - 2*D(9,8)); % s1^2 * s3 (2*D(1,2) + 2*D(1,4) + 2*D(2,1) - 2*D(2,5) - 2*D(2,9) + 2*D(4,1) - 2*D(4,5) - 2*D(4,9) - 2*D(5,2) - 2*D(5,4) - 2*D(9,2) - 2*D(9,4))]; % s1^3 f3coeff = [2*D(1,2) - 2*D(1,4) + 2*D(2,1) + 2*D(2,5) + 2*D(2,9) - 2*D(4,1) - 2*D(4,5) - 2*D(4,9) + 2*D(5,2) - 2*D(5,4) + 2*D(9,2) - 2*D(9,4); % constant term (2*D(1,6) + 2*D(1,8) + 4*D(2,3) + 4*D(2,7) + 4*D(3,2) + 4*D(3,4) + 4*D(4,3) + 4*D(4,7) - 2*D(5,6) - 2*D(5,8) + 2*D(6,1) - 2*D(6,5) - 2*D(6,9) + 4*D(7,2) + 4*D(7,4) + 2*D(8,1) - 2*D(8,5) - 2*D(8,9) - 2*D(9,6) - 2*D(9,8)); % s1^2 * s2 (8*D(2,2) - 8*D(3,3) - 8*D(4,4) + 8*D(6,6) + 8*D(7,7) - 8*D(8,8)); % s1 * s2 (4*D(1,8) - 4*D(1,6) + 8*D(2,3) + 8*D(2,7) + 8*D(3,2) - 8*D(3,4) - 8*D(4,3) - 8*D(4,7) - 4*D(5,6) + 4*D(5,8) - 4*D(6,1) - 4*D(6,5) + 4*D(6,9) + 8*D(7,2) - 8*D(7,4) + 4*D(8,1) + 4*D(8,5) - 4*D(8,9) + 4*D(9,6) - 4*D(9,8)); % s1 * s3 (4*D(1,3) - 4*D(1,7) + 8*D(2,6) + 8*D(2,8) + 4*D(3,1) + 4*D(3,5) - 4*D(3,9) - 8*D(4,6) - 8*D(4,8) + 4*D(5,3) - 4*D(5,7) + 8*D(6,2) - 8*D(6,4) - 4*D(7,1) - 4*D(7,5) + 4*D(7,9) + 8*D(8,2) - 8*D(8,4) - 4*D(9,3) + 4*D(9,7)); % s2 * s3 (4*D(1,1) - 4*D(5,5) + 4*D(5,9) + 8*D(6,6) + 8*D(6,8) + 8*D(8,6) + 8*D(8,8) + 4*D(9,5) - 4*D(9,9)); % s2^2 * s3 (2*D(5,6) - 2*D(1,8) - 2*D(1,6) + 2*D(5,8) - 2*D(6,1) + 2*D(6,5) - 2*D(6,9) - 2*D(8,1) + 2*D(8,5) - 2*D(8,9) - 2*D(9,6) - 2*D(9,8)); % s2^3 (6*D(3,9) - 6*D(1,7) - 6*D(3,1) - 6*D(3,5) - 6*D(1,3) - 6*D(5,3) - 6*D(5,7) - 6*D(7,1) - 6*D(7,5) + 6*D(7,9) + 6*D(9,3) + 6*D(9,7)); % s1 * s3^2 (2*D(1,3) + 2*D(1,7) + 4*D(2,6) - 4*D(2,8) + 2*D(3,1) + 2*D(3,5) + 2*D(3,9) - 4*D(4,6) + 4*D(4,8) + 2*D(5,3) + 2*D(5,7) + 4*D(6,2) - 4*D(6,4) + 2*D(7,1) + 2*D(7,5) + 2*D(7,9) - 4*D(8,2) + 4*D(8,4) + 2*D(9,3) + 2*D(9,7)); % s1 (8*D(2,2) - 4*D(1,5) - 4*D(1,1) - 8*D(2,4) - 8*D(4,2) + 8*D(4,4) - 4*D(5,1) - 4*D(5,5) + 4*D(9,9)); % s3 (2*D(1,6) + 2*D(1,8) - 4*D(2,3) + 4*D(2,7) - 4*D(3,2) + 4*D(3,4) + 4*D(4,3) - 4*D(4,7) + 2*D(5,6) + 2*D(5,8) + 2*D(6,1) + 2*D(6,5) + 2*D(6,9) + 4*D(7,2) - 4*D(7,4) + 2*D(8,1) + 2*D(8,5) + 2*D(8,9) + 2*D(9,6) + 2*D(9,8)); % s2 (6*D(6,9) - 6*D(1,8) - 6*D(5,6) - 6*D(5,8) - 6*D(6,1) - 6*D(6,5) - 6*D(1,6) - 6*D(8,1) - 6*D(8,5) + 6*D(8,9) + 6*D(9,6) + 6*D(9,8)); % s2 * s3^2 (2*D(1,2) - 2*D(1,4) + 2*D(2,1) - 2*D(2,5) - 2*D(2,9) + 4*D(3,6) - 4*D(3,8) - 2*D(4,1) + 2*D(4,5) + 2*D(4,9) - 2*D(5,2) + 2*D(5,4) + 4*D(6,3) + 4*D(6,7) + 4*D(7,6) - 4*D(7,8) - 4*D(8,3) - 4*D(8,7) - 2*D(9,2) + 2*D(9,4)); % s1^2 (6*D(1,4) - 6*D(1,2) - 6*D(2,1) - 6*D(2,5) + 6*D(2,9) + 6*D(4,1) + 6*D(4,5) - 6*D(4,9) - 6*D(5,2) + 6*D(5,4) + 6*D(9,2) - 6*D(9,4)); % s3^2 (2*D(1,4) - 2*D(1,2) - 2*D(2,1) + 2*D(2,5) - 2*D(2,9) - 4*D(3,6) - 4*D(3,8) + 2*D(4,1) - 2*D(4,5) + 2*D(4,9) + 2*D(5,2) - 2*D(5,4) - 4*D(6,3) + 4*D(6,7) + 4*D(7,6) + 4*D(7,8) - 4*D(8,3) + 4*D(8,7) - 2*D(9,2) + 2*D(9,4)); % s2^2 (4*D(1,1) + 4*D(1,5) - 4*D(1,9) + 4*D(5,1) + 4*D(5,5) - 4*D(5,9) - 4*D(9,1) - 4*D(9,5) + 4*D(9,9)); % s3^3 (4*D(2,9) - 4*D(1,4) - 4*D(2,1) - 4*D(2,5) - 4*D(1,2) + 8*D(3,6) + 8*D(3,8) - 4*D(4,1) - 4*D(4,5) + 4*D(4,9) - 4*D(5,2) - 4*D(5,4) + 8*D(6,3) + 8*D(6,7) + 8*D(7,6) + 8*D(7,8) + 8*D(8,3) + 8*D(8,7) + 4*D(9,2) + 4*D(9,4)); % s1 * s2 * s3 (4*D(2,6) - 2*D(1,7) - 2*D(1,3) + 4*D(2,8) - 2*D(3,1) + 2*D(3,5) - 2*D(3,9) + 4*D(4,6) + 4*D(4,8) + 2*D(5,3) + 2*D(5,7) + 4*D(6,2) + 4*D(6,4) - 2*D(7,1) + 2*D(7,5) - 2*D(7,9) + 4*D(8,2) + 4*D(8,4) - 2*D(9,3) - 2*D(9,7)); % s1 * s2^2 (4*D(1,9) - 4*D(1,1) + 8*D(3,3) + 8*D(3,7) + 4*D(5,5) + 8*D(7,3) + 8*D(7,7) + 4*D(9,1) - 4*D(9,9)); % s1^2 * s3 (2*D(1,3) + 2*D(1,7) + 2*D(3,1) - 2*D(3,5) - 2*D(3,9) - 2*D(5,3) - 2*D(5,7) + 2*D(7,1) - 2*D(7,5) - 2*D(7,9) - 2*D(9,3) - 2*D(9,7))]; % s1^3 % Construct the Macaulay matrix % u0 = round(randn(1)*100); % u1 = round(randn(1)*100); % u2 = round(randn(1)*100); % u3 = round(randn(1)*100); %M2 = cayley_LS_M(f1coeff, f2coeff, f3coeff,u0,u1,u2,u3); u = round(randn(4,1) * 100); M2 = cayley_LS_M(f1coeff, f2coeff, f3coeff,u); % construct the multiplication matrix via schur compliment of the Macaulay % matrix Mtilde = M2(1:27,1:27) - M2(1:27,28:120)/M2(28:120,28:120)*M2(28:120,1:27); [V,~] = eig(Mtilde); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Now check the solutions %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % extract the optimal solutions from the eigen decomposition of the % Multiplication matrix sols = zeros(3,27); cost = zeros(27,1); i = 1; for k = 1:27 V(:,k) = V(:,k)/V(1,k); if (imag(V(2,k)) == 0) stmp = V([10 4 2],k); H = Hessian(f1coeff, f2coeff, f3coeff, stmp); if eig(H) > 0 sols(:,i) = stmp; Cbar = cayley2rotbar(stmp); CbarVec = Cbar'; CbarVec = CbarVec(:); cost(i) = CbarVec' * D * CbarVec; i = i+1; end end end sols = sols(:,1:i-1); cost = cost(1:i-1); C_est = zeros(3,3,size(sols,2)); t_est = zeros(3, size(sols,2)); for j = 1:size(sols,2) % recover the optimal orientation C_est(:,:,j) = 1/(1 + sols(:,j)' * sols(:,j)) * cayley2rotbar(sols(:,j)); A2 = zeros(3); for i = 1:N A2 = A2 + eye(3) - z(:,i)*z(:,i)'; end b2 = zeros(3,1); for i = 1:N b2 = b2 + (z(:,i)*z(:,i)' - eye(3)) * C_est(:,:,j) * p(:,i); end % recover the optimal translation t_est(:,j) = A2\b2; end % check that the points are infront of the center of perspectivity sols_valid = []; for k = 1:size(sols,2) cam_points = C_est(:,:,k) * p + repmat(t_est(:,k),1, length(p)); if isempty(find(cam_points(3,:) < 0)) sols_valid = [sols_valid; k]; end end t_est = t_est(:,sols_valid); C_est = C_est(:,:,sols_valid); cost = cost(sols_valid); end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Some helper functions %% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function C = cayley2rotbar(s) C = ( (1-s'*s) * eye(3) + 2 * skewsymm(s) + 2 * (s * s'))'; end function C = skewsymm(X1) % generates skew symmetric matrix C = [0 , -X1(3) , X1(2) X1(3) , 0 , -X1(1) -X1(2) , X1(1) , 0]; end function M = LeftMultVec(v) % R * p = LeftMultVec(p) * vec(R) M = [v' zeros(1,6); zeros(1,3) v' zeros(1,3); zeros(1,6) v']; end function M = cayley_LS_M(a,b,c,u) %,u1,u2,u3) % Construct the Macaulay resultant matrix M = [u(1) 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 0 a(1) 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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0 0 0 0 0 0 0 0 0 0 b(1) b(9) b(13) b(2) 0 b(11) b(3) 0 0 b(15) 0 b(18) 0 0 c(15) c(18) 0 0 0 c(11) c(1) c(9) 0 c(3) 0 0 0 0 0 0 0 0 0 0 c(13) 0 0 0 0 0 0 0 0 0 0 0 c(2); 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u(2) 0 0 0 0 0 u(3) 0 u(4) u(1) 0 0 0 a(4) a(19) 0 a(15) a(18) 0 0 0 0 a(5) a(17) a(11) 0 0 a(2) a(9) a(13) 0 a(3) 0 0 0 0 a(10) a(6) 0 0 0 0 0 b(18) b(3) b(15) 0 b(13) 0 0 0 0 b(9) 0 0 b(2) b(11) b(10) b(4) b(19) 0 0 b(5) b(17) 0 0 b(6) 0 0 0 0 c(6) 0 0 c(3) 0 c(5) c(10) c(4) c(11) c(17) c(9) 0 0 c(2) 0 0 0 0 0 0 c(19) 0 0 0 0 c(13) 0 0 0 c(15) c(18) 0 0; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u(2) 0 0 0 0 0 u(3) 0 u(4) u(1) a(15) a(18) a(8) 0 0 a(6) 0 0 0 0 0 a(12) 0 a(5) a(2) a(3) 0 a(4) a(19) a(13) a(17) 0 0 0 0 a(14) 0 0 b(15) b(3) b(18) 0 0 b(17) b(6) b(2) b(19) 0 0 b(13) 0 b(4) 0 0 0 b(5) b(14) b(8) 0 0 0 b(12) 0 0 0 0 0 0 0 0 0 0 0 c(17) 0 c(12) c(14) c(8) c(5) 0 c(4) 0 0 0 0 c(13) 0 0 0 c(3) 0 0 0 0 c(2) c(19) c(15) c(18) 0 c(6) 0 0 0; 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 u(3) 0 0 0 0 0 0 0 0 0 0 0 0 0 a(11) a(3) 0 0 0 0 0 a(7) 0 0 a(15) 0 0 0 0 0 0 0 0 0 a(18) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 b(9) b(1) 0 0 0 b(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0 0 0 0 c(13) c(20) c(4) c(19) 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 a(20) 0 0 0 a(19) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 a(8) 0 0 0 0 0 0 b(20) 0 0 b(19) 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 b(8) 0 0 0 c(8) 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 c(20) 0 c(19) 0 0 0 0]'; end function [H] = Hessian(f1coeff, f2coeff, f3coeff, s) % the vector of monomials is % m = [ const ; s1^2 * s2 ; s1 * s2 ; s1 * s3 ; s2 * s3 ; s2^2 * s3 ; s2^3 ; ... % s1 * s3^2 ; s1 ; s3 ; s2 ; s2 * s3^2 ; s1^2 ; s3^2 ; s2^2 ; s3^3 ; ... % s1 * s2 * s3 ; s1 * s2^2 ; s1^2 * s3 ; s1^3] % % deriv of m w.r.t. s1 Hs1 = [0 ; 2 * s(1) * s(2) ; s(2) ; s(3) ; 0 ; 0 ; 0 ; ... s(3)^2 ; 1 ; 0 ; 0 ; 0 ; 2 * s(1) ; 0 ; 0 ; 0 ; ... s(2) * s(3) ; s(2)^2 ; 2*s(1)*s(3); 3 * s(1)^2]; % deriv of m w.r.t. s2 Hs2 = [0 ; s(1)^2 ; s(1) ; 0 ; s(3) ; 2 * s(2) * s(3) ; 3 * s(2)^2 ; ... 0 ; 0 ; 0 ; 1 ; s(3)^2 ; 0 ; 0 ; 2 * s(2) ; 0 ; ... s(1) * s(3) ; s(1) * 2 * s(2) ; 0 ; 0]; % deriv of m w.r.t. s3 Hs3 = [0 ; 0 ; 0 ; s(1) ; s(2) ; s(2)^2 ; 0 ; ... s(1) * 2 * s(3) ; 0 ; 1 ; 0 ; s(2) * 2 * s(3) ; 0 ; 2 * s(3) ; 0 ; 3 * s(3)^2 ; ... s(1) * s(2) ; 0 ; s(1)^2 ; 0]; H = [ f1coeff' * Hs1 , f1coeff' * Hs2 , f1coeff' * Hs3; f2coeff' * Hs1 , f2coeff' * Hs2 , f2coeff' * Hs3; f3coeff' * Hs1 , f3coeff' * Hs2 , f3coeff' * Hs3]; end %function [C] = cayley2rot(s) % C = ( (1-s'*s) * eye(3) + 2 * skewsymm(s) + 2 * s * s')' / ( 1 + s' * s); %end
github
rising-turtle/slam_matlab-master
compute_error.m
.m
slam_matlab-master/libs_dir/plane_fitting_code/all/dls_pnp_matlab/compute_error.m
1,320
utf_8
9661477a57e8c1cd36f99c33566fb9ba
function [da, dt] = compute_error(C, t, Cm, tm) % compute the error quaternion btw. the true and the estimated solutions % (using JPL definition of quaternions) q_del = rot2quat(C' * Cm); % compute the tilt angle error da = norm(q_del(1:3) * 2); % compute the position error dt = norm(t - tm); end function q = rot2quat(R) % converts a rotational matrix to a unit quaternion, according to JPL % procedure (Breckenridge Memo) T = trace(R); [dummy maxpivot] = max([R(1,1) R(2,2) R(3,3) T]); %#ok<ASGLU> switch maxpivot case 1 q(1) = sqrt((1+2*R(1,1)-T)/4); q(2:4) = 1/(4*q(1)) * [R(1,2)+R(2,1); R(1,3)+R(3,1); R(2,3)-R(3,2) ]; case 2 q(2) = sqrt((1+2*R(2,2)-T)/4); q([1 3 4]) = 1/(4*q(2)) * [R(1,2)+R(2,1); R(2,3)+R(3,2); R(3,1)-R(1,3) ]; case 3 q(3) = sqrt((1+2*R(3,3)-T)/4); q([1 2 4]) = 1/(4*q(3)) * [R(1,3)+R(3,1); R(2,3)+R(3,2); R(1,2)-R(2,1) ]; case 4 q(4) = sqrt((1+T)/4); q(1:3) = 1/(4*q(4)) * [R(2,3)-R(3,2); R(3,1)-R(1,3); R(1,2)-R(2,1) ]; end % switch % make column vector q = q(:); % 4th element is always positive if q(4)<0 q = -q; end % quaternion normalization q = q/sqrt(q'*q); end
github
rising-turtle/slam_matlab-master
gtsamExamples.m
.m
slam_matlab-master/libs_dir/gtsam-toolbox-2.3.0-win64/toolbox/gtsam_examples/gtsamExamples.m
5,664
utf_8
f2621b78fabdb370c4f63d5e0309b7e9
function varargout = gtsamExamples(varargin) % GTSAMEXAMPLES MATLAB code for gtsamExamples.fig % GTSAMEXAMPLES, by itself, creates a new GTSAMEXAMPLES or raises the existing % singleton*. % % H = GTSAMEXAMPLES returns the handle to a new GTSAMEXAMPLES or the handle to % the existing singleton*. % % GTSAMEXAMPLES('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in GTSAMEXAMPLES.M with the given input arguments. % % GTSAMEXAMPLES('Property','Value',...) creates a new GTSAMEXAMPLES or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before gtsamExamples_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to gtsamExamples_OpeningFcn via varargin. % % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one % instance to run (singleton)". % % See also: GUIDE, GUIDATA, GUIHANDLES % Edit the above text to modify the response to help gtsamExamples % Last Modified by GUIDE v2.5 03-Sep-2012 13:34:13 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gtsamExamples_OpeningFcn, ... 'gui_OutputFcn', @gtsamExamples_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before gtsamExamples is made visible. function gtsamExamples_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to gtsamExamples (see VARARGIN) % Choose default command line output for gtsamExamples handles.output = hObject; % Update handles structure guidata(hObject, handles); OdometryExample; % --- Outputs from this function are returned to the command line. function varargout = gtsamExamples_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % -------------------------------------------------------------------- function CloseMenuItem_Callback(hObject, eventdata, handles) % hObject handle to CloseMenuItem (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],... ['Close ' get(handles.figure1,'Name') '...'],... 'Yes','No','Yes'); if strcmp(selection,'No') return; end delete(handles.figure1) % --- Executes on button press in Odometry. function Odometry_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on OdometryExample; echo off % --- Executes on button press in Localization. function Localization_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on LocalizationExample; echo off % --- Executes on button press in Pose2SLAM. function Pose2SLAM_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on Pose2SLAMExample echo off % --- Executes on button press in Pose2SLAMCircle. function Pose2SLAMCircle_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on Pose2SLAMExample_circle echo off % --- Executes on button press in Pose2SLAMManhattan. function Pose2SLAMManhattan_Callback(hObject, eventdata, handles) axes(handles.axes3); Pose2SLAMExample_graph % --- Executes on button press in Pose3SLAM. function Pose3SLAM_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on Pose3SLAMExample echo off % --- Executes on button press in Pose3SLAMSphere. function Pose3SLAMSphere_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on Pose3SLAMExample_graph echo off % --- Executes on button press in PlanarSLAM. function PlanarSLAM_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on PlanarSLAMExample echo off % --- Executes on button press in PlanarSLAMSampling. function PlanarSLAMSampling_Callback(hObject, eventdata, handles) axes(handles.axes3); PlanarSLAMExample_sampling % --- Executes on button press in PlanarSLAMGraph. function PlanarSLAMGraph_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on PlanarSLAMExample_graph echo off % --- Executes on button press in SFM. function SFM_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on SFMExample echo off % --- Executes on button press in VisualISAM. function VisualISAM_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on VisualISAMExample echo off % --- Executes on button press in StereoVO. function StereoVO_Callback(hObject, eventdata, handles) axes(handles.axes3); echo on StereoVOExample echo off % --- Executes on button press in StereoVOLarge. function StereoVOLarge_Callback(hObject, eventdata, handles) axes(handles.axes3); StereoVOExample_large
github
rising-turtle/slam_matlab-master
VisualISAM_gui.m
.m
slam_matlab-master/libs_dir/gtsam-toolbox-2.3.0-win64/toolbox/gtsam_examples/VisualISAM_gui.m
10,009
utf_8
ed501f5a7d855d179385d3bb29e65500
function varargout = VisualISAM_gui(varargin) % VisualISAM_gui: runs VisualSLAM iSAM demo in GUI % Interface is defined by VisualISAM_gui.fig % You can run this file directly, but won't have access to globals % By running ViusalISAMDemo, you see all variables in command prompt % Authors: Duy Nguyen Ta % Last Modified by GUIDE v2.5 13-Jun-2012 23:15:43 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @VisualISAM_gui_OpeningFcn, ... 'gui_OutputFcn', @VisualISAM_gui_OutputFcn, ... 'gui_LayoutFcn', [] , ... 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end % End initialization code - DO NOT EDIT % --- Executes just before VisualISAM_gui is made visible. function VisualISAM_gui_OpeningFcn(hObject, ~, handles, varargin) % This function has no output args, see OutputFcn. % varargin command line arguments to VisualISAM_gui (see VARARGIN) % Choose default command line output for VisualISAM_gui handles.output = hObject; % Update handles structure guidata(hObject, handles); % --- Outputs from this function are returned to the command line. function varargout = VisualISAM_gui_OutputFcn(hObject, ~, handles) % varargout cell array for returning output args (see VARARGOUT); % Get default command line output from handles structure varargout{1} = handles.output; %---------------------------------------------------------- % Convenient functions %---------------------------------------------------------- function showFramei(hObject, handles) global frame_i set(handles.frameStatus, 'String', sprintf('Frame: %d',frame_i)); drawnow guidata(hObject, handles); function showWaiting(handles, status) set(handles.waitingStatus,'String', status); drawnow guidata(handles.waitingStatus, handles); function triangle = chooseDataset(handles) str = cellstr(get(handles.dataset,'String')); sel = get(handles.dataset,'Value'); switch str{sel} case 'triangle' triangle = true; case 'cube' triangle = false; end function initOptions(handles) global options % Data options options.triangle = chooseDataset(handles); options.nrCameras = str2num(get(handles.numCamEdit,'String')); options.showImages = get(handles.showImagesCB,'Value'); % iSAM Options options.hardConstraint = get(handles.hardConstraintCB,'Value'); options.pointPriors = get(handles.pointPriorsCB,'Value'); options.batchInitialization = get(handles.batchInitCB,'Value'); %options.reorderInterval = str2num(get(handles.reorderIntervalEdit,'String')); options.alwaysRelinearize = get(handles.alwaysRelinearizeCB,'Value'); % Display Options options.saveDotFile = get(handles.saveGraphCB,'Value'); options.printStats = get(handles.printStatsCB,'Value'); options.drawInterval = str2num(get(handles.drawInterval,'String')); options.cameraInterval = str2num(get(handles.cameraIntervalEdit,'String')); options.drawTruePoses = get(handles.drawTruePosesCB,'Value'); options.saveFigures = get(handles.saveFiguresCB,'Value'); options.saveDotFiles = get(handles.saveGraphsCB,'Value'); %---------------------------------------------------------- % Callback functions for GUI elements %---------------------------------------------------------- % --- Executes during object creation, after setting all properties. function dataset_CreateFcn(hObject, ~, handles) % handles empty - handles not created until after all CreateFcns called % Hint: popupmenu controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on selection change in dataset. function dataset_Callback(hObject, ~, handles) % Hints: contents = cellstr(get(hObject,'String')) returns dataset contents as cell array % contents{get(hObject,'Value')} returns selected item from dataset % --- Executes during object creation, after setting all properties. function numCamEdit_CreateFcn(hObject, ~, handles) % Hint: edit controls usually have a white background on Windows. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function numCamEdit_Callback(hObject, ~, handles) % Hints: get(hObject,'String') returns contents of numCamEdit as text % str2double(get(hObject,'String')) returns contents of numCamEdit as a double % --- Executes on button press in showImagesCB. function showImagesCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of showImagesCB % --- Executes on button press in hardConstraintCB. function hardConstraintCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of hardConstraintCB % --- Executes on button press in pointPriorsCB. function pointPriorsCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of pointPriorsCB % --- Executes during object creation, after setting all properties. function batchInitCB_CreateFcn(hObject, eventdata, handles) set(hObject,'Value',1); % --- Executes on button press in batchInitCB. function batchInitCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of batchInitCB % --- Executes on button press in alwaysRelinearizeCB. function alwaysRelinearizeCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of alwaysRelinearizeCB % --- Executes during object creation, after setting all properties. function reorderIntervalText_CreateFcn(hObject, ~, handles) % Hint: edit controls usually have a white background on Windows. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes during object creation, after setting all properties. function reorderIntervalEdit_CreateFcn(hObject, ~, handles) % Hint: edit controls usually have a white background on Windows. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes during object creation, after setting all properties. function drawInterval_CreateFcn(hObject, ~, handles) % Hint: edit controls usually have a white background on Windows. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function drawInterval_Callback(hObject, ~, handles) % Hints: get(hObject,'String') returns contents of drawInterval as text % str2double(get(hObject,'String')) returns contents of drawInterval as a double function cameraIntervalEdit_Callback(hObject, ~, handles) % Hints: get(hObject,'String') returns contents of cameraIntervalEdit as text % str2double(get(hObject,'String')) returns contents of cameraIntervalEdit as a double % --- Executes during object creation, after setting all properties. function cameraIntervalEdit_CreateFcn(hObject, ~, handles) % Hint: edit controls usually have a white background on Windows. % See ISPC and COMPUTER. if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in saveGraphCB. function saveGraphCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of saveGraphCB % --- Executes on button press in printStatsCB. function printStatsCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of printStatsCB % --- Executes on button press in drawTruePosesCB. function drawTruePosesCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of drawTruePosesCB % --- Executes on button press in saveFiguresCB. function saveFiguresCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of saveFiguresCB % --- Executes on button press in saveGraphsCB. function saveGraphsCB_Callback(hObject, ~, handles) % Hint: get(hObject,'Value') returns toggle state of saveGraphsCB % --- Executes on button press in intializeButton. function intializeButton_Callback(hObject, ~, handles) global frame_i truth data noiseModels isam result nextPoseIndex options % initialize global options initOptions(handles) % Generate Data [data,truth] = gtsam.VisualISAMGenerateData(options); % Initialize and plot [noiseModels,isam,result,nextPoseIndex] = gtsam.VisualISAMInitialize(data,truth,options); cla gtsam.VisualISAMPlot(truth, data, isam, result, options) frame_i = 2; showFramei(hObject, handles) % --- Executes on button press in runButton. function runButton_Callback(hObject, ~, handles) global frame_i truth data noiseModels isam result nextPoseIndex options while (frame_i<size(truth.cameras,2)) frame_i = frame_i+1; showFramei(hObject, handles) [isam,result,nextPoseIndex] = gtsam.VisualISAMStep(data,noiseModels,isam,result,truth,nextPoseIndex); if mod(frame_i,options.drawInterval)==0 showWaiting(handles, 'Computing marginals...'); gtsam.VisualISAMPlot(truth, data, isam, result, options) showWaiting(handles, ''); end end % --- Executes on button press in stepButton. function stepButton_Callback(hObject, ~, handles) global frame_i truth data noiseModels isam result nextPoseIndex options if (frame_i<size(truth.cameras,2)) frame_i = frame_i+1; showFramei(hObject, handles) [isam,result,nextPoseIndex] = gtsam.VisualISAMStep(data,noiseModels,isam,result,truth,nextPoseIndex); showWaiting(handles, 'Computing marginals...'); gtsam.VisualISAMPlot(truth, data, isam, result, options) showWaiting(handles, ''); end
github
rising-turtle/slam_matlab-master
find_pair_tp.m
.m
slam_matlab-master/ground_truth_zh/find_pair_tp.m
4,069
utf_8
48cda0aca2320418530334c250c0cc24
% Find pairs between two 3D point sets by using T pattern % % Author : Soonhac Hong ([email protected]) % Date : 2/18/14 % % Input : gt_total : [time_stamp [x y z]*5] function [ gt_total_pair ] = find_pair_tp( gt_total ) %UNTITLED Summary of this function goes here % Detailed explanation goes here %addpath('..\icp'); %addpath('D:\Soonhac\SW\icp'); % original code %addpath('C:\Yiming\ground_truth_soonhac\icp'); % added by Yimin Zhao on @06/12/2015$ % figure; plot_colors={'b.','r.','g.','m.','c.'}; %gt_total_pair=gt_total(1,:); % copy the first data for i=1:size(gt_total,1) %new_gt = []; gt_total_pair(i,1) = gt_total(i,1); min_idx_prev=[]; prev=[]; cur=[]; distance=[]; for j=1:5 %prev = [prev; gt_total_pair(i-1,2+(j-1)*3:4+(j-1)*3)]; cur = [cur; gt_total(i,2+(j-1)*3:4+(j-1)*3)]; end % Find T pattern cur_idx =[]; cur_mean = mean(cur); for k=1:5 distance(k) = norm(cur(k,:) - cur_mean); end [~, sort_idx] = sort(distance); cur_idx(1:2,1) = [sort_idx(1);sort_idx(2)]; temp_cur_1 = cur(sort_idx(1),:); temp_cur_2 = cur(sort_idx(2),:); v1 = temp_cur_2-temp_cur_1; for k=3:5 %three_markers=[temp_cur_1;temp_cur_2;cur(sort_idx(k),:)]; v=cur(sort_idx(k),:)- temp_cur_1; theta(k-2) = asin(norm(cross(v,v1))/(norm(v)*norm(v1))); %d(k-2)=det(cross(v1,v)); %[plane error]= fit([three_markers(:,1),three_markers(:,2)],three_markers(:,3),'poly11'); %fit_error(k-2) = error.sse; end [~, min_idx] = min(theta); temp_cur_3 = cur(sort_idx(min_idx+2),:); cur_idx(3,1) = sort_idx(min_idx+2); if norm(diff([temp_cur_1;temp_cur_3])) > norm(diff([temp_cur_2;temp_cur_3])) cur_idx(1:2,1) = sort_idx(1:2); else cur_idx(1,1) = sort_idx(2); cur_idx(2,1) = sort_idx(1); end find_idx=4; for n=1:5 t=find(cur_idx==n); if isempty(t) cur_idx(find_idx,1) = n; find_idx=find_idx+1; end end % % find temp_cur_4 and temp_cur_5 % cur45=cur; % cur45(cur_idx,:) = []; % v3=cur(cur_idx(1,1),:) - cur(cur_idx(3,1),:); % v4=cur45(1,:)-cur(cur_idx(3,1),:); % v5=cur45(2,:)-cur(cur_idx(3,1),:); % %theta4 = asin(norm(cross(v3,v4))/(norm(v4)*norm(v3))); % %theta5 = asin(norm(cross(v3,v5))/(norm(v5)*norm(v3))); % if v4(1)*v4(3) < 0 && v5(1)*v5(1) > 0 % find_idx=4; % for n=1:5 % t=find(cur_idx==n); % if isempty(t) % cur_idx(find_idx,1) = n; % find_idx=find_idx+1; % end % end % else % find_idx=5; % for n=1:5 % t=find(cur_idx==n); % if isempty(t) % cur_idx(find_idx,1) = n; % find_idx=find_idx-1; % end % end % end % determin temp_cur1 and temp_cur2 % Run ICP %[match, TR, TT, ER, t] = icp_match(prev', cur', 20); %[match, TR, TT, ER, t] = icp_match(prev', cur', 20,'Minimize','lmaPoint'); % {point} | plane | lmaPoint % diff_dist=[]; % for k=1:5 % pre = gt_total(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:end)=new_cur; for k=1:5 gt_total_pair(i,2+(k-1)*3:4+(k-1)*3)=cur(cur_idx(k),:); %degbug by showing plot % plot3(cur(cur_idx(k),1),cur(cur_idx(k),2),cur(cur_idx(k),3),plot_colors{k}); % hold on; end %gt_total_pair = [gt_total_pair; new_gt]; end end
github
rising-turtle/slam_matlab-master
generate_gt_wpattern_syn_zh.m
.m
slam_matlab-master/ground_truth_zh/generate_gt_wpattern_syn_zh.m
8,468
utf_8
341b6b99aacac024b3929ca4d0226dcf
% Generate ground truth from motion capture data of MOTIVE, using Time to % synchorize not the movement, also synchorize the camera record time % Assumption : Motion caputre data of MOTIVE(file format : *.csv) has at least 5 markers on SR4K % % Author : David Zhang ([email protected]) % Date : 10/23/15 function generate_gt_wpattern_syn_zh() clear all clc clf close all %% add 3rd libraries add_path_zh; %% Load motion capture data [data_file_name, camera_record_name] = get_file_name(); %% 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 [gt, gt_total] = synchorize_gt_record(data_file_name, camera_record_name); %% 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 %% transform all the points from the motion capture coordinate frame into local coordinate frame % 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 % f_w = f_l*R_l2w, p^l = R_l2w * p^w [R_l2w, t_l2w] = compute_initial_T(marker); [ gt_total_pair(:,2:16)] = transform_pc( gt_total_pair(:,2:16), R_l2w, t_l2w); [ gt(:, 2:4)] = transform_pc(gt(:, 2:4), R_l2w, t_l2w); %% 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); %% only convert with dataset_3 % gt_pose = [gt_pose(:,1), gt_pose(:,2), gt_pose(:,3), gt_pose(:,4:end)]; %% 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_TPattern(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] = add_new_trans(rot, trans, timestamp, ... op_pset1, op_pset2, gt_pose,gt_pose_euler, distance_total) q = R2q(rot); gt_pose=[gt_pose; timestamp, trans' q']; % e = R2e(rot); gt_pose_euler=[gt_pose_euler; timestamp, 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]; 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'); % [rot, trans, sta] = find_transform_matrix(op_pset1', op_pset2'); if sta > 0 [gt_pose, gt_pose_euler, distance_total] = add_new_trans(rot, trans, gt_total_pair(i+1,1),... op_pset1, op_pset2, gt_pose, gt_pose_euler, distance_total); else % sta; % [rot, trans, valid] = computeT_with_previous(op_pset1, op_pset2, gt_pose_euler); % if valid % find valid transformation % [gt_pose, gt_pose_euler, distance_total] = add_new_trans(rot, trans, gt_total_pair(i+1,1), ... % op_pset1, op_pset2, gt_pose, gt_pose_euler, distance_total); % end %% use this more robust function to compute [R, t] [rot, trans] = eq_point(op_pset2', op_pset1'); % [rot, trans] = eq_point(op_pset1', op_pset2'); [gt_pose, gt_pose_euler, distance_total] = add_new_trans(rot, trans, gt_total_pair(i+1,1), ... op_pset1, op_pset2, gt_pose, gt_pose_euler, distance_total); end end end function [rot, trans, valid] = computeT_with_previous(op_pset1, op_pset2, gt_pose_euler) valid = 0; j = size(gt_pose_euler,1); for k=j-1:-1:1 p = gt_pose_euler(k, 2:end); %% [R t]-1 = [R' -R't] R = euler_to_rot(p(4), p(5), p(6)); t = p(1:3); R_INV = R'; t_INV = -R'*t'; op_pset_prev = R_INV*op_pset2' + repmat(t_INV, 1, 5); [rot, trans, sta] = find_transform_matrix(op_pset_prev, op_pset1'); if sta > 0 %% rot = R * rot; trans = R * trans + t; valid = 1; return ; 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_TPattern(gt_total) plot_colors={'b.','r.','g.','m.','c.'}; figure; px = zeros(5, 1); py = zeros(5,1); pz = zeros(5,1); for i=1:5 px(i) = gt_total(1,2+3*(i-1)); py(i) = gt_total(1,3+3*(i-1)); pz(i) = gt_total(1,4+3*(i-1)); hold on; plot3(px(i), py(i), pz(i), plot_colors{i}); end grid; axis equal; hold off; 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
rmat2quat.m
.m
slam_matlab-master/ground_truth_zh/rmat2quat.m
795
utf_8
238c076762b7266d10f6726f613f660c
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
github
rising-turtle/slam_matlab-master
quat2rmat.m
.m
slam_matlab-master/ground_truth_zh/quat2rmat.m
798
utf_8
fb153dbeaab428656e51bea7b133b87c
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % 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 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
github
rising-turtle/slam_matlab-master
compute_initial_Tnew.m
.m
slam_matlab-master/ground_truth_zh/compute_initial_Tnew.m
3,696
utf_8
8d867c8f8fc844654fc6bb156c2b5ec4
% % new T-bar on the robocane for data collection % find the initial transformation from world coordinate to camera % coordinate, z % the result shows that / % T pattern, find matched points / % x ---|--- 5 1 4 /-----> x % | 2 | % z| 3 | y % p1 (0, 0, 0) | % p2 (0, 0, -0.0838) % p3 (0, 0, -0.1681) % p4 (0.127, 0, 0) % p5 (-0.134, 0, 0) % Author : David Zhang ([email protected]) % Date : Jan. 30 2018 % from led to the front plate of sr4k, consider Tplate_cam later % z axis offset 22.5 mm % y axis offset 10.5 mm + (height=65/2) = 10.5 + 32.5 = 43 mm function [rot, trans] = compute_initial_Tnew(p_world) if nargin == 0 p_world = [1.6982 0.6840 2.4577; 1.6432 0.7339 2.4971; 1.5857 0.7820 2.5376; 1.7844 0.7082 2.5511; 1.6088 0.6648 2.3616]; end z_shift = 0; y_shift = 0; %% for different cases, have to pay attention which case fit, by checking that whether the result of % generate_gt_wpattern_syn_zh consistent in plot_gt_and_estimate %% case 1 p_local = [0 0 0; 0 0 -0.0838; 0 0 -0.1681; 0.127, 0, 0; -0.134, 0, 0]; %% case 2 % p_local = [0 0 0; 0 0 -0.0838; 0 0 -0.1681; 0.1302 0 0; -0.1317 0 0 ]; p_local = p_local + repmat([0 y_shift z_shift], 5, 1); %% compute the transfrom, pl = Tlc * pc, Tlc = find_transform_matrix(pl, pc); [rot, trans, sta] = find_transform_matrix(p_local', p_world'); % [rot, trans] = eq_point(p_local', p_world'); tmp_p_l = rot * p_world' + repmat(trans, 1, 5); end function compute_initial_five_pts() path_dir = '.'; 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)); rel_dis = compute_relative_dis(gt_total_pair(:, 2:16)); plot_gt_pairs(gt_total_pair); end function [rel_dis] = compute_relative_dis(pts) pt_1 = pts(:, 1:3); pt_2 = pts(:, 4:6); pt_3 = pts(:, 7:9); pt_4 = pts(:, 10:12); pt_5 = pts(:, 13:15); pt_0 = pt_1; pt_1 = pt_1 - pt_0; pt_2 = pt_2 - pt_0; pt_3 = pt_3 - pt_0; pt_4 = pt_4 - pt_0; pt_5 = pt_5 - pt_0; d1 = sqrt(diag(pt_1*pt_1')); d2 = sqrt(diag(pt_2*pt_2')); d3 = sqrt(diag(pt_3*pt_3')); d4 = sqrt(diag(pt_4*pt_4')); d5 = sqrt(diag(pt_5*pt_5')); rel_dis = [d1 d2 d3 d4 d5]; end function plot_gt_pairs(gt_total_pair) %% show ground truth by pairs plot_colors={'b.','r.','g.','y.','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
github
rising-turtle/slam_matlab-master
extractTPattern.m
.m
slam_matlab-master/ground_truth_zh/extractTPattern.m
4,990
utf_8
d95b3060ae44175ad6d00c6f87ecdeca
%% % Jan. 30 2018, He Zhang, [email protected] % extract T Pattern from motion capture data, and store it into TPattern.log % the T Pattern is described in compute_initial_Tnew.m function extractTPattern(fname, ouf) clear all clc clf close all global g_TN; g_TN = 5; global g_6; g_6 = 0; if nargin == 0 fname = './motion_capture_data/Dense_Slow_640x480_30_b.csv'; ouf = './motion_capture_data/Dense_Slow_640x480_30_b_TPattern.log'; end %% read data from .csv file pts = extract_TPoints(fname); fprintf('pattern extracted given 6 points %d\n', g_6); %% compute sum distance sum_dis = compute_distance(pts(:, 2:end)); mu = mean(sum_dis); sigma = std(sum_dis); %% save it dlmwrite(ouf,pts,' '); % [time_stamp pt1 pt2 pt3 pt4 pt5] end function pts = extract_TPoints(fname) %% scan all lines into a cell array global g_TN; fid = fopen(fname); columns=textscan(fid,'%s','delimiter','\n'); lines=columns{1}; N=size(lines,1); pts=[]; cnt_b5 = 0; 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',','); l = textscan(line_i, '%s %d %f %f %f\n', 'delimiter', ','); %% valid data if strcmp(l{1}, 'frame') if l{5} >= 5 %% read data line_data = []; if l{5} == 5 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\n','delimiter',','); elseif l{5} == 6 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 %f %f %f %d %s\n','delimiter',','); else fprintf('extractTPattern: not handle %d points\n', l{5}); continue; end time_stamp = line_data{3}; %% extract marker point marker=[]; 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 %% extract TPattern TP = get_T_pattern(marker); if size(TP, 1) == g_TN cnt_b5 = cnt_b5 + 1; pts =[pts; time_stamp reshape(TP', 1, 15)]; end end end end fclose(fid); fprintf('scan_data.m: cnt 5-points %d, \n', cnt_b5); end function TP = get_T_pattern(markers) global g_TN global g_6 TP = []; if size(markers, 1) == g_TN TP = TPattern(markers); elseif size(markers, 1) == g_TN + 1 TP = TPatternPlus(markers); if size(TP, 1) == g_TN g_6 = g_6 + 1; end end end %% only work when size(markers,1) = g_TN + 1 function TP = TPatternPlus(markers) global g_TN TP = []; for i=1:size(markers, 1) pts = []; for j = 1:size(markers,1) if j == i continue; % exclude point i end pts = [pts; markers(j,:)]; end TP = TPattern(pts); if size(TP, 1) == g_TN break; end end end function TP = TPattern(markers) global g_TN; %% T pattern, details in compute_initial_Tnew.m T_dis = [0.51, 0.48, 0.68, 0.75, 0.76]; pdis = compute_distance_pattern(markers); TP = zeros(size(markers)); % first find point 1, 2, 3, then distinguish point 4, 5 seq = [0 0 0 0 0]; flag = [0 0 0 0 0]; thre = 0.01; % 1cm cnt_45 = 0; pre_j = 0; pre_dj = 0; sorted_dis = sort(pdis); for i =1:g_TN fprintf('%f ', sorted_dis(i)); end fprintf('\n'); for i=1:g_TN d = pdis(i); for j = 1:g_TN if abs(d - T_dis(j)) < thre seq(i) = j; flag(j) = 1; end end %% distinguish 4 and 5. the TPattern design is so bad if d > 0.75 && d < 0.79 if cnt_45 == 0 pre_j = i; pre_dj = d; else if d < pre_dj seq(i) = 4; seq(pre_j) = 5; else seq(i) = 5; seq(pre_j) = 4; end flag(4) = 1; flag(5) = 1; end cnt_45 = cnt_45 + 1; end end if sum(flag) ~= g_TN TP = []; else for i=1:g_TN if seq(i) == 0 TP = []; break; end TP(seq(i),:) = markers(i, :); end end end function [sum_dis] = compute_distance_pattern(pts) global g_TN; sum_dis = zeros(g_TN, 1); for i=1:g_TN pti = pts(i, :); dis_m = 0; % sum of point i to all other points for m=1:g_TN ptj = pts(m, :); d_pt = ptj - pti; dis_m = dis_m + sqrt(sum(d_pt.*d_pt)); end sum_dis(i) = dis_m; end end
github
rising-turtle/slam_matlab-master
transform_pc.m
.m
slam_matlab-master/ground_truth_zh/transform_pc.m
333
utf_8
61bdbcf94164db5c26d374657b5b494e
% % transform point cloud given [R t] % Author : David Zhang ([email protected]) % Date : 10/23/15 function [pc] = transform_pc(pc, R, t) [m, n] = size(pc); loop_n = n/3; translation = repmat(t, 1, m); for i=1:loop_n pc_T = pc(:,(i-1)*3+1:i*3)'; pc_T = R*pc_T + translation; pc(:, (i-1)*3+1:i*3) = pc_T'; end end
github
rising-turtle/slam_matlab-master
compare_error_lsd_rgbd_vo.m
.m
slam_matlab-master/ground_truth_zh/compare_error_lsd_rgbd_vo.m
2,666
utf_8
476dd1331f449491f422d3bfbb435ea0
function compare_error_lsd_rgbd_vo() %% % Author : David Zhang ([email protected]) % Date : 08/08/16 % compute the RMSE of the relative displacement error given the result % from VO of LSDSLAM and of RGBDSLAM %% comparison between dense-track and sparse-track, use dataset_3 gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.dat_pose_wp'; es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\compare_lsd_vo\key_frame_trajectory.log'; % lsd-vo es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\compare_lsd_vo\trajectory_estimate.txt'; % rgbd-vo es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\data3_vro_estimate.txt'; es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\data3_plane_em_vro_4_estimate.txt'; add_path_zh; %% compute RTE for rgbd's vo and lsd's vo respectively E_lsd = computeRTE(gt_f, es_f); E_rgbd = computeRTE(gt_f, es_f2); %% draw them st = 2; et = min(size(E_rgbd,1), size(E_lsd,1)); e_lsd = E_lsd(st:et,1); plot(e_lsd, 'b-*'); xlabel('Number of Keyframes #', 'FontSize', 20); ylabel('Relative Translational Error [m]', 'FontSize', 20); hold on; e_rgbd = E_rgbd(st:et,1); plot(e_rgbd, 'r-*'); set(gca, 'fontsize', 17); h = legend('VO LSD-SLAM', 'VO RGBD-SLAM'); set(h, 'FontSize', 24); grid on; end function [E_ab, E_sq] = computeRTE(gt_f, es_f) gt = load(gt_f); es = load(es_f); % es2 = load(es_f2); %% synchroization with time [es_syn, gt_syn] = syn_time_with_gt(es, gt); E_sq = zeros(size(es_syn,1), 2); E_ab = zeros(size(es_syn,1), 2); Te_1 = eye(4); Tg_1 = eye(4); j = 1; for i=2:1:size(es_syn,1) pe_2 = es_syn(i, 2:end); pe_2_seq = pe_2(4:7); pe_2_seq(2:4) = pe_2(4:6); pe_2_seq(1) = pe_2(7); pg_2 = gt_syn(i, 2:end); Re_2 = quat2rmat(pe_2_seq'); te_2 = pe_2(1:3)'; Rg_2 = quat2rmat(pg_2(4:7)'); tg_2 = pg_2(1:3)'; Te_2 = combine(Re_2, te_2); Tg_2 = combine(Rg_2, tg_2); [t_sq, r_sq] = compute_squared_error(Te_1, Te_2, Tg_1, Tg_2); E_sq(j,1) = t_sq; E_sq(j, 2) = r_sq; E_ab(j,1) = sqrt(t_sq); E_ab(j,2) = sqrt(r_sq); j = j+1; Te_1 = Te_2; Tg_1 = Tg_2; end E_sq(j:end,:) = []; E_ab(j:end,:) = []; end function [T] = combine(R, t) T = [R t; 0 0 0 1]; end function [R, t] = decompose(T) R = T(1:3, 1:3); t = T(1:3, 4); end function [t_sq, r_sq] = compute_squared_error(Te_1, Te_2, Tg_1, Tg_2) dTe12 = Te_1\Te_2; % inv(Te_1)*Te_2; dTg12 = Tg_1\Tg_2; %inv(Tg_1)*Tg_2; deltaT = dTe12\dTg12; % inv(dTe12)*dTg12; [R, t] = decompose(deltaT); e = R2e(R); e = e.*180./pi; t_sq = t'*t; r_sq = e'*e; end
github
rising-turtle/slam_matlab-master
transform_TR.m
.m
slam_matlab-master/ground_truth_zh/transform_TR.m
443
utf_8
a666dc39ac19c4ad53318391dd685460
%% % transform coodinate system % pay attention to quaternion sequence function [pose] = transform_TR(pose, R, t) T_w2l = combine(R, t); for i = 1:size(pose, 1) t_l2i = pose(i, 1:3); q = pose(i, 4:7); R_l2i = quat2rmat(q'); T_l2i = combine(R_l2i, t_l2i'); T_w2i = T_w2l * T_l2i; [R_w2i, t_w2i] = decompose(T_w2i); pose(i, 1:3) = t_w2i'; q = rmat2quat(R_w2i); pose(i, 4:7) = [q(2:4); q(1)]'; end end
github
rising-turtle/slam_matlab-master
eq_point.m
.m
slam_matlab-master/ground_truth_zh/eq_point.m
834
utf_8
e792beddfd466db4f709817ca9559e8e
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% this function is from icp function function [R,T] = eq_point(q,p,weights) if nargin <= 2 weights = ones(1,size(q,2)); end 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,~,V] = svd(N); % singular value decomposition R = V*diag([1 1 det(U*V')])*transpose(U); T = q_bar - R*p_bar; end
github
rising-turtle/slam_matlab-master
get_ground_truth_pose.m
.m
slam_matlab-master/ground_truth_zh/get_ground_truth_pose.m
1,938
utf_8
96628d57e5d78e6f7f222759ad420b01
function get_ground_truth_pose() % % Author : David Zhang ([email protected]) % Date : 08/08/16 % get the ground truth pose of the keyframes % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.dat_pose_wp'; es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\compare_lsd_vo\key_frame_trajectory.log'; % lsd-vo % es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\compare_lsd_vo\trajectory_estimate.txt'; % rgbd-vo add_path_zh; gt = load(gt_f); es = load(es_f); %% synchroization with time [es_syn, gt_syn] = syn_time_with_gt(es, gt); % gt sequence: timestamp x y z qw qx qy qz => timestamp x y z qx qy qz qw gt = [es_syn(:,1) gt_syn(:,2:4) gt_syn(:, 6:8) gt_syn(:, 5)]; % dlmwrite('.\tmp\data_3_rgbd_gt_pose.log', gt, 'delimiter', ' '); dlmwrite('.\tmp\data_3_lsd_gt_pose.log', gt, 'delimiter', ' '); sid = 1; eid = 100; %size(gt,1); plot3(gt(sid:eid,2), gt(sid:eid,3), gt(sid:eid,4), 'k-*'); hold on; plot3(es_syn(sid:eid,2), es_syn(sid:eid,3), es_syn(sid:eid,4), 'b*-'); % test_gt(gt_syn(1:end,2:8)); end %% test whether the gt's transformation works correctly function test_gt(gt) tmp_v = [0 0 0 1 0 0 0]; pre_gt = gt(1,:); T_g1 = toTrans(pre_gt); T_n1 = toTrans(tmp_v); nv = tmp_v; for i=2:size(gt,1) cur_gt = gt(i,:); T_g2 = toTrans(cur_gt); % gt incremental transformation inc_trans = T_g1\T_g2; % inv(Tg1)*Tg2 T_n2 = T_n1*inc_trans; cur_v = toPose(T_n2); nv = [nv; cur_v]; % next iteration T_n1 = T_n2; T_g1 = T_g2; end hold on; plot3(nv(:,1), nv(:,2), nv(:,3), 'b*-'); end function T = toTrans(p) % R = quat2rmat(p(4), p(5), p(6), p(7)); q = p(4:7); t = p(1:3); R = quat2rmat(q'); T = [R t'; 0 0 0 1]; end function p = toPose(T) R = T(1:3,1:3); q = rmat2quat(R); t = T(1:3,4); p(1:3) = t'; p(4:7) = q'; end
github
rising-turtle/slam_matlab-master
generate_gt_trajectory.m
.m
slam_matlab-master/ground_truth_zh/generate_gt_trajectory.m
8,560
utf_8
83821a42059115510139114d096fa98f
% input: inf: *.csv file % Assumption : Motion caputre data of MOTIVE(file format : *.csv) has at % least 5 markers on camera % % input: inf .log file include TPattern points extracted by extractTPattern.m % output: ouf: .log file [timestamp x, y, z, qx, qy, qz, qw] % Author : David Zhang ([email protected]) % Date : Jan. 28 2018 function generate_gt_trajectory(inf, ouf) clear all clc clf close all if nargin == 0 % inf = './motion_capture_data/Dense_Slow_640x480_30_b.csv'; inf = './motion_capture_data/Dense_Slow_640x480_30_b_TPattern.log'; ouf = './motion_capture_data/Dense_Slow_640x480_30_b_trajectory.log'; ouf2 = './motion_capture_data/Dense_Slow_640x480_30_b_trajectory_g.log'; end %% add 3rd libraries add_path_zh; %% read data gt_total_pair = load(inf); timestamp = gt_total_pair(:,1); pts = gt_total_pair(:,2:end); %% 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 %% transform all the points from the motion capture coordinate frame into local coordinate frame % 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 % f_w = f_l*R_l2w, p^l = R_l2w * p^w [R_l2w, t_l2w] = compute_initial_Tnew(marker); [ gt_total_pair(:,2:16)] = transform_pc( gt_total_pair(:,2:16), R_l2w, t_l2w); % [ gt(:, 2:4)] = transform_pc(gt(:, 2:4), R_l2w, t_l2w); %% 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); %% transform back into global coordinates R_w2l = R_l2w'; t_w2l = -R_w2l*t_l2w; % e = R2e(R_w2l); % e(1) = 0; % R_w2l = e2R(e); % t_w2l = [0 0 0]'; % only use gt_pose_back = gt_pose; % gt_pose_back(:, 2:4) = transform_pc(gt_pose_euler(:,2:4), R_w2l, t_w2l); gt_pose_back(:, 2:8) = transform_TR(gt_pose(:,2:8), R_w2l, t_w2l); % e(1:2) = 0; %% get rid of yaw component % e(3) = -e(3); % R_w2l = e2R(e); % gt_pose_back(:, 2:4) = transform_pc(gt_pose_back(:,2:4), R_w2l, t_w2l); %% only convert with dataset_3 % gt_pose = [gt_pose(:,1), gt_pose(:,2), gt_pose(:,3), gt_pose(:,4:end)]; %% 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_gt_pose(gt_pose_back); % plot_ground_truth2(gt_total); % plot_TPattern(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] dlmwrite(ouf, gt_pose,' '); % [time_stamp [x y z q1 q2 q3 q4] dlmwrite(ouf2, gt_pose_back, ' '); % [time_stamp [x y z q1 q2 q3 q4] end function [gt_pose, gt_pose_euler, distance_total] = add_new_trans(rot, trans, timestamp, ... op_pset1, op_pset2, gt_pose,gt_pose_euler, distance_total) q = R2q(rot); gt_pose=[gt_pose; timestamp, trans' q']; % e = R2e(rot); gt_pose_euler=[gt_pose_euler; timestamp, 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]; 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'); % [rot, trans, sta] = find_transform_matrix(op_pset1', op_pset2'); if sta > 0 [gt_pose, gt_pose_euler, distance_total] = add_new_trans(rot, trans, gt_total_pair(i+1,1),... op_pset1, op_pset2, gt_pose, gt_pose_euler, distance_total); else % sta; % [rot, trans, valid] = computeT_with_previous(op_pset1, op_pset2, gt_pose_euler); % if valid % find valid transformation % [gt_pose, gt_pose_euler, distance_total] = add_new_trans(rot, trans, gt_total_pair(i+1,1), ... % op_pset1, op_pset2, gt_pose, gt_pose_euler, distance_total); % end %% use this more robust function to compute [R, t] [rot, trans] = eq_point(op_pset2', op_pset1'); % [rot, trans] = eq_point(op_pset1', op_pset2'); [gt_pose, gt_pose_euler, distance_total] = add_new_trans(rot, trans, gt_total_pair(i+1,1), ... op_pset1, op_pset2, gt_pose, gt_pose_euler, distance_total); 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', 20); 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', 20); hold off; axis equal; grid; xlabel('X');ylabel('Y');zlabel('Z'); title('GT pairs'); end function plot_TPattern(gt_total) plot_colors={'b.','r.','g.','m.','c.'}; figure; px = zeros(5, 1); py = zeros(5,1); pz = zeros(5,1); for i=1:5 px(i) = gt_total(1,2+3*(i-1)); py(i) = gt_total(1,3+3*(i-1)); pz(i) = gt_total(1,4+3*(i-1)); hold on; plot3(px(i), py(i), pz(i), plot_colors{i}); end grid; axis equal; hold off; 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
find_pair_nn.m
.m
slam_matlab-master/ground_truth_zh/find_pair_nn.m
816
utf_8
a1524f22e650404f71c7aa8e8853bd08
% Find pairs between two 3D point sets by Nearest Neighbors % % Author : Soonhac Hong ([email protected]) % Date : 2/21/14 % % Input : gt_total : [[x y z]*n] function [ gt_total_pair] = find_pair_nn( gt_total) % Find pairs by nearest neighbor gt_total_pair=gt_total(1,:); for i=2:size(gt_total,1) min_idx_prev=[]; for j=1:2 cur = gt_total(i,1+(j-1)*3:3+(j-1)*3); diff_dist=[]; for k=1:2 pre = gt_total_pair(i-1,1+(k-1)*3:3+(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,1+(min_idx-1)*3:3+(min_idx-1)*3)=cur; end end end
github
rising-turtle/slam_matlab-master
plot_ate_translation_error.m
.m
slam_matlab-master/ground_truth_zh/plot_ate_translation_error.m
1,920
utf_8
ad162345ee6f3a0cbc13de7dd392e0da
% Author : David Zhang ([email protected]) % Date : 11/09/15 % plot the the ATE displacement error at each step, function plot_ate_translation_error() add_path_zh; %% dataset_1 % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.25.55 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_p_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_pem_estimate.txt'; %% dataset_2 gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.46.44 PM.dat_pose_wp'; es_f = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_p_estimate.txt'; es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_pem_estimate.txt'; %% dataset_3 % es_f = '.\motion_capture_data\test_10_16_2015\trajectory_estimate_04.49.46.txt'; % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_p_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_pem_estimate.txt'; mode = 'ATE'; [rmse, E_sq, E_ab] = compute_error(gt_f, es_f, mode); E1 = E_ab; [rmse, E_sq, E_ab] = compute_error(gt_f, es_f2, mode); E2 = E_ab; plot_error(E1, E2); end function plot_error(E1, E2) et1 = sqrt(E1(:,1)); et2 = sqrt(E2(:,1)); plot(et1, 'r+'); hold on; plot(et2, 'b+'); xlabel('nth camera frame #'); ylabel('translational error [m]'); legend('VO', 'VO_p'); end
github
rising-turtle/slam_matlab-master
compute_initial_T.m
.m
slam_matlab-master/ground_truth_zh/compute_initial_T.m
3,809
utf_8
fd2892b25e171900ac986ea56e8b49a7
% % find the initial transformation from world coordinate to camera % coordinate, y z % the result shows that | / % T pattern, find matched points | / % ---|--- 5/4 1 4/5 x ----|/ % | 2 % | 3 % p1 (0, 0, 0) % p2 (0, 0, -0.0838) % p3 (0, 0, -0.1681) % p4/5 (-0.1317, 0, 0) % p5/4 (0.1302, 0, 0) % Author : David Zhang ([email protected]) % Date : 10/23/15 % from led to the front plate of sr4k % z axis offset 22.5 mm % y axis offset 10.5 mm + (height=65/2) = 10.5 + 32.5 = 43 mm function [rot, trans] = compute_initial_T(p_world) if nargin == 0 p_world = [3.2867 0.8038 -1.1012; 3.3616 0.8403 -1.0947; 3.4369 0.8772 -1.0855; 3.2812 0.7928 -0.9697; 3.2941 0.8155 -1.2305]; p_world = [3.3603 0.7747 -1.0545; 3.4357 0.8076 -1.039; 3.511 0.8418 -1.0212; 3.3872 0.7772 -1.182; 3.3349 0.7741 -0.9254]; end z_shift = -0.0225; y_shift = +0.043; %% for different cases, have to pay attention which case fit, by checking that whether the result of % generate_gt_wpattern_syn_zh consistent in plot_gt_and_estimate %% case 1 p_local = [0 0 0; 0 0 -0.0838; 0 0 -0.1681; -0.1317 0 0; 0.1302 0 0]; %% case 2 % p_local = [0 0 0; 0 0 -0.0838; 0 0 -0.1681; 0.1302 0 0; -0.1317 0 0 ]; p_local = p_local + repmat([0 y_shift z_shift], 5, 1); %% compute the transfrom, pl = Tlc * pc, Tlc = find_transform_matrix(pl, pc); [rot, trans, sta] = find_transform_matrix(p_local', p_world'); % [rot, trans] = eq_point(p_local', p_world'); tmp_p_l = rot * p_world' + repmat(trans, 1, 5); end function compute_initial_five_pts() path_dir = '.'; 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)); rel_dis = compute_relative_dis(gt_total_pair(:, 2:16)); plot_gt_pairs(gt_total_pair); end function [rel_dis] = compute_relative_dis(pts) pt_1 = pts(:, 1:3); pt_2 = pts(:, 4:6); pt_3 = pts(:, 7:9); pt_4 = pts(:, 10:12); pt_5 = pts(:, 13:15); pt_0 = pt_1; pt_1 = pt_1 - pt_0; pt_2 = pt_2 - pt_0; pt_3 = pt_3 - pt_0; pt_4 = pt_4 - pt_0; pt_5 = pt_5 - pt_0; d1 = sqrt(diag(pt_1*pt_1')); d2 = sqrt(diag(pt_2*pt_2')); d3 = sqrt(diag(pt_3*pt_3')); d4 = sqrt(diag(pt_4*pt_4')); d5 = sqrt(diag(pt_5*pt_5')); rel_dis = [d1 d2 d3 d4 d5]; end function plot_gt_pairs(gt_total_pair) %% show ground truth by pairs plot_colors={'b.','r.','g.','y.','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
github
rising-turtle/slam_matlab-master
plot_gt_and_estimate.m
.m
slam_matlab-master/ground_truth_zh/plot_gt_and_estimate.m
5,255
utf_8
cdc1577b62ee7dcf19136ad6ee3972bd
% Author : David Zhang ([email protected]) % Date : 10/23/15 % plot the estimated trajectory and the ground truth function plot_gt_and_estimate(gt_f, es_f) if nargin == 0 %% dataset_1 % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.25.55 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_p_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_pem_estimate.txt'; %% dataset_2 % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.46.44 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_p_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_pem_estimate.txt'; %% dataset_3 % es_f = '.\motion_capture_data\test_10_16_2015\trajectory_estimate_04.49.46.txt'; % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_p_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_pem_estimate.txt'; %% dataset_4 % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.51.46 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_4\trajectory_vo_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_4\trajectory_vo_p_estimate.txt'; %% comparison between dense-track and sparse-track, use dataset_3 gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.dat_pose_wp'; % ground truth es_f2 ='.\motion_capture_data\test_10_16_2015\dataset_3\compare_lsd_vo\key_frame_trajectory.log'; % lsd-slam es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\compare_lsd_vo\trajectory_estimate.txt'; % rgbd-slam es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\data3_vro_estimate.txt'; es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\data3_plane_em_vro_estimate.txt'; end gt = load(gt_f); es = load(es_f); es_p = load(es_f2); % traj_len = compute_trajectory_length(es_p(:,2:4)); gt = syn_last_frame(gt, es(:,1)); % p = 0.513; %1; % st = 1; % et = size(gt,1)*p; % sti = int32(size(gt,1)*p) ; % eti = int32(size(gt,1)*0.763); % plot_xyz(gt(sti:eti,2), gt(sti:eti,3), gt(sti:eti,4), '-k'); gt(:,2:8) = transform_traj(gt(:,2:8)); es(:,2:8) = change_order(es(:,2:8)); es_p(:,2:8) = change_order(es_p(:,2:8)); es(:,2:8) = transform_traj(es(:,2:8)); es_p(:,2:8) = transform_traj(es_p(:,2:8)); % plot_xyz(gt(:,2), gt(:,3), gt(:,4), 'k'); plot_xyz(gt(:,2), gt(:,3), gt(:,4), 'y'); hold on; st = 1;% 1200; et = size(es,1); % 1800 plot_xyz(es(st:et,2), es(st:et,3), es(st:et,4), '-r'); hold on; plot_xyz(es_p(st:et,2), es_p(st:et,3), es_p(st:et,4),'-g'); % legend('GT','VO','VO_P'); h = legend('GroundTruth', 'VO RGBD-SLAM', 'VO LSD-SLAM'); set(h, 'FontSize', 14); hold on; plot3(gt(1,2), gt(1,3), gt(1,4), 'g*', 'MarkerSize', 15, 'LineWidth',2); % plot3(gt(sti,2), gt(sti,3), gt(sti,4), 'k*', 'MarkerSize', 15, 'LineWidth',2); % plot3(es(st,2), es(st,3), es(st,4), 'r*', 'MarkerSize', 15, 'LineWidth',2); % plot3(es_p(st,2), es_p(st,3), es_p(st,4), 'b*', 'MarkerSize', 15, 'LineWidth',2); %% try save meshlab % save_meshlab('./tmp/trajectory_mesh_2.ply',gt(:,2:4), es(:, 2:4), es_p(:,2:4)); end function np = change_order(p) np = p ; np(:,5:7) = p(:,4:6); np(:,4) = p(:,7); end %% save into meshlab function save_meshlab(f, gt, es1, es2) % pts_gt = generate_mesh_pts(gt, [0 0 0]); % black for gt % pts_gt = generate_mesh_pts(gt, [153 0 153]); % purple pts_gt = generate_mesh_pts(gt, [255 255 0]); % yellow pts_es1 = generate_mesh_pts(es1, [255 0 0]); % red for es1 pts_es2 = generate_mesh_pts(es2, [0 255 0]); % blue for es2 %% write them into a ply file pts = [pts_gt; pts_es1; pts_es2]; n = size(pts, 1); fid = fopen(f, 'w'); fprintf(fid, 'ply\nformat ascii 1.0\nelement vertex %d\nproperty float x\nproperty float y\nproperty float z\nproperty uchar red\nproperty uchar green\nproperty uchar blue\nend_header\n', n); fclose(fid); dlmwrite(f,pts,'-append', 'delimiter',' '); end function [pts] = generate_mesh_pts(t, c) pts = t; pc = repmat( c, size(t,1), 1); pts = [pts pc]; end function l = compute_trajectory_length(p) l = 0; for i=2:size(p,1) dt = p(i,:) - p(i-1,:); l = l + sqrt(dt*dt'); end end function gt = syn_last_frame(gt, es_t) time_passed = es_t(end) - es_t(1); index = size(gt,1); while gt(index,1) - gt(1,1) > time_passed index = index - 1; end gt(index+1:size(gt,1), :) = []; end function plot_xyz(x, y, z, c) plot3(x, y, z, c, 'LineWidth', 2); hold on; hold off; axis equal; grid; xlabel('X (m)');ylabel('Y (m)');zlabel('Z (m)'); end
github
rising-turtle/slam_matlab-master
transform_traj.m
.m
slam_matlab-master/ground_truth_zh/transform_traj.m
715
utf_8
b10b621acceb5b4ffe34ca4642d61bff
%% % Aug. 16, 2016, David Z % Transform a trajectory into a new reference function tp = transform_traj(p, iniT) if nargin < 2 iniT = [0.2 0.03 0.98 -0.43; -0.98 -0.08 0.2 -0.29; 0.09 -1. 0.01 0.23; 0 0 0 1]; end np = vect_T(iniT); tp = np; new_T = iniT; last_T = trans_T(p(1,:)); for i =2:size(p,1) cur_T = trans_T(p(i,:)); del_T = last_T\cur_T; new_T = new_T*del_T; np = vect_T(new_T); tp = [tp; np]; last_T = cur_T; end end function T = trans_T(p) R = quat2rmat(p(4:7)'); t = p(1:3)'; T = [R t; 0 0 0 1]; end function p = vect_T(T) R = T(1:3,1:3); t = T(1:3,4); q = rmat2quat(R); p = [t' q']; end
github
rising-turtle/slam_matlab-master
getTPattern.m
.m
slam_matlab-master/ground_truth_zh/getTPattern.m
1,328
utf_8
9bc54a7788714c6f84971a73e5515dcd
%% % Jan. 28 2018, He Zhang, [email protected] % explore the T pattern % function getTPattern(fname) global g_TN; g_TN = 5; if nargin == 0 fname = './motion_capture_data/Dense_Slow_640x480_30_b.csv'; end %% read data from .csv file pts = get_data(fname); %% compute sum distance sum_dis = compute_distance(pts); mu = mean(sum_dis); sigma = std(sum_dis); end function pts = get_data(fname) %% scan all lines into a cell array global g_TN; fid = fopen(fname); columns=textscan(fid,'%s','delimiter','\n'); lines=columns{1}; N=size(lines,1); pts=[]; cnt_b5 = 0; 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}) % time_stamp = line_data{3}; marker=[]; if line_data{5} == 5 % original 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 cnt_b5 = cnt_b5 + 1; pts =[pts; reshape(marker', 1, 15)]; end end end end fclose(fid); fprintf('scan_data.m: cnt 5-points %d, \n', cnt_b5); end
github
rising-turtle/slam_matlab-master
deconstruct.m
.m
slam_matlab-master/ground_truth_zh/deconstruct.m
116
utf_8
41b09cb36372256be5cdd13704898870
function [q, t] = deconstruct(T) [R,t] = decompose(T); q = rmat2quat(R); q = [q(2) q(3) q(4) q(1)]; end
github
rising-turtle/slam_matlab-master
plot_rte_translation_error.m
.m
slam_matlab-master/ground_truth_zh/plot_rte_translation_error.m
2,679
utf_8
c6a2dedbcd822057858f9662f7e72390
% Author : David Zhang ([email protected]) % Date : 11/13/15 % plot the accumulated RTE displacement error at each step, function plot_rte_translation_error() add_path_zh; %% dataset_1 gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.25.55 PM.dat_pose_wp'; es_f = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_p_estimate.txt'; es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_pem_estimate.txt'; %% dataset_2 % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.46.44 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_p_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_pem_estimate.txt'; %% dataset_3 gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_estimate.txt'; es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\data3_vro_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_p_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_pem_estimate.txt'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\data3_plane_em_vro_estimate.txt'; es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\data3_plane_em_vro_4_estimate.txt'; % es_f2 = '.\motion_capture_data\test_10_16_2015\dataset_3\compare_lsd_vo\trajectory_estimate.txt'; mode = 'RTE'; [rmse, E_sq, E_ab] = compute_error(gt_f, es_f, mode); E1 = E_ab; [rmse, E_sq, E_ab] = compute_error(gt_f, es_f2, mode); E2 = E_ab; plot_error(E1, E2); end function E = accumulate(E) for i=2:size(E,1) E(i) = E(i-1) + E(i); end end function plot_error(E1, E2) et1 = sqrt(E1(:,1)); et2 = sqrt(E2(:,1)); et1 = accumulate(et1); et2 = accumulate(et2); plot_error_impl(et1, et2, 'translational error [m]'); figure; et1 = sqrt(E1(:,2)); et2 = sqrt(E2(:,2)); et1 = accumulate(et1); et2 = accumulate(et2); plot_error_impl(et1, et2, 'rotational error [m]'); end function plot_error_impl(et1, et2, y_label) plot(et1, 'r+'); hold on; plot(et2, 'b+'); xlabel('nth camera frame #'); ylabel(y_label); legend('VO', 'VO_p'); end
github
rising-turtle/slam_matlab-master
compute_distance.m
.m
slam_matlab-master/ground_truth_zh/compute_distance.m
662
utf_8
a959fb86cb7213760e2844ca61964ba3
%% compute sum of mutual distance between all points function [sum_dis] = compute_distance(pts) [row, col] = size(pts); global g_TN; sum_dis = zeros(row, col/3); for i=1:row pt_dis = zeros(1, g_TN); for m=1:g_TN pt = pts(i, (m-1)*3+1:(m*3)); dis_m = 0; % sum of point i to all other points for n =1:g_TN pt_j = pts(i, (n-1)*3+1:(n*3)); d_pt = pt_j - pt; dis_m = dis_m + sqrt(sum(d_pt.*d_pt)); end pt_dis(1, m) = dis_m; end sorted_dis = sort(pt_dis); sum_dis(i,:) = sorted_dis; end end
github
rising-turtle/slam_matlab-master
synchorize_gt_record.m
.m
slam_matlab-master/ground_truth_zh/synchorize_gt_record.m
2,150
utf_8
57bbd95d8600f2e1b5c43fe5b69a9210
% % synchorize the timestamp between motion capture and camera record % % Author : David Zhang ([email protected]) % Date : 10/28/15 function [gt, gt_total] = synchorize_gt_record(gt_fname, record_log) clc if nargin == 0 %% Load motion capture data % gt_fname = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.csv'; % record_log = '.\motion_capture_data\test_10_16_2015\timestamp_04.49.46.log'; gt_fname = './motion_capture_data/test_10_16_2015/Take 2015-10-16 04.25.55 PM.csv'; record_log = './motion_capture_data/test_10_16_2015/timestamp_04.25.55.log'; end %% load gt data fid = fopen(gt_fname); if fid < 0 error(['Cannot open file ' data_file_name]); end [line_data, gt, gt_total] = scan_data(fid); gt_time_seq = gt(:,1); % gt_time_base = repmat(gt_time_seq(1), size(gt_time_seq,1), 1); % gt_time_shift = gt_time_seq - gt_time_base; %% load camera record data % fid = fopen(record_log); camera_record_data = load(record_log); cr_time_seq = camera_record_data(:, 2); cr_time_base = repmat(cr_time_seq(1), size(cr_time_seq,1), 1); cr_time_seq = cr_time_seq - cr_time_base; %% find the synchronize start point global g_index g_index = 1; potential_syn_points = find(cr_time_seq > gt_time_seq(1)); for i=1:size(potential_syn_points) cr_index = potential_syn_points(i); gt_index = find_syn_index(cr_time_seq(cr_index), gt_time_seq); if gt_index ~= -1 break; end end %% delete the non-synchronize part M = size(gt,1); gt = gt(gt_index:M, :); gt_total = gt_total(gt_index:M, :); fprintf('synchorize_gt_record.m: gt_index %d, cr_index %d\n', gt_index, cr_index); end function index = find_syn_index(cr_elapse_time, gt_time_seq) global g_index %% gt has 120 hz, 1/120 ~ 0.0083 gt_time_span_upper = 0.009; while g_index < size(gt_time_seq,1) cur_t = gt_time_seq(g_index); if abs(cur_t - cr_elapse_time) < gt_time_span_upper index = g_index; break; end if cur_t > cr_elapse_time index = -1; break; end g_index = g_index+1; end end
github
rising-turtle/slam_matlab-master
compute_error.m
.m
slam_matlab-master/ground_truth_zh/compute_error.m
6,020
utf_8
5435bdb9264dc70c0879cef7e7e930e5
function [rmse, E_sq, E_ab] = compute_error(gt_f, es_f, mode) % % Author : David Zhang ([email protected]) % Date : 11/06/15 % compute the RMSE of the relative displacement error, following % kuemmerl09auro's approach, RTE, and ATE, % if nargin == 0 %% dataset_1 % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.25.55 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_estimate.txt'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_p_estimate.txt'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_1\trajectory_vo_pem_estimate.txt'; %% dataset_2 % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.46.44 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_estimate.txt'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_pem_estimate.txt'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_2\trajectory_vo_p_estimate.txt'; %% dataset_3 gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_estimate.txt'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_p_estimate.txt'; %es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\trajectory_vo_pem_estimate.txt'; es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\data3_vro_estimate.txt'; es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\data3_plane_em_vro_2_estimate.txt'; %% comparison between dense-track and sparse-track, use dataset_3 % gt_f = '.\motion_capture_data\test_10_16_2015\Take 2015-10-16 04.49.46 PM.dat_pose_wp'; % es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\compare_lsd_vo\key_frame_trajectory.log'; % lsd-vo % es_f = '.\motion_capture_data\test_10_16_2015\dataset_3\compare_lsd_vo\trajectory_estimate.txt'; % rgbd-vo mode = 'RTE'; % 'RTE' end if nargin == 2 mode = 'ATE'; % 'RTE' end add_path_zh; gt = load(gt_f); es = load(es_f); % es2 = load(es_f2); %% synchroization with time [es_syn, gt_syn] = syn_time_with_gt(es, gt); %% statistically collect error information % compute the relative transformation between any two VO pairs, and then % collect translation error and rotational error % [es_syn2, gt_syn2] = syn_time_with_gt(es2, gt); % st = 120; et = st + 30; plot_xyz(es_syn(st:et, 2), es_syn(st:et, 3), es_syn(st:et, 4), 'b*-'); hold on; plot_xyz(gt_syn(st:et, 2), gt_syn(st:et, 3), gt_syn(st:et, 4), 'k*-'); % hold on; % plot_xyz(es_syn2(st:et, 2), es_syn2(st:et, 3), es_syn2(st:et, 4), '-r'); % hold on; % plot_xyz(gt_syn2(st:et, 2), gt_syn2(st:et, 3), gt_syn2(st:et, 4), '-c'); % es_syn = es_syn2(st:et, :); % gt_syn = gt_syn(st:et, :); if strcmp(mode,'RTE') [E_ab, E_sq] = computeRTE(es_syn, gt_syn); else [E_ab, E_sq] = computeATE(es_syn, gt_syn); end E = E_ab; plot_error(E); me = mean(E); stde = std(E); maxe = max(E); fprintf('\n'); fprintf('E_abs mean: %f %f, std: %f %f \n', me(1), me(2), stde(1), stde(2)); fprintf('E_abs max: %f %f \n', maxe(1), maxe(2)); E = E_sq; N = size(E,1); rmse = sqrt(sum(E)./N); me = mean(E); stde = std(E); fprintf('E_sqr mean: %f %f, std: %f %f rmse %f %f \n', me(1), me(2), stde(1), ... stde(2), rmse(1), rmse(2)); end function [E_ab, E_sq] = computeATE(es_syn, gt_syn) E_sq = zeros(size(es_syn,1), 2); E_ab = zeros(size(es_syn,1), 2); for i=2:size(es_syn,1) pe_2 = es_syn(i, 2:end); pe_2_seq = pe_2(4:7); pe_2_seq(2:4) = pe_2(4:6); pe_2_seq(1) = pe_2(7); pg_2 = gt_syn(i, 2:end); Re_2 = quat2rmat(pe_2_seq'); te_2 = pe_2(1:3)'; Rg_2 = quat2rmat(pg_2(4:7)'); tg_2 = pg_2(1:3)'; Te_2 = combine(Re_2, te_2); Tg_2 = combine(Rg_2, tg_2); deltaT = Te_2\Tg_2; [R, t] = decompose(deltaT); e = R2e(R); e = e.*180./pi; t_sq = t'*t; r_sq = e'*e; E_sq(i,1) = t_sq; E_sq(i, 2) = r_sq; E_ab(i,1) = sqrt(t_sq); E_ab(i,2) = sqrt(r_sq); end end function [E_ab, E_sq] = computeRTE(es_syn, gt_syn) E_sq = zeros(size(es_syn,1), 2); E_ab = zeros(size(es_syn,1), 2); Te_1 = eye(4); Tg_1 = eye(4); j = 1; for i=2:1:size(es_syn,1) pe_2 = es_syn(i, 2:end); pe_2_seq = pe_2(4:7); pe_2_seq(2:4) = pe_2(4:6); pe_2_seq(1) = pe_2(7); pg_2 = gt_syn(i, 2:end); Re_2 = quat2rmat(pe_2_seq'); te_2 = pe_2(1:3)'; % pg_2(5:6) = pg_2(5:6)*-1; % why gt's qx qy is has different signs with vo's qx qy Rg_2 = quat2rmat(pg_2(4:7)'); tg_2 = pg_2(1:3)'; Te_2 = combine(Re_2, te_2); Tg_2 = combine(Rg_2, tg_2); [t_sq, r_sq] = compute_squared_error(Te_1, Te_2, Tg_1, Tg_2); E_sq(j,1) = t_sq; E_sq(j, 2) = r_sq; E_ab(j,1) = sqrt(t_sq); E_ab(j,2) = sqrt(r_sq); j = j+1; Te_1 = Te_2; Tg_1 = Tg_2; end E_sq(j:end,:) = []; E_ab(j:end,:) = []; end function plot_error(E) et = E(:,1); er = E(:,2); plot(et, 'r-*'); xlabel('relation #'); ylabel('translational error [m]'); % figure; % plot(er, 'r+'); % xlabel('relation #'); % ylabel('angular error [deg]'); end function [t_sq, r_sq] = compute_squared_error(Te_1, Te_2, Tg_1, Tg_2) dTe12 = Te_1\Te_2; % inv(Te_1)*Te_2; dTg12 = Tg_1\Tg_2; %inv(Tg_1)*Tg_2; deltaT = dTe12\dTg12; % inv(dTe12)*dTg12; [R, t] = decompose(deltaT); e = R2e(R); e = e.*180./pi; t_sq = t'*t; r_sq = e'*e; end function plot_xyz(x, y, z, c) plot3(x, y, z, c, 'LineWidth', 2); hold on; hold off; axis equal; grid; xlabel('X (m)');ylabel('Y (m)');zlabel('Z (m)'); end function [T] = combine(R, t) T = [R t; 0 0 0 1]; end function [R, t] = decompose(T) R = T(1:3, 1:3); t = T(1:3, 4); end
github
rising-turtle/slam_matlab-master
pose_optimization_example_landmark_2d.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/pose_optimization_example_landmark_2d.m
6,710
utf_8
0600bb720d4a8ddc710779bc6a61242b
% 2D Example of Pose Graph Optimization % Data : 4/12/12 % Author : Soonhac Hong ([email protected]) function pose_optimization_example_landmark_2d() % 2D case pose_data=[1 1 0 0 0; 1 2 2 0 0 ; 2 3 2 0 pi/2]; landmark_data=[3 4 2 0 ; 1 5 2 2 ; 2 5 2 0 ]; % [first pose, second pose, constraint[x,y,theta]] xinit = [0.5; 0.0; 0.2; 2.3; 0.1; -0.2; 4.1; 0.1; pi/2; 4.0; 2.0; 2.1; 2.1] motion_noise = [0.3;0.3;0.1]; pose_num = size(pose_data,1); variable_size = (size(pose_data,2)-2); % size of each variable [x, y, r] total_num = size(unique(pose_data(:,1:2)),1)*variable_size + size(unique(landmark_data(:,2)),1)*2; % first position is not optimized. Omega = zeros(total_num,total_num); Xi = zeros(total_num,1); Odometry=zeros(total_num,1); %Odometry = zeros(pose_num,1); % Fill the elements of Omega and Xi % Initial point for i=1:variable_size Omega(i,i) = 1; Xi(i) = pose_data(1,i+2); Odometry(i) = pose_data(1,i+2); end %% Pose data for i=2:pose_num unit_data = pose_data(i,:); current_index = unit_data(1); next_index = unit_data(2); movement = unit_data(3:2+variable_size); %previous_theta = pose_data(i-1,2+variable_size); % Adjust index according to the size of each variable if current_index ~= 1 current_index = (current_index - 1) * variable_size + 1; end if next_index ~= -1 next_index = (next_index - 1) * variable_size + 1; end for j=0:variable_size-1 % Fill diagonal elements of Omega switch j case 0 diagonal_factor = cos(movement(3)); offdiagonal_factor = 1; case 1 diagonal_factor = cos(movement(3)); offdiagonal_factor = -1; case 2 diagonal_factor = 1; offdiagonal_factor = -1; end Omega(current_index+j,current_index+j) = Omega(current_index+j,current_index+j) + diagonal_factor*motion_noise(j+1); Omega(next_index+j,next_index+j) = Omega(next_index+j,next_index+j) + 1/motion_noise(j+1); % Fill Off-diagonal elements of Omega Omega(current_index+j,next_index+j) = Omega(current_index+j,next_index+j) + (-1)/motion_noise(j+1); Omega(next_index+j,current_index+j) = Omega(next_index+j,current_index+j) + (-1)*diagonal_factor/motion_noise(j+1); if j <= 1 Omega(current_index+j,current_index+j+offdiagonal_factor) = Omega(current_index+j,next_index+j+offdiagonal_factor) + (-1)*offdiagonal_factor*sin(movement(3))/motion_noise(j+1); Omega(next_index+j,current_index+j+offdiagonal_factor) = Omega(next_index+j,current_index+j+offdiagonal_factor) + offdiagonal_factor*sin(movement(3))/motion_noise(j+1); end % Fill Xi Xi(current_index+j) = Xi(current_index+j) + (-1)*movement(j+1)/motion_noise(j+1); Xi(next_index+j) = Xi(next_index+j) + movement(j+1)/motion_noise(j+1); end % Update Odometry if abs(current_index - next_index) == 3 translation=[0 0 1]'; for t=i:-1:2 unit_movement=pose_data(t,3:5); translation = [cos(unit_movement(3)) -sin(unit_movement(3)) unit_movement(1); sin(unit_movement(3)) cos(unit_movement(3)) unit_movement(2); 0 0 1]*translation; end %translation = Odometry(current_index:current_index+1) + movement(1:2)'; Odometry(next_index:next_index+1) = translation(1:2); orientation = Odometry(current_index+2) + movement(3); if orientation > pi*2 orientation = orientation - pi*2; end Odometry(next_index+2) = orientation; end end %% Landmark data for i=1:size(landmark_data,1); unit_data = landmark_data(i,:); current_index = unit_data(1); next_index = unit_data(2) - pose_num; % should be changed to number of unique pose movement = unit_data(3:2+variable_size-1); %previous_theta = pose_data(i-1,2+variable_size); % Adjust index according to the size of each variable %if current_index ~= 1 current_index = (current_index - 1) * variable_size +1; %end if next_index ~= -1 next_index = (next_index - 1) * variable_size-1 + variable_size*pose_num + 1; end for j=0:variable_size-2 % Fill diagonal elements of Omega Omega(current_index+j,current_index+j) = Omega(current_index+j,current_index+j) + 1*motion_noise(j+1); Omega(next_index+j,next_index+j) = Omega(next_index+j,next_index+j) + 1/motion_noise(j+1); % Fill Off-diagonal elements of Omega Omega(current_index+j,next_index+j) = Omega(current_index+j,next_index+j) + (-1)/motion_noise(j+1); Omega(next_index+j,current_index+j) = Omega(next_index+j,current_index+j) + (-1)/motion_noise(j+1); % Fill Xi Xi(current_index+j) = Xi(current_index+j) + (-1)*movement(j+1)/motion_noise(j+1); Xi(next_index+j) = Xi(next_index+j) + movement(j+1)/motion_noise(j+1); end % Update Odometry %if abs(current_index - next_index) == 3 translation=[landmark_data(i,3:4)'; 1]; for t=unit_data(1):-1:2 unit_movement=pose_data(t,3:5); translation = [cos(unit_movement(3)) -sin(unit_movement(3)) unit_movement(1); sin(unit_movement(3)) cos(unit_movement(3)) unit_movement(2); 0 0 1]*translation; end %translation = Odometry(current_index:current_index+1) + movement(1:2)'; Odometry(next_index:next_index+1) = translation(1:2); %end end %Omega %Xi %mu = Omega^-1 * Xi % Using LM xdata = Omega; ydata = Xi; %myfun = @(x,xdata)Rot(x(1:3))*xdata+repmat(x(4:6),1,length(xdata)); myfun = @(x,xdata)xdata*x(1:size(xdata,1)); options = optimset('Algorithm', 'levenberg-marquardt'); %x = lsqcurvefit(myfun, zeros(6,1), p, q, [], [], options); x = lsqcurvefit(myfun, xinit, xdata, ydata, [], [], options) x_mat = vec2mat(x(1:pose_num*variable_size),3); Odometry_mat = vec2mat(Odometry(1:pose_num*variable_size),3); xinit_mat = vec2mat(xinit(1:pose_num*variable_size),3); x_lm_mat = vec2mat(x(1+pose_num*variable_size:end),2); Odometry_lm_mat = vec2mat(Odometry(1+pose_num*variable_size:end),2); xinit_lm_mat = vec2mat(xinit(1+pose_num*variable_size,end),2); plot(xinit_mat(:,1), xinit_mat(:,2) ,'bo-'); hold on; plot(Odometry_mat(:,1), Odometry_mat(:,2) ,'go-'); plot(x_mat(:,1), x_mat(:,2) ,'ro-'); plot(x_lm_mat(:,1), x_lm_mat(:,2) ,'bd'); plot(Odometry_lm_mat(:,1), Odometry_lm_mat(:,2) ,'gd'); plot(xinit_lm_mat(:,1), xinit_lm_mat(:,2) ,'rd'); hold off; legend('Initial','Odometry','Optimized','Initial LM','Odometry LM','Optimized LM'); %legend('Initial','Optimized'); end
github
rising-turtle/slam_matlab-master
generate_location_info.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/generate_location_info.m
2,639
utf_8
6d427ec892a4afe59429489cac5899bc
% Generate the location infomation for Text-To-Speech and plots % % Author : Soonhac Hong ([email protected]) % History : % 8/27/14 : Created % function [location_info, location_file_index] = generate_location_info(gtsam_pose_result, plot_xyz_result, location_file_index) import gtsam.* % Extract the optimized pose from gtsam data structure if the optimized pose is not available if isempty(plot_xyz_result) keys = KeyVector(gtsam_pose_result.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_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 end %% Generate the location information % %ex1 % location_info_list={'Room 222 is your left;',... % 'Room 230 is your right;',... % 'Room 245 is your left;',... % 'Room 300 is your right;'}; % short_location_info_list={'Rm 222',... % 'Rm 230',... % 'Rm 245',... % 'Rm 300'}; % location_info_xy=[0, 1; -0.1, 5; -0.5, 10; -7, 5]; % unit : [m] % etas 523 exp2 location_info_list={'Room 523 is your right;',... 'Room 526 is your left;',... 'Room 528 is your left;',... 'Room 527 is your right;',... 'Room 529 is your right;'}; short_location_info_list={'Rm 523',... 'Rm 526',... 'Rm 528',... 'Rm 527',... 'Rm 529'}; location_info_xy=[0, 2; -0.1, 5; 0.1, 8.5; 3.5, 8; 9, 7.7]; % unit : [m] % location_info_list={'Room 507 is your left;',... % 'Room 505 is your right;',... % 'Room 504 is your right;',... % 'Room 503 is your right;',... % 'Room 501 is your right;'}; % short_location_info_list={'Rm 507',... % 'Rm 505',... % 'Rm 504',... % 'Rm 503',... % 'Rm 501'}; % location_info_xy=[0, 11; 0, 12.5; 0, 16.5; 0, 18; -1, 19.5]; % unit : [m] location_threshold = 0.4; % [m] location_info_file_name = sprintf('C:\\SC-DATA-TRANSFER\\location_info_%d.txt', location_file_index); location_info=[]; current_position = [plot_xyz_result(end,1),plot_xyz_result(end,2),plot_xyz_result(end,3)]; % [x, y, z] for i=location_file_index:size(location_info_xy,1) distance = norm(current_position(1, 1:2) - location_info_xy(i,:)); if distance < location_threshold location_info = short_location_info_list{i}; % Write the location information to the location_info.txt fd = fopen(location_info_file_name, 'w'); fprintf(fd,'%s',location_info_list{i}); fclose(fd); location_file_index = location_file_index + 1; break; end end end
github
rising-turtle/slam_matlab-master
plot_isam.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot_isam.m
6,643
utf_8
b50a91a7288a763a25eedeb7ae97e1f4
% Plot the result of graph SLAM, isam % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function plot_isam(org_file_name, opt_file_name) [org_poses] = load_graph_isp(org_file_name); [opt_poses] = load_graph_isam(opt_file_name); % Show the pose start_index = 1; %end_index = min(size(org_poses,1), size(opt_poses)); %80; end_index = size(org_poses,1); if size(org_poses,2) == 2 % SE2 figure; plot(org_poses(start_index:end_index,1), org_poses(start_index:end_index,2),'b*-'); %xlabel('X [m]'); %ylabel('Y [m]'); %grid;[e_t_pose e_o_pose] = convert_o2p(f_index, t_pose, o_pose) %figure; hold on; plot(opt_poses(start_index:end_index,1), opt_poses(start_index:end_index,2),'ro-','LineWidth',2); %plot_groundtruth(); xlabel('X [m]'); ylabel('Y [m]'); grid; legend('vro','isam'); %,'eGT'); %xlim([-0.1 0.6]); %ylim([-0.1 0.6]); hold off; elseif size(org_poses,2) == 3 % SE3:QUAT figure; plot3(org_poses(:,1), org_poses(:,2), org_poses(:,3), 'b:', 'LineWidth',2); %xlabel('X [m]'); %ylabel('Y [m]'); %zlabel('Z [m]');plot_g2o.m %grid;[e_t_pose e_o_pose] = convert_o2p(f_index, t_pose, o_pose) %figure; hold on; plot3(opt_poses(:,1), opt_poses(:,2), opt_poses(:,3), 'r-.', 'LineWidth',2); %plot_groundtruth_3D(); %plot_gt_etas(); xlabel('X [m]'); ylabel('Y [m]'); zlabel('Z [m]'); legend('vro','isam','GT_e'); grid; axis equal; hold off; end end function plot_groundtruth() gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; gt_x = gt_x / 1000; % [mm] -> [m] gt_y = gt_y / 1000; % [mm] -> [m] plot(gt_x,gt_y,'g-','LineWidth',2); end function plot_groundtruth_3D() % inch2mm = 304.8; % 1 cube = 12 inch = 304.8 mm % gt_x = [0 0 13*inch2mm 13*inch2mm 0]; % gt_y = [-1*inch2mm 6*inch2mm 6*inch2mm -1*inch2mm -1*inch2mm]; % %gt_x = [0 0 2135 2135 0]; % %gt_y = [0 1220 1220 0 0]; % gt_z = [0 0 0 0 0]; % gt_x = gt_x / 1000; % [mm] -> [m] % gt_y = gt_y / 1000; % [mm] -> [m] % gt_z = gt_z / 1000; % [mm] -> [m] 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; gt_z = zeros(length(gt_x),1); plot3(gt_x,gt_y,gt_z,'g-','LineWidth',2); end % function [t_pose] = load_graph_sam(file_name) % fid = fopen(file_name); % data = textscan(fid, '%s %d %f %f %f '); % 2D format % fclose(fid); % % % Convert data % % Pose % data_name = data{1}; % data_name_list = {'ODOMETRY','LANDMARK','EDGE3','VERTEX_SE2'}; % vertex_index = 1; % edge_index = 1; % for i = 1 : size(data_name,1) % if strcmp(data_name{i}, data_name_list{4}) % VERTEX_SE2 % %unit_data =[]; % %for j=3:5 % % unit_data = [unit_data data{j}(i)]; % %end % f_index(vertex_index,:) = data{2}(i); % t_pose(vertex_index,:) = [data{3}(i) data{4}(i) 0]; % o_pose(vertex_index,:) = [ 0 0 data{5}(i)]; % vertex_index = vertex_index + 1; % % elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % % unit_data =[gt_y = gt_y / [e_t_pose e_o_pose] = convert_o2p(f_index, t_pose, o_pose)1000; % [mm] -> [m]]; % % for j=4:12 % % unit_data = [unit_data data{j}(i)]; % % end% elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % % unit_data =[]; % % for j=4:12 % % unit_data= [unit_data data{j}(i)]; % % end % % edges(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % % % edges(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % % elseif strcmp(data_name{i}, data_name_list{3}) % VERTEX_SE3:QUAT % % unit_data =[]; % % for j=3:9 % % unit_data = [unit_data data{j}(i)]; % % end % % poses(vertex_index,:) = unit_data; % % vertex_index = vertex_index + 1; % % elseif strcmp(data_name{i}, data_name_list{4}) % EDGE_SE3:QUAT % % unit_data =[]; % % for j=2:31 % % unit_data = [unit_data data{j}(i)]; % % end % % edge[e_t_pose e_o_pose] = convert_o2p(f_index, t_pose, o_pose)s(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % end % % end % end % function [poses] = load_graph_opt(file_name) % fid = fopen(file_name); % % % % Convert data % % Pose % % data_name_list = {'Pose2d_Node','Pose2d_Pose2d_Factor'}; % vertex_index = 1; % edge_index = 1; % while ~feof(fid) %for i = 1 : size(data_name,1) % header = textscan(fid, '%s',1); % 2D format % data_name = header{1}; % if strcmp(data_name, data_name_list{1}) % VERTEX_SE2 % data = textscan(fid, '%f (%f,%f,%f)'); % unit_data =[]; % for j=1:4 % unit_data = [unit_data data{j}]; % end % f_index(vertex_index, :) = unit_data(1); % t_pose(vertex_index,:) = [unit_data(2:3) 0]; % o_pose(vertex_index,:) = [0 0 unit_data(4)]; % vertex_index = vertex_index + 1; % % elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % % unit_data =[]; % % for j=4:12 % % unit_data= [unit_data data{j}(i)]; % % end % % edges(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % % elseif strcmp(data_name{i}, data_name_list{3}) % VERTEX_SE3:QUAT % % unit_data =[]; % % for j=3:9 % % unit_data = [unit_data data{j}(i)]; % % end % % poses(vertex_index,:) = unit_data; % % vertex_index = vertex_index + 1; % % elseif strcmp(data_name{i}, data_name_list{4}) % EDGE_SE3:QUAT % % unit_data =[]; % % for j=2:31 % % unit_data = [unit_data data{j}(i)]; % % end % % edges(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % end % % end % fclose(fid); % poses = [t_pose(:,1:2) o_pose(:,3)]; % end
github
rising-turtle/slam_matlab-master
load_graph_g2o.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/load_graph_g2o.m
2,350
utf_8
90f4a5ad47e0b0c319d82f953af06196
% Load graph of vro function [poses edges fpts_poses fpts_edges] = load_graph_g2o(file_name) fid = fopen(file_name); data = textscan(fid, '%s %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 %f %f %f'); % 2D format fclose(fid); % Convert data % Pose data_name = data{1}; data_name_list = {'VERTEX_SE2','EDGE_SE2','VERTEX_SE3:QUAT','EDGE_SE3:QUAT'}; fpts_name_list ={'VERTEX_XY','EDGE_SE2_XY'}; vertex_index = 1; edge_index = 1; fpts_pose_index =1; fpts_edge_index =1; fpts_poses =[]; fpts_edges =[]; for i = 1 : size(data_name,1) if strcmp(data_name{i}, data_name_list{1}) % VERTEX_SE2 unit_data =[]; for j=3:5 unit_data = [unit_data data{j}(i)]; end poses(vertex_index,:) = unit_data; vertex_index = vertex_index + 1; elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 unit_data =[]; for j=2:12 unit_data = [unit_data data{j}(i)]; end edges(edge_index,:) = unit_data; edge_index = edge_index + 1; elseif strcmp(data_name{i}, fpts_name_list{1}) % VERTEX_XY unit_data =[]; for j=3:5 unit_data = [unit_data data{j}(i)]; end fpts_poses(fpts_pose_index,:) = unit_data; fpts_pose_index = fpts_pose_index + 1; elseif strcmp(data_name{i}, fpts_name_list{2}) % EDGE_SE2_XY unit_data =[]; for j=2:12 unit_data = [unit_data data{j}(i)]; end fpts_edges(fpts_edge_index,:) = unit_data; fpts_edge_index = fpts_edge_index + 1; elseif strcmp(data_name{i}, data_name_list{3}) % VERTEX_SE3:QUAT unit_data =[]; for j=3:9 unit_data = [unit_data data{j}(i)]; end poses(vertex_index,:) = unit_data; vertex_index = vertex_index + 1; elseif strcmp(data_name{i}, data_name_list{4}) % EDGE_SE3:QUAT unit_data =[]; for j=2:31 unit_data = [unit_data data{j}(i)]; end edges(edge_index,:) = unit_data; edge_index = edge_index + 1; end end end
github
rising-turtle/slam_matlab-master
Convert_map.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/Convert_map.m
2,344
utf_8
43aaeae9934a5b80a0b75f7f680234ef
% Convert map based its locations % % Author : Soonhac Hong ([email protected]) % Date : 5/16/14 function Convert_map() %input_file_name = 'D:\Soonhac\SW\GraphSLAM\results\isam\3d\revisiting9_10m_Replace_pose_zero_827_vro_gtsam_feature_total_v1.ply'; %output_file_name = 'D:\Soonhac\SW\GraphSLAM\results\isam\3d\revisiting9_10m_Replace_pose_zero_827_vro_gtsam_feature_total_v21.ply'; input_file_name = 'D:\Soonhac\SW\GraphSLAM\results\isam\3d\revisiting9_10m_Replace_pose_zero_827_vro_gtsam_feature_v1.ply'; output_file_name = 'D:\Soonhac\SW\GraphSLAM\results\isam\3d\revisiting9_10m_Replace_pose_zero_827_vro_gtsam_feature_v2.ply'; %% Load an input file fid = fopen(input_file_name); if fid < 0 error(['Cannot open file ' input_file_name]); end % scan all lines into a cell array columns=textscan(fid,'%s','delimiter','\n'); lines=columns{1}; fclose(fid); %% Convert the color of a trajectory x_threshold_min = -4; x_threshold_max = 0.5; y_threshold_min = -3; y_threshold_max = 7; z_threshold = -0.67; new_data=[]; new_data_index = 1; for i=1:size(lines,1) i line_i=lines{i}; if i > 12 % check intensity data v = textscan(line_i,'%f %f %f %d %d %d',1); if v{1} < x_threshold_max && v{1} > x_threshold_min && v{2} < y_threshold_max && v{2} > y_threshold_min if v{3} < z_threshold new_data(new_data_index, :)=[v{1},v{2},v{3},double(v{4}),double(v{5}),double(v{6})]; new_data_index = new_data_index + 1; %fprintf(fd,'%f %f %f %d %d %d\n',v{1},v{2},v{3}, target_color); end else new_data(new_data_index, :)=[v{1},v{2},v{3},double(v{4}),double(v{5}),double(v{6})]; new_data_index = new_data_index + 1; end end end %% Write data ply_headers={'ply','format ascii 1.0','comment Created with XYZRGB_to_PLY', 'element_vertex_dummy', 'property float x', 'property float y','property float z','property uchar red','property uchar green','property uchar blue','end_header'}; nply_data = size(new_data,1) element_vertex_n = sprintf('element vertex %d',nply_data); ply_headers{4} = element_vertex_n; fd = fopen(output_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',new_data(i,:)); end fclose(fd); end
github
rising-turtle/slam_matlab-master
get_global_transformation_dataname.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/get_global_transformation_dataname.m
11,980
utf_8
8be9a4cd85dc54f2a37329cbcb602d99
% Get global transformation for each data set % % Author : Soonhac Hong ([email protected]) % Date : 10/22/12 function [h_global] = get_global_transformation_dataname(data_name, dynamic_index, isgframe) addpath('..\slamtoolbox\slamToolbox_11_09_08\FrameTransforms\Rotations'); % rx, ry, rz : [degree] % tx, ty, tz : [mm] rx=0; ry=0; rz=0; tx=0; ty=0; tz=0; switch data_name case {'square'} switch dynamic_index case 16 %h_global = [euler_to_rot(0, -15.4, 0) [0 0 0]'; 0 0 0 1]; % square_700 rx = -15.4; end case {'etas'} switch dynamic_index case 1 %h_global = [euler_to_rot(0, -36.3, 0) [0 0 0]'; 0 0 0 1]; % etas %rx = -36.3; rx = -29.5089; ry = 1.1837; rz=3.6372; case 3 rx = -28.9278; ry = 1.1894; rz=0.8985; case 5 rx = -29.2181; ry = 1.1830; rz=1.8845; end case {'loops'} switch dynamic_index case 2 %h_global = [euler_to_rot(1.23, -25.6, 3.51) [0 0 0]'; 0 0 0 1]; % loops_2 rx=-25.6; ry=1.23; rz=3.51; case 3 %h_global =[euler_to_rot(1.2670, -24.3316, 4.6656) [0 0 0]'; 0 0 0 1]; %loops_3 rx=-24.3316; ry=1.2670; rz=0; %4.6656; case 13 rx=-25.6109; ry=1.2418; rx=3.8448 end case {'kinect_tum'} switch dynamic_index case 2 % start image : 13050033527.670034 % Groundtruth : 1305033527.6662 1.4906 -1.1681 0.6610 0.8959 0.0713 -0.0460 -0.4361 init_qauterion = [0.8959, 0.0713, -0.046, -0.4361]; % temp_rot = q2R(init_qauterion); % [r1, r2, r3] = rot_to_euler(temp_rot); % r2d = 180 / pi; % temp_rot = euler_to_rot(r2*r2d, r1*r2d, r3*r2d); temp_r = q2e(init_qauterion) * 180 / pi; %temp_rot = euler_to_rot(temp_r(2), temp_r(1), temp_r(3)); % degree %temp_rot = euler_to_rot(45, -45, 90) * temp_rot ; %[temp_r(2) temp_r(1) temp_r(3)] = rot_to_euler(temp_rot); temp_trans = [1.4906 -1.1681 0.661]*1000; %temp_r = temp_r * 180 / pi; rx = temp_r(1); ry = temp_r(2); rz = temp_r(3); %rx =0; ry =0; rz=0; tx = temp_trans(1); ty = temp_trans(2); tz = temp_trans(3); end case {'loops2', 'amir_vro'} switch dynamic_index case 1 %h_global =[euler_to_rot(1.2670, -24.3316, 4.6656) [0 0 0]'; 0 0 0 1]; %loops_3 rx=-24.4985419798496; ry=1.26190320102629; rz=4.69088809909393; %4.6656; case 2 rx=-23.3420; ry=1.2739; rz=4.3772; case 3 rx=-24.5234; ry=1.2565; rz=4.2682; case 4 rx=-24.2726; ry=1.2606; rz=2.7462; case 5 rx=-26.6191; ry=1.2173; rz=5.0601; %2.7462; case 6 rx=-25.7422; ry=1.2396; rz=3.0821; case 7 rx=-24.6791; ry=1.2562; rz=4.1917; %3.0821; case 8 %h_global =[euler_to_rot(1.2670, -24.3316, 4.6656) [0 0 0]'; 0 0 0 1]; %loops_3 rx=-23.8464; ry=1.2721; rz= 3.7964; %3.75437022813459; %init_qauterion = [0.977813222516827,-0.206522692608165,0.00392574917797234,0.0348463456121639]; %temp_r = q2e(init_qauterion) * 180 / pi; %rx = temp_r(1); ry = temp_r(2); rz = temp_r(3); case 9 rx=-25.6806; ry=1.2383; rz=3.4203; case 10 rx=-25.1216960394087; ry=1.25311495911881; rz=-0.909688742543562; case 11 %h_global = [euler_to_rot(1.23, -25.6, 3.51) [0 0 0]'; 0 0 0 1]; % loops_2 %rx=-25.6; ry=1.23; rz=3.51; rx=-33.7709; ry=1.0903; rz=3.0738; case 12 % same as exp 7 rx=-24.6791; ry=1.2562; rz=4.1917; %3.0821; end case {'sparse_feature'} switch dynamic_index case 1 rx=-29.9267; ry=1.1978; rz=0; %-2.6385; %4.69088809909393; %4.6656; case 2 rx=-28.7386; ry=1.2247; rz=0.8001; %-2.6385; %4.69088809909393; %4.6656; case 3 rx=-31.1218; ry=1.1713; rz=-1.7365; case 4 rx=-29.3799; ry=1.2133; rz=-2.4075; case {5,6,7,8} rx = -39.1930; ry = 1.0134; rz = -1.2122; case {9, 10, 11} rx = -37.1533; ry = 1.0455; rz = -3.0266; case {12,16} rx = -38.3570; ry = 1.0315; rz = -0.3114; case 13 rx=-28.3021; ry=1.2357; rz=-1.3391; case 14 rx=-29.1073; ry=1.2133; rz=-0.5520; end case {'swing','swing2'} switch dynamic_index case 1 rx=-32.2179; ry=1.1567; rz=-1.1344; case 2 rx=-28.6379; ry=1.2207; rz=-1.5099; case 3 rx=-33.3490; ry=1.1279; rz=-3.1225; case 4 rx=-31.0073; ry=1.1770; rz=-0.6052; case 5 rx=-31.7611; ry=1.1627; rz=-0.9156; case 7 rx=-19.2560; ry=0.8450; rz=0.5809; case 8 rx=-17.5219; ry=0.8546; rz=-4.5522; case 9 rx=-17.2286; ry=0.8616; rz=-3.4105; case 10 rx=-18.1945; ry=0.8501; rz=1.4029; case 11 rx=-18.2734; ry=0.8556; rz=0.2481; case 12 rx=-24.4356; ry=0.7918; rz=-0.9333; case 13 rx=-17.2649; ry=0.8549; rz=-2.8848; case 14 rx=-20.1519; ry=0.8284; rz=-1.3661; case 15 rx=-20.5691; ry=0.8302; rz=-0.7713; case 16 rx=-19.8892; ry=0.8389; rz=-1.3603; case 17 rx=-24.4211; ry=0.7959; rz=-3.0972; case 18 rx=-21.7207; ry=0.8163; rz=-4.3600; case 19 rx=-19.3202; ry=0.8454; rz=-2.7863; case 20 rx=-20.2662; ry=0.8354; rz=-2.5763; case 21 rx=-19.5310; ry=0.8403; rz=-1.9310; case 22 rx=-18.3081; ry=0.8536; rz=-4.6978; case 23 rx=-16.7653; ry=0.8678; rz=-4.2483; case 24 rx=-16.4797; ry=0.8697; rz=-2.3778; case 25 rx=-17.3060; ry=0.8587; rz=-3.1753; case 26 rx=-16.9306; ry=0.8576; rz=-2.6512; end case {'motive'} switch dynamic_index case 1 rx=-22.2924; ry=0.8198; rz=-4.3367; case 2 rx=-23.9217; ry=0.7990; rz=-3.1450; case 11 rx=-17.5025; ry=1.3989; rz=-1.5120; case 12 rx=-17.1856; ry=1.4018; rz=-0.3795; case 13 rx=-16.8428; ry=0.8657; rz=-4.1148; case 15 rx=-20.3861; ry=0.8323; rz=-4.4565; case 16 rx=-21.2226; ry=0.8261; rz=-6.5253; case 17 rx=-19.2100; ry=1.3724; rz=-4.0953; case 18 rx=-18.4614; ry=1.3822; rz=-2.2221; case 19 rx=-14.2685; ry=0.8810; rz=-2.4514; case 20 rx=-14.8030; ry=0.8806; rz=-3.6865; case 21 rx=-18.6913; ry=0.8436; rz=-1.3773; case 22 rx=-15.3041; ry=0.8815; rz=0.3623; case 23 %rx=-14.6923; ry=0.8813; rz=0.5994; rx=-15.8020; ry=0.8704; rz=-1.0940; case 24 %rx=-13.9262; ry=0.8867; rz=2.9371; rx=-13.4739; ry=0.8915; rz=-3.8607; case 25 %rx=-12.5003; ry=0.8973; rz=-1.6229; rx=-12.5852; ry=0.8966; rz=-1.7487; case 26 %rx=-13.1931; ry=0.8922; rz=0.3750; rx=-13.1931; ry=0.8922; rz=0.3750; case 27 rx=-13.7715; ry=0.8868; rz=0.7914; case 28 rx=-14.2207; ry=0.8836; rz=-1.8911; case 29 rx=-13.4205; ry=0.8920; rz=-1.8912; case 30 rx=-15.2320; ry=0.8793; rz=-0.8757; case 31 rx=-15.8020; ry=0.8704; rz=-1.0940; case 32 rx=-18.3082; ry=1.3832; rz=2.6882; case 33 rx=-18.3023; ry=1.3870; rz=-0.4907; case 34 rx=-16.3416; ry=1.4141; rz=-1.3016; case 35 rx=-15.9030; ry=1.4182; rz=-2.7589; case 36 rx=-18.8863; ry=1.3755; rz=-4.6635; case 37 rx=-15.9639; ry=1.4180; rz=0.1582; end case {'object_recognition'} switch dynamic_index case 1 rx=-37.7656; ry=1.0435; rz=-5.2416; case 2 rx=-9.4696; ry=0.9351; rz=8.0194; case 3 rx=-49.0312; ry=0.4693; rz=17.9271; case 4 rx = -102.3278; ry=-0.4342; rz=-4.9235; case 5 rx=-36.4384; ry=1.0755; rz=22.0853; case 6 rx=-36.8751; ry=1.0886; rz=24.7719; case 7 rx = -26.0697; ry=1.2667; rz=3.3011; case 8 rx = -34.3278; ry=0.6732; rz=3.7436; case 9 rx = -28.8132; ry=0.7380; rz=10.7045; case 10 rx = -35.7148; ry=0.6569; rz=-10.9565; case 11 rx = -27.3853; ry=0.7568; rz=-7.5140; end case {'map'} switch dynamic_index case 2 rx=-20.9872; ry=0.8237; rz= -1.6569; case 3 rx=-21.9661; ry=0.8124; rz=1.3211; case 4 rx=-20.0099; ry=0.8344; rz=3.4412; case 5 rx=-20.7988; ry=0.8285; rz=-1.4896; case 6 %rx=-20.8341; ry=0.8281; rz=-1.5208; rx=-17.5434; ry=1.4023; rz=-0.4495; case 7 rx=-19.7766; ry=1.3672; rz=-2.9528; case 8 rx=-20.7362; ry=1.3549; rz=-3.8060; case 9 rx=-17.1903; ry=1.4010; rz=0.2855; end end %h_global_tf = [euler_to_rot(0, 90, 0) [0 0 0]'; 0 0 0 1]; if strcmp(isgframe, 'gframe') h_global = [e2R([rx*pi/180, ry*pi/180, rz*pi/180]) [tx ty tz]'; 0 0 0 1]; else %h_global = [euler_to_rot(ry, rx, rz) [tx ty tz]'; 0 0 0 1]; h_global = [euler_to_rot(rz, rx, ry) [tx ty tz]'; 0 0 0 1]; end %h_global = h_global * h_global_tf; %h_global = [euler_to_rot(0, 0, 15) [tx ty tz]'; 0 0 0 1]; %h_global = [euler_to_rot(rz, rx, ry) [tx ty tz]'; 0 0 0 1]; %h_global = [euler_to_rot(0, 0, 0) [0 0 0]'; 0 0 0 1]; %h_global = [euler_to_rot(0, -23.8, 0) [0 0 0]'; 0 0 0 1]; % square_1000 %init_qauterion = [0.8959, 0.0695, -0.0461, -0.4364]; %temp_rot = q2R(init_qauterion); %[r1, r2, r3] = rot_to_euler(temp_rot); %r2d = 180 / pi; %temp_rot = euler_to_rot(r2*r2d, r1*r2d, r3*r2d); %temp_r = q2v(init_qauterion) * 180 / pi; %temp_rot = euler_to_rot(temp_r(2), temp_r(1), temp_r(3)); % degree %temp_trans = [1.4908 -1.1707 0.6603]*1000; %h_global = [temp_rot temp_trans'; 0 0 0 1]; % kinect_tum %h_global_temp = [euler_to_rot(90, 0, 90) [0 0 0]'; 0 0 0 1]; % ????? %h_global_temp = [[1 0 0; 0 0 -1; 0 1 0] [0 0 0]'; 0 0 0 1]; %h_global = h_global * h_global_temp; %h_global = [euler_to_rot(0, 0, 0) temp_trans'; 0 0 0 1]; end
github
rising-turtle/slam_matlab-master
Convert_map_culling.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/Convert_map_culling.m
1,973
utf_8
5f09a0f4dbe560f1581a95e4b29f0753
% Convert map based its locations % % Author : Soonhac Hong ([email protected]) % Date : 5/16/14 function Convert_map_culling() %input_file_name = 'D:\Soonhac\SW\GraphSLAM\results\isam\3d\revisiting9_10m_Replace_pose_zero_827_vro_gtsam_feature_total_v1.ply'; %output_file_name = 'D:\Soonhac\SW\GraphSLAM\results\isam\3d\revisiting9_10m_Replace_pose_zero_827_vro_gtsam_feature_total_v21.ply'; input_file_name = 'D:\Soonhac\SW\GraphSLAM\results\isam\3d\revisiting9_10m_Replace_pose_zero_827_vro_gtsam_feature_v2.ply'; output_file_name = 'D:\Soonhac\SW\GraphSLAM\results\isam\3d\revisiting9_10m_Replace_pose_zero_827_vro_gtsam_feature_v3.ply'; %% Load an input file fid = fopen(input_file_name); if fid < 0 error(['Cannot open file ' input_file_name]); end % scan all lines into a cell array columns=textscan(fid,'%s','delimiter','\n'); lines=columns{1}; fclose(fid); %% Convert the color of a trajectory x_threshold_min = -4; x_threshold_max = 0.5; y_threshold_min = -3; y_threshold_max = 7; z_threshold = -0.67; new_data=[]; new_data_index = 1; for i=1:size(lines,1) i line_i=lines{i}; if i > 12 % check intensity data if mod(i,2) == 0 v = textscan(line_i,'%f %f %f %d %d %d',1); new_data(new_data_index, :)=[v{1},v{2},v{3},double(v{4}),double(v{5}),double(v{6})]; new_data_index = new_data_index + 1; end end end %% Write data ply_headers={'ply','format ascii 1.0','comment Created with XYZRGB_to_PLY', 'element_vertex_dummy', 'property float x', 'property float y','property float z','property uchar red','property uchar green','property uchar blue','end_header'}; nply_data = size(new_data,1) element_vertex_n = sprintf('element vertex %d',nply_data); ply_headers{4} = element_vertex_n; fd = fopen(output_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',new_data(i,:)); end fclose(fd); end
github
rising-turtle/slam_matlab-master
load_graph_toro.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/load_graph_toro.m
2,468
utf_8
9ad77c44caa6bd902416b9677c82e351
% Plot the data of TORO % Author : Soonhac Hong ([email protected]) % Date : 4/19/2012 function [poses edges fpts_poses fpts_edges] = load_graph_toro(file_name) fid = fopen(file_name); data = textscan(fid, '%s %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 %f %f %f'); % 2D format fclose(fid); % Convert data % Pose data_name = data{1}; data_name_list = {'VERTEX','EDGE','VERTEX2','EDGE2','VERTEX3','EDGE3'}; fpts_name_list ={'VERTEX_XY','EDGE_SE2_XY'}; vertex_index = 1; edge_index = 1; fpts_pose_index =1; fpts_edge_index =1; fpts_poses =[]; fpts_edges =[]; for i = 1 : size(data_name,1) if strcmp(data_name{i}, data_name_list{1}) || strcmp(data_name{i}, data_name_list{3}) % VERTEX unit_data =[]; for j=3:5 unit_data = [unit_data data{j}(i)]; end poses(vertex_index,:) = unit_data; vertex_index = vertex_index + 1; elseif strcmp(data_name{i}, data_name_list{2}) || strcmp(data_name{i}, data_name_list{4}) % EDGE unit_data =[]; for j=2:12 unit_data = [unit_data data{j}(i)]; end edges(edge_index,:) = unit_data; edge_index = edge_index + 1; elseif strcmp(data_name{i}, fpts_name_list{1}) % VERTEX_XY unit_data =[]; for j=3:5 unit_data = [unit_data data{j}(i)]; end fpts_poses(fpts_pose_index,:) = unit_data; fpts_pose_index = fpts_pose_index + 1; elseif strcmp(data_name{i}, fpts_name_list{2}) % EDGE_SE2_XY unit_data =[]; for j=2:12 unit_data = [unit_data data{j}(i)]; end fpts_edges(fpts_edge_index,:) = unit_data; fpts_edge_index = fpts_edge_index + 1; elseif strcmp(data_name{i}, data_name_list{5}) % VERTEX3 unit_data =[]; for j=3:8 unit_data = [unit_data data{j}(i)]; end poses(vertex_index,:) = unit_data; vertex_index = vertex_index + 1; elseif strcmp(data_name{i}, data_name_list{6}) % EDGE3 unit_data =[]; for j=2:30 unit_data = [unit_data data{j}(i)]; end edges(edge_index,:) = unit_data; edge_index = edge_index + 1; end end
github
rising-turtle/slam_matlab-master
graph_slam_1d.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/graph_slam_1d.m
2,026
utf_8
0855b87c8e04ca339c4e5517526e64ec
% 1-D graph SLAM % Data : 4/12/12 % Author : Soonhac Hong ([email protected]) function graph_slam_1d() % Data %pose_data = [1 1 -3; 1 2 5; 2 3 3]; % first row : initial pose, second row : [1]= current index, [2] = next index, [3] = movement %result = [-3; 2; 5]; % pose_data =[1 1 0; 1 2 3; 2 3 4; 1 3 6; 3 4 2]; % % [-9.66914000000000,10.9800100000000,6.85198000000000;] % [-12.9620100000000,25.6074800000000,18.3592900000000;] % [-0.776060000000000,16.2314800000000,6.47385000000000;] % [-4.67272000000000,36.1912600000000,18.4479100000000;] % [0.930870000000000,38.1723100000000,17.0636200000000;] pose_data =[1 1 0; 1 2 -9.66914000000000; 2 3 -12.9620100000000; 3 4 -0.776060000000000; 4 5 -4.67272000000000; 5 6 0.930870000000000]; motion_noise = 1.0; pose_num = size(unique(pose_data(:,1:2)),1); Omega = zeros(pose_num,pose_num); Xi = zeros(pose_num,1); Odometry = zeros(pose_num,1); % Fill the elements of Omega and Xi Omega(1,1) = 1; Xi(1) = pose_data(1,3); Odometry = pose_data(1,3); for i=2:size(pose_data,1); unit_data = pose_data(i,:); current_index = unit_data(1); next_index = unit_data(2); movement = unit_data(3); % Fill diagonal elements of Omega Omega(current_index,current_index) = Omega(current_index,current_index) + 1/motion_noise; Omega(next_index,next_index) = Omega(next_index,next_index) + 1/motion_noise; % Fill Off-diagonal elements of Omega Omega(current_index,next_index) = Omega(current_index,next_index) + (-1)/motion_noise; Omega(next_index,current_index) = Omega(next_index,current_index) + (-1)/motion_noise; % Fill Xi Xi(current_index) = Xi(current_index) + (-1)*movement/motion_noise; Xi(next_index) = Xi(next_index) + movement/motion_noise; % Update Odometry if abs(current_index - next_index) == 1 Odometry(next_index) = Odometry(next_index-1) + movement; end end Omega Xi mu = Omega^-1 * Xi plot(Odometry,'bd-'); hold on; plot(mu,'ro-'); hold off; legend('Odometry','Optimized'); end
github
rising-turtle/slam_matlab-master
plot_gtsam.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot_gtsam.m
8,191
utf_8
32b10ae3e271c52b77844abca2c62522
% Plot the result of graph SLAM, isam % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function plot_gtsam(org_file_name, opt_file_name) [org_poses] = load_graph_isp(org_file_name); [opt_poses] = load_graph_isp(opt_file_name); compute_trajectory_error(org_poses, opt_poses); % Show the pose start_index = 1; %end_index = min(size(org_poses,1), size(opt_poses)); %80; end_index = size(org_poses,1); if size(org_poses,2) == 2 % SE2 figure; plot(org_poses(start_index:end_index,1), org_poses(start_index:end_index,2),'b*-'); %xlabel('X [m]'); %ylabel('Y [m]'); %grid;[e_t_pose e_o_pose] = convert_o2p(f_index, t_pose, o_pose) %figure; hold on; plot(opt_poses(start_index:end_index,1), opt_poses(start_index:end_index,2),'ro-','LineWidth',2); %plot_groundtruth(); xlabel('X [m]'); ylabel('Y [m]'); grid; legend('vro_icp','gtsam'); %,'eGT'); %xlim([-0.1 0.6]); %ylim([-0.1 0.6]); hold off; elseif size(org_poses,2) == 3 % SE3:QUAT figure; plot3(org_poses(:,1), org_poses(:,2), org_poses(:,3), 'b:', 'LineWidth',2); %xlabel('X [m]'); %ylabel('Y [m]'); %zlabel('Z [m]');plot_g2o.m %grid;[e_t_pose e_o_pose] = convert_o2p(f_index, t_pose, o_pose) %figure; hold on; plot3(opt_poses(:,1), opt_poses(:,2), opt_poses(:,3), 'r-.', 'LineWidth',2); %plot_groundtruth_3D(); %plot_gt_etas(); xlabel('X [m]'); ylabel('Y [m]'); zlabel('Z [m]'); legend('vro icp','gtsam','GT_e'); grid; axis equal; hold off; end end function compute_trajectory_error(org_poses, opt_poses) %Compute trajectory percentage error % org_poses(end,:) % opt_poses(end,:) org_poses_first_last_distance = sqrt(sum(abs(org_poses(1,:)-org_poses(end,:)).^2)) opt_poses_first_last_distance = sqrt(sum(abs(opt_poses(1,:)-opt_poses(end,:)).^2)) %Compute trajectory length org_poses_trajectory_length = 0; opt_poses_trajectory_length = 0; for i=1:size(org_poses,1)-1 org_poses_trajectory_length = org_poses_trajectory_length + sqrt(sum(abs(org_poses(i,:)-org_poses(i+1,:)).^2)); end for i=1:size(org_poses,1)-1 opt_poses_trajectory_length = opt_poses_trajectory_length + sqrt(sum(abs(opt_poses(i,:)-opt_poses(i+1,:)).^2)); end org_poses_trajectory_length opt_poses_trajectory_length %Compute percentage error org_poses_trajectory_error = org_poses_first_last_distance * 100 / org_poses_trajectory_length opt_poses_trajectory_error = opt_poses_first_last_distance * 100 / opt_poses_trajectory_length % %Compute height error % org_poses_delta = abs(org_poses - repmat(org_poses(1,:), size(org_poses,1),1)); % opt_poses_delta = abs(opt_poses - repmat(opt_poses(1,:), size(opt_poses,1),1)); % % mean_org_poses_delta_height = mean(org_poses_delta(:,3)) % mean_opt_poses_delta_height = mean(opt_poses_delta(:,3)) % % % Show height error % figure; % plot(org_poses_delta(:,3),'b-'); % hold on; % plot(opt_poses_delta(:,3),'r-'); % legend('vro','gtsam'); % grid; % ylabel('height error [m]'); % xlabel('Step'); % hold off; end function plot_groundtruth() gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; gt_x = gt_x / 1000; % [mm] -> [m] gt_y = gt_y / 1000; % [mm] -> [m] plot(gt_x,gt_y,'g-','LineWidth',2); end function plot_groundtruth_3D() % inch2mm = 304.8; % 1 cube = 12 inch = 304.8 mm % gt_x = [0 0 13*inch2mm 13*inch2mm 0]; % gt_y = [-1*inch2mm 6*inch2mm 6*inch2mm -1*inch2mm -1*inch2mm]; % %gt_x = [0 0 2135 2135 0]; % %gt_y = [0 1220 1220 0 0]; % gt_z = [0 0 0 0 0]; % gt_x = gt_x / 1000; % [mm] -> [m] % gt_y = gt_y / 1000; % [mm] -> [m] % gt_z = gt_z / 1000; % [mm] -> [m] 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; gt_z = zeros(length(gt_x),1); plot3(gt_x,gt_y,gt_z,'g-','LineWidth',2); end % function [t_pose] = load_graph_sam(file_name) % fid = fopen(file_name); % data = textscan(fid, '%s %d %f %f %f '); % 2D format % fclose(fid); % % % Convert data % % Pose % data_name = data{1}; % data_name_list = {'ODOMETRY','LANDMARK','EDGE3','VERTEX_SE2'}; % vertex_index = 1; % edge_index = 1; % for i = 1 : size(data_name,1) % if strcmp(data_name{i}, data_name_list{4}) % VERTEX_SE2 % %unit_data =[]; % %for j=3:5 % % unit_data = [unit_data data{j}(i)]; % %end % f_index(vertex_index,:) = data{2}(i); % t_pose(vertex_index,:) = [data{3}(i) data{4}(i) 0]; % o_pose(vertex_index,:) = [ 0 0 data{5}(i)]; % vertex_index = vertex_index + 1; % % elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % % unit_data =[gt_y = gt_y / [e_t_pose e_o_pose] = convert_o2p(f_index, t_pose, o_pose)1000; % [mm] -> [m]]; % % for j=4:12 % % unit_data = [unit_data data{j}(i)]; % % end% elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % % unit_data =[]; % % for j=4:12 % % unit_data= [unit_data data{j}(i)]; % % end % % edges(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % % % edges(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % % elseif strcmp(data_name{i}, data_name_list{3}) % VERTEX_SE3:QUAT % % unit_data =[]; % % for j=3:9 % % unit_data = [unit_data data{j}(i)]; % % end % % poses(vertex_index,:) = unit_data; % % vertex_index = vertex_index + 1; % % elseif strcmp(data_name{i}, data_name_list{4}) % EDGE_SE3:QUAT % % unit_data =[]; % % for j=2:31 % % unit_data = [unit_data data{j}(i)]; % % end % % edge[e_t_pose e_o_pose] = convert_o2p(f_index, t_pose, o_pose)s(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % end % % end % end % function [poses] = load_graph_opt(file_name) % fid = fopen(file_name); % % % % Convert data % % Pose % % data_name_list = {'Pose2d_Node','Pose2d_Pose2d_Factor'}; % vertex_index = 1; % edge_index = 1; % while ~feof(fid) %for i = 1 : size(data_name,1) % header = textscan(fid, '%s',1); % 2D format % data_name = header{1}; % if strcmp(data_name, data_name_list{1}) % VERTEX_SE2 % data = textscan(fid, '%f (%f,%f,%f)'); % unit_data =[]; % for j=1:4 % unit_data = [unit_data data{j}]; % end % f_index(vertex_index, :) = unit_data(1); % t_pose(vertex_index,:) = [unit_data(2:3) 0]; % o_pose(vertex_index,:) = [0 0 unit_data(4)]; % vertex_index = vertex_index + 1; % % elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % % unit_data =[]; % % for j=4:12 % % unit_data= [unit_data data{j}(i)]; % % end % % edges(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % % elseif strcmp(data_name{i}, data_name_list{3}) % VERTEX_SE3:QUAT % % unit_data =[]; % % for j=3:9 % % unit_data = [unit_data data{j}(i)]; % % end % % poses(vertex_index,:) = unit_data; % % vertex_index = vertex_index + 1; % % elseif strcmp(data_name{i}, data_name_list{4}) % EDGE_SE3:QUAT % % unit_data =[]; % % for j=2:31 % % unit_data = [unit_data data{j}(i)]; % % end % % edges(edge_index,:) = unit_data; % % edge_index = edge_index + 1; % end % % end % fclose(fid); % poses = [t_pose(:,1:2) o_pose(:,3)]; % end
github
rising-turtle/slam_matlab-master
convert_pc2ply_map_registration_v2.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/convert_pc2ply_map_registration_v2.m
5,723
utf_8
cdf00bc9983ff11fc3c1ea7f124934dc
% Write 3D point clouds to a ply file using map registration algorithm % Conver isp to ply for meshlab % % Author : Soonhac Hong ([email protected]) % History : % 1/8/14 : Created % 2/27/14 : Update map by mean value of correspondence and include quality % factor function convert_pc2ply_map_registration_v2(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_mag_reg_v2.ply') feature_ct_file_name=strrep(ply_file_name, '.ply','_feature_mag_reg_v2.ct') % Write headers pose_interval = 1; sample_interval = 2; image_width = 176; 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; %8; %5; distance_threshold_min = 0.8; ply_data=[]; ply_data_index = 1; map=[]; map_kd_tree=[]; map_quality=[]; 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'); 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; unit_map=[]; 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 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 unit_pose_global = h{i}*[unit_pose, 1]'; [map_registration_flag, unit_map_quality, map]=check_map_registration(map_kd_tree, map, [unit_pose_global(1:3,1)', double(img(row_idx, col_idx))]); if map_registration_flag 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)]; unit_map(ply_data_index,:) = [unit_pose_global(1:3,1)', double(unit_color(1)), 0, 1]; %[x,y,z,gray,radius,n] ply_data_index = ply_data_index + 1; else if unit_map_quality >= 0 map_quality = [map_quality; unit_map_quality]; end end end end end end map = [map; unit_map]; %update k-d tree with new map map_kd_tree = kdtree_build(map(:,1:4)); 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,' '); % Display map quality mean_map_quality = mean(map_quality) std_map_quality = std(map_quality) end function [registration_flag, map_quality, map] = check_map_registration(map_kd_tree, map, point) registration_flag = true; dist_th = 0.3; % [m] gray_th = 255*0.01; % [gray level] map_quality = -1; if ~isempty(map_kd_tree) % find closest point using kd-tree temp_idx = kdtree_nearest_neighbor(map_kd_tree, point); closest_point = map(temp_idx,:); dist = norm(point(1:3) - closest_point(1:3)); gray_dist = abs(point(4) - closest_point(4)); % check distance less than threshold and determine the flag if dist < dist_th && gray_dist < gray_th registration_flag = false; map(temp_idx,1:4) = sum([point;closest_point(1:4)*closest_point(6)])/(closest_point(6)+1); map_quality = norm(map(temp_idx,1:3)-point(1:3)); map(temp_idx,5) = map_quality; map(temp_idx,6) = map(temp_idx,6) + 1; end end end
github
rising-turtle/slam_matlab-master
analyze_bundler_file.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/analyze_bundler_file.m
3,795
utf_8
d9454f3886b73ec5e3a3f2cb4db97ca5
% Analyze bundler file % % Author : Soonhac Hong ([email protected]) % Date : 2/13/13 function analyze_bundler_file() 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/exp1_bus_door_straight_150_Replace_pose_feature_426_48_ros_sba.out'; file_name = 'results/ros_sba/exp1_bus_door_straight_150_Replace_pose_feature_426_48_ros_sba_result.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/exp1_bus_door_straight_150_Replace_pose_feature_1614_101_ros_sba_result.out'; %file_name = 'data/ba/ros_sba/sample_bundler_file.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', 'on', 'k.-' ); hold on; %plot3(landmark_position(:,1),landmark_position(:,2),landmark_position(:,3),'m.'); axis equal; %% Anlayze landmark position landmark_distance = sqrt(sum(landmark_position.^2,2)); %% Analyze projection %cam = initialize_cam2(); cam = initialize_cam(); features_info=[]; u0 = cam.Cx; v0 = cam.Cy; %ros_sba_T = sr4k_p2T([0,0,0,pi/2,0,0]); % temp_t = camera_poses(1,1:3)'; % temp_R = e2R(camera_poses(1,4:6)'); % reference_T = [temp_R, temp_t; 0 0 0 1]; %reference_T = inv(ros_sba_T)*reference_T; for i=1:size(camera_poses,1) temp_t = camera_poses(i,1:3)'; temp_R = e2R(camera_poses(i,4:6)'); %temp_R = eye(3); % T = [temp_R, temp_t; 0 0 0 1]; % %T = bundler_T*T; % Convert Bundler frame to SBA frame. % temp_t = T(1:3,4); % temp_R = T(1:3,1:3); projection_idx = find(landmark_projection(:,1) == (i-1)); estimated_uv=[]; measured_uv=[]; for j=1:size(projection_idx,1)-1 measured_uv(j,:) = landmark_projection(projection_idx(j), end-1:end); measured_uv(j,:) = [measured_uv(j,1) + u0, -1 * measured_uv(j,2) + v0]; temp_p = landmark_position(landmark_projection(projection_idx(j), 2)+1,:)'; %temp_p = reference_T * [landmark_position(landmark_projection(projection_idx(j), 2)+1,:)'; 1]; % The reference frame of all landmark positions is the first camera coordinate !!!!! %temp_p = bundler_T * [landmark_position(landmark_projection(projection_idx(j), 2)+1,:)'; 1]; % The reference frame of all landmark positions is the first camera coordinate !!!!! estimated_uv(j,:) = hi_cartesian_test(temp_p(1:3), temp_t, temp_R, cam, features_info)'; %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(measured_uv(:,1),measured_uv(:,2),'ro'); legend('Estimated','Measured'); hold off; projection_error = sqrt(sum((estimated_uv - measured_uv(:,1:2)).^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 cam = initialize_cam2() nRows = 480; nCols = 640; k1= 0; %-0.85016; k2= 0; %0.56153; cam.Cx = 320; cam.Cy = 240; cam.fd = 430; cam.f = 430; cam.k1 = k1; cam.k2 = k2; cam.nRows = nRows; cam.nCols = nCols; cam.d = 4/nCols*0.001; cam.F = cam.f/cam.d; % cam.f = f; cam.dx = cam.d; %% dx and dy are actually slightly different dx =4/176 while dy = 3.17/144 cam.dy = cam.d; cam.K = sparse( [ cam.fd 0 cam.Cx; 0 cam.fd cam.Cy; 0 0 1] ); cam.model = 'two_distortion_parameters'; end
github
rising-turtle/slam_matlab-master
generate_feature_index.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/generate_feature_index.m
2,078
utf_8
a2d297a437866c5e4fc478c009089384
% Generate feature index through all data % % Author : Soonhac Hong ([email protected]) % Date : 3/1/13 function [feature_points] = generate_feature_index(feature_points) feature_index_list=[]; camera_index_list=[]; feature_index = 1; for i=1:size(feature_points,1) if feature_points(i,1) == 1 && feature_points(i,2) == 2 && feature_points(i,3) == 1 feature_index_list(i,1) = feature_index; feature_index = feature_index + 1; camera_index_list(i,1) = feature_points(i,3); elseif feature_points(i,1) == 1 && feature_points(i,2) == 2 && feature_points(i,3) == 2 feature_index_list(i,1) = feature_index_list(i-feature_index+1,1); camera_index_list(i,1) = feature_points(i,3); else [unit_feature_index, unit_camera_index]= find_similar_feature_index(feature_points(1:i,:), feature_index_list, camera_index_list); % if i==411 % disp('debug'); % end feature_index_list(i,1) = unit_feature_index; if unit_feature_index > feature_index feature_index = unit_feature_index; end camera_index_list(i,1) = unit_camera_index; end end feature_points = [feature_points, feature_index_list, camera_index_list]; end function [feature_index, camera_index] = find_similar_feature_index(feature_points, feature_index_list, camera_index_list) if feature_points(end,3) == 1 camera_index = feature_points(end,1); else camera_index = feature_points(end,2); end same_camera_index_list = find(camera_index_list == camera_index); % Find similarity by pixel index if feature points observed by same camera if ~isempty(same_camera_index_list) same_camera_index = find(feature_points(same_camera_index_list,7) == feature_points(end,7) & feature_points(same_camera_index_list,8) == feature_points(end,8)); if ~isempty(same_camera_index) feature_index = feature_index_list(same_camera_index(1),1); else feature_index = max(feature_index_list) + 1; end else feature_index = max(feature_index_list) + 1; end end
github
rising-turtle/slam_matlab-master
compensate_vro.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/compensate_vro.m
10,828
utf_8
75a630c580d4f470b446748ce1cce2d2
% Compensate the missing pose % Author : Soonhac Hong ([email protected]) % Date : 4/19/20 function [new_f_index, new_t_pose, new_o_pose, new_fpts_index, new_pose_std] = compensate_vro(f_index, t_pose, o_pose, fpts_index, pose_std, pose_std_flag, cmp_option) cur_index = f_index(1,1); new_index = 1; f_index_length = size(f_index,1); new_fpts_index = []; new_pose_std = []; if strcmp(cmp_option,'Replace') for i = 1:f_index_length missing_index = [0 0]; if f_index(i,1) == cur_index new_f_index(new_index,:) = f_index(i,:); new_t_pose(new_index,:) = t_pose(i,:); new_o_pose(new_index,:) = o_pose(i,:); if pose_std_flag == 1 new_pose_std(new_index,:) = pose_std(i,:); end elseif f_index(i,1) == cur_index + 1 cur_index = f_index(i,1); new_f_index(new_index,:) = f_index(i,:); new_t_pose(new_index,:) = t_pose(i,:); new_o_pose(new_index,:) = o_pose(i,:); if pose_std_flag == 1 new_pose_std(new_index,:) = pose_std(i,:); end else % missing constraints n_missing_index = f_index(i,1) - (cur_index + 1); missing_index = missing_index + [n_missing_index n_missing_index]; % t_pose_compensation = (t_pose(i,:) + t_pose(i-1,:))/2; % o_pose_compensation = (o_pose(i,:) + o_pose(i-1,:))/2; % for k=1:n_missing_index % new_f_index(new_index,:) = [cur_index+k, cur_index+k+1]; % new_t_pose(new_index,:) = t_pose_compensation; % new_o_pose(new_index,:) = o_pose_compensation; % new_index = new_index + 1 % end cur_index = f_index(i,1) - missing_index(1); new_f_index(new_index,:) = f_index(i,:) - missing_index; new_t_pose(new_index,:) = t_pose(i,:); new_o_pose(new_index,:) = o_pose(i,:); if pose_std_flag == 1 new_pose_std(new_index,:) = pose_std(i,:); end f_index(i:f_index_length,:) = f_index(i:f_index_length,:) - repmat(missing_index, f_index_length-i+1, 1); end new_index = new_index + 1; end % check successiveness of second pose index_diff = diff(new_f_index,1,1); for i=1:size(index_diff,1); if index_diff(i,2) ~= 1 && index_diff(i,1) == 0 new_f_index(i+1,2) = new_f_index(i,2) + 1; end end % check consecutive of neighbor pose index_diff = diff(new_f_index,1,1); % Comment out for loop closure for i=2:size(new_f_index,1); if abs(new_f_index(i,1)-new_f_index(i,2)) >= 2 && abs(new_f_index(i,1)-new_f_index(i-1,1)) ~= 0 new_f_index(i,2) = new_f_index(i,1) + 1; end end % Adjuste index of features if ~isempty(fpts_index) fpts_index_length = size(fpts_index,1); new_index = 1; cur_index = fpts_index(1,1); for i = 1:fpts_index_length if fpts_index(i,1) == cur_index new_fpts_index(new_index,:) = fpts_index(i,:); elseif fpts_index(i,1) == cur_index + 1 cur_index = fpts_index(i,1); new_fpts_index(new_index,:) = fpts_index(i,:); else % missing constraints n_missing_index = fpts_index(i,1) - (cur_index + 1); missing_index = [n_missing_index n_missing_index]; cur_index = fpts_index(i,1) - missing_index(1); new_fpts_index(new_index,:) = fpts_index(i,:) - missing_index; fpts_index(i:fpts_index_length,:) = fpts_index(i:fpts_index_length,:) - repmat(missing_index, fpts_index_length-i+1, 1); end new_index = new_index + 1; end % check successiveness of second pose index_diff = diff(new_fpts_index,1,1); for i=1:size(index_diff,1); if index_diff(i,2) > 1 && index_diff(i,1) == 0 update_index = find(new_fpts_index(:,1) == new_fpts_index(i+1,1) & new_fpts_index(:,2) == new_fpts_index(i+1,2)); new_fpts_index(update_index,2) = new_fpts_index(i,2) + 1; end end end elseif strcmp(cmp_option,'Linear') missing_index = 0; for i = 1:f_index_length if f_index(i,1) == cur_index new_f_index(new_index,:) = f_index(i,:); new_t_pose(new_index,:) = t_pose(i,:); new_o_pose(new_index,:) = o_pose(i,:); if pose_std_flag == 1 new_pose_std(new_index,:) = pose_std(i,:); end elseif f_index(i,1) == cur_index + 1 cur_index = f_index(i,1); new_f_index(new_index,:) = f_index(i,:); new_t_pose(new_index,:) = t_pose(i,:); new_o_pose(new_index,:) = o_pose(i,:); if pose_std_flag == 1 new_pose_std(new_index,:) = pose_std(i,:); end else % missing constraints n_missing_index = f_index(i,1) - (cur_index + 1); missing_index = missing_index + n_missing_index; t_pose_compensation = (t_pose(i,:) + t_pose(i-1,:))/2; o_pose_compensation = (o_pose(i,:) + o_pose(i-1,:))/2; if pose_std_flag == 1 pose_std_compensation = (pose_std(i,:) + pose_std(i-1,:))/2; end for k=1:n_missing_index new_f_index(new_index,:) = [cur_index+k, cur_index+k+1]; new_t_pose(new_index,:) = t_pose_compensation; new_o_pose(new_index,:) = o_pose_compensation; if pose_std_flag == 1 new_pose_std(new_index,:) = pose_std_compensation; end new_index = new_index + 1; end cur_index = f_index(i,1); new_f_index(new_index,:) = f_index(i,:); new_t_pose(new_index,:) = t_pose(i,:); new_o_pose(new_index,:) = o_pose(i,:); if pose_std_flag == 1 new_pose_std(new_index,:) = pose_std(i,:); end end new_index = new_index + 1; end % check successiveness of second pose tmp_new_f_index = new_f_index; tmp_new_t_pose = new_t_pose; tmp_new_o_pose = new_o_pose; tmp_new_pose_std = new_pose_std; new_f_index = []; new_t_pose = []; new_o_pose = []; new_pose_std = []; index_diff = diff(tmp_new_f_index,1,1); new_index = 1; for i=1:size(index_diff,1); new_f_index(new_index,:) = tmp_new_f_index(i,:); new_t_pose(new_index,:) = tmp_new_t_pose(i,:); new_o_pose(new_index,:) = tmp_new_o_pose(i,:); if pose_std_flag == 1 new_pose_std(new_index,:) = tmp_new_pose_std(i,:); end new_index = new_index + 1; if index_diff(i,2) ~= 1 && index_diff(i,1) == 0 %if (index_diff(i,2) - index_diff(i,1)) >= 1 t_pose_compensation = (tmp_new_t_pose(i,:) + tmp_new_t_pose(i-1,:))/2; o_pose_compensation = (tmp_new_o_pose(i,:) + tmp_new_o_pose(i-1,:))/2; if pose_std_flag == 1 pose_std_compensation = (tmp_new_pose_std(i,:) + tmp_new_pose_std(i-1,:))/2; end for k=1:index_diff(i,2)-1 new_f_index(new_index,:) = [tmp_new_f_index(i,1), tmp_new_f_index(i,2)+k]; new_t_pose(new_index,:) = t_pose_compensation; new_o_pose(new_index,:) = o_pose_compensation; if pose_std_flag == 1 new_pose_std(new_index,:) = pose_std_compensation; end new_index = new_index + 1; end end end new_f_index(new_index,:) = tmp_new_f_index(i+1,:); new_t_pose(new_index,:) = tmp_new_t_pose(i+1,:); new_o_pose(new_index,:) = tmp_new_o_pose(i+1,:); if pose_std_flag == 1 new_pose_std(new_index,:) = tmp_new_pose_std(i+1,:); end % check consecutive of neighbor pose tmp_new_f_index = new_f_index; tmp_new_t_pose = new_t_pose; tmp_new_o_pose = new_o_pose; if pose_std_flag == 1 tmp_new_pose_std = new_pose_std; end new_f_index = tmp_new_f_index(1,:); new_t_pose = tmp_new_t_pose(1,:); new_o_pose = tmp_new_o_pose(1,:); if pose_std_flag == 1 new_pose_std = tmp_new_pose_std(1,:); end new_index = 2; for i=2:size(tmp_new_f_index,1); if abs(tmp_new_f_index(i,1) - tmp_new_f_index(i,2)) >= 2 && abs(tmp_new_f_index(i,1) - tmp_new_f_index(i-1,1)) ~= 0 %new_f_index(i,2) = new_f_index(i,1) + 1; t_pose_compensation = (tmp_new_t_pose(i,:) + tmp_new_t_pose(i-1,:))/2; o_pose_compensation = (tmp_new_o_pose(i,:) + tmp_new_o_pose(i-1,:))/2; if pose_std_flag == 1 pose_std_compensation = (tmp_new_pose_std(i,:) + tmp_new_pose_std(i-1,:))/2; end interval = abs(tmp_new_f_index(i,1)-tmp_new_f_index(i,2)) - 1; for k=1:interval new_f_index(new_index,:) = [tmp_new_f_index(i,1), tmp_new_f_index(i,1)+k]; new_t_pose(new_index,:) = t_pose_compensation; new_o_pose(new_index,:) = o_pose_compensation; if pose_std_flag == 1 new_pose_std(new_index,:) = pose_std_compensation; end new_index = new_index + 1; end end new_f_index(new_index,:) = tmp_new_f_index(i,:); new_t_pose(new_index,:) = tmp_new_t_pose(i,:); new_o_pose(new_index,:) = tmp_new_o_pose(i,:); if pose_std_flag == 1 new_pose_std(new_index,:) = tmp_new_pose_std(i,:); end new_index = new_index + 1; end end % Reduce the constraints % tmp_new_f_index = new_f_index; % tmp_new_t_pose = new_t_pose; % tmp_new_o_pose = new_o_pose; % new_f_index = tmp_new_f_index(1,:); % new_t_pose = tmp_new_t_pose(1,:); % new_o_pose = tmp_new_o_pose(1,:); % new_index = 2; % % min_edge = 1; % unit_edge_cnt = 1; % % for i=2:size(tmp_new_f_index,1) % if tmp_new_f_index(i,1) ~= tmp_new_f_index(i-1,1) % new_f_index(new_index,:) = tmp_new_f_index(i,:); % new_t_pose(new_index,:) = tmp_new_t_pose(i,:); % new_o_pose(new_index,:) = tmp_new_o_pose(i,:); % new_index = new_index + 1; % unit_edge_cnt = 1; % elseif unit_edge_cnt < min_edge % new_f_index(new_index,:) = tmp_new_f_index(i,:); % new_t_pose(new_index,:) = tmp_new_t_pose(i,:); % new_o_pose(new_index,:) = tmp_new_o_pose(i,:); % new_index = new_index + 1; % unit_edge_cnt = unit_edge_cnt + 1; % end % end end
github
rising-turtle/slam_matlab-master
run_pose_graph_optimization_v2.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/run_pose_graph_optimization_v2.m
1,322
utf_8
d28a8104e89fa69ed5a18db6501d5382
% Run pose graph optimization % % Author : Soonhac Hong ([email protected]) % History : % 3/26/14 : Created function [result, graph, initial, h_global, location_file_index, location_info_history]=run_pose_graph_optimization_v2(vro_result, vro_pose_std, graph, initial, h_global, dis, location_flag, location_file_index, location_info_history, lcd_found) import gtsam.* t = gtsam.Point3(0, 0, 0); if isempty(h_global) h_global = get_global_transformation_single('smart_cane'); rot = h_global(1:3,1:3); R = gtsam.Rot3(rot); origin= gtsam.Pose3(R,t); initial.insert(0,origin); end pgc_t=tic; [graph,initial] = construct_pose_graph(vro_result, vro_pose_std, graph, initial); first = initial.at(0); pgc_ct =toc(pgc_t) graph.add(NonlinearEqualityPose3(0, first)); gtsam_t=tic; optimizer = LevenbergMarquardtOptimizer(graph, initial); result = optimizer.optimizeSafely(); gtsam_ct =toc(gtsam_t) % Show the results in the plot and generate location information if dis==true [location_file_index, location_info_history]=plot_graph_initial_result_v2(initial, result, location_flag, location_file_index, location_info_history, lcd_found); elseif location_flag == true && lcd_found == true [location_info, location_file_index] = generate_location_info_v2(result,[], location_file_index); end end
github
rising-turtle/slam_matlab-master
convert_o2p_adaptive.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/convert_o2p_adaptive.m
5,408
utf_8
0c1a9b2d0a86628ce2495a472c1f80ae
% Conver the odometery to the global pose % t_pose [mm] % o_pose [degree] function [pose_index, e_t_pose e_o_pose fpts_h] = convert_o2p_adaptive(data_index, dynamic_index, f_index, t_pose, o_pose, feature_points, dense_index, sparse_interval) % 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) relative_max_index = max(find(f_index(:,1) == f_index(i,1))) if f_index(i,1) > previous_index && (i == relative_max_index || check_orientation(o_pose(i,:)) == 1) %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; 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)]; end end % Eliminate duplicated points 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); for i = 1:size(vro_t_pose,1) 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]; 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; [e_o_pose(k,1) e_o_pose(k,2) e_o_pose(k,3)] = rot_to_euler(temp_h(1:3,1:3)); 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 else fpts_h={}; end temp_h = h_global; [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 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,:)); 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 [orientation_dominant] = check_orientation(unit_o_pose) o_threshold = 3.0 ; %0.24; %[degree] idx = find(abs(unit_o_pose) > o_threshold); if isempty(idx) orientation_dominant = 0 else orientation_dominant = 1 end end
github
rising-turtle/slam_matlab-master
kinect_relative_pose_gt.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/kinect_relative_pose_gt.m
2,205
utf_8
99fd8e96694f4792837b8a2ac1a0d976
% Compute relative pose b/w two images from ground truth in kinect_tum % % Author : Soonhac Hong ([email protected]) % Date : 12/20/12 function kinect_relative_pose_gt(dir_index, depth_file_index_1, depth_file_index_2) format LONGG; 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'); % Get time stamp of color files fisrt_depth_file_time_stamps = get_timestamp_kinect_tum(dir_index,depth_file_index_1) second_depth_file_time_stamps = get_timestamp_kinect_tum(dir_index,depth_file_index_2) % Load ground truth [gt rgbdslam rtime] = Load_kinect_gt(dir_index); % Find first time stamp %first_timestamp = get_timestamp_kinect_tum(dir_index,file_index_1); gt_first_index = find(gt(:,1) > fisrt_depth_file_time_stamps, 1); if gt(gt_first_index,1) - fisrt_depth_file_time_stamps > fisrt_depth_file_time_stamps - gt(gt_first_index-1,1) gt_first_index = gt_first_index - 1; end % Find second time stamp %second_timestamp = get_timestamp_kinect_tum(dir_index,file_index_2); gt_second_index = find(gt(:,1) > second_depth_file_time_stamps, 1); if gt(gt_second_index,1) - second_depth_file_time_stamps > second_depth_file_time_stamps - gt(gt_second_index-1,1) gt_second_index = gt_second_index - 1; end gt_first_tf =[q2R([gt(gt_first_index,5:8)]) [gt(gt_first_index,2:4)]'; 0 0 0 1]; gt_second_tf =[q2R([gt(gt_second_index,5:8)]) [gt(gt_second_index,2:4)]'; 0 0 0 1]; rgbdslam_first_tf =[q2R([rgbdslam(gt_first_index,5:8)]) [rgbdslam(gt_first_index,2:4)]'; 0 0 0 1]; rgbdslam_second_tf =[q2R([rgbdslam(gt_second_index,5:8)]) [rgbdslam(gt_second_index,2:4)]'; 0 0 0 1]; gt_relative_tf = inv(gt_first_tf) * gt_second_tf; gt_translation = [gt_relative_tf(1,4) gt_relative_tf(2,4) gt_relative_tf(3,4)]; gt_euler = R2e(gt_relative_tf(1:3,1:3)); rgbdslam_relative_tf = inv(rgbdslam_first_tf) * rgbdslam_second_tf; rgbdslam_translation = [rgbdslam_relative_tf(1,4) rgbdslam_relative_tf(2,4) rgbdslam_relative_tf(3,4)]; rgbdslam_euler = R2e(rgbdslam_relative_tf(1:3,1:3)); figure; plot(gt_translation,'g*'); hold on; plot(rgbdslam_translation,'rd'); hold off; end
github
rising-turtle/slam_matlab-master
plot3_gtsam.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot3_gtsam.m
1,456
utf_8
5e536d0602db5d998c7d610d2e8c0e25
% This file was modified from gtsam/toolbox/+gtsam/plot3DTreajectory.m function plot3_gtsam(values,linespec,frames,scale,marginals) % plot3DTrajectory plots a 3D trajectory % plot3DTrajectory(values,linespec,frames,scale,marginals) if ~exist('scale','var') || isempty(scale), scale=1; end if ~exist('frames','var'), scale=[]; end import gtsam.* haveMarginals = exist('marginals', 'var'); keys = KeyVector(values.keys); holdstate = ishold; hold on % Plot poses and covariance matrices lastIndex = []; for i = 0:keys.size-1 key = keys.at(i); x = values.at(key); if isa(x, 'gtsam.Pose3') if ~isempty(lastIndex) % Draw line from last pose then covariance ellipse on top of % last pose. lastKey = keys.at(lastIndex); lastPose = values.at(lastKey); plot3([ x.x; lastPose.x ], [ x.y; lastPose.y ], [ x.z; lastPose.z ], linespec); if haveMarginals P = marginals.marginalCovariance(lastKey); else P = []; end %gtsam.plotPose3(lastPose, P, scale); end lastIndex = i; end end % Draw final pose if ~isempty(lastIndex) lastKey = keys.at(lastIndex); lastPose = values.at(lastKey); if haveMarginals P = marginals.marginalCovariance(lastKey); else P = []; end %gtsam.plotPose3(lastPose, P, scale); end if ~holdstate hold off end grid; end
github
rising-turtle/slam_matlab-master
construct_pose_graph.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/construct_pose_graph.m
2,474
utf_8
1d5fc7f3f5bebe8be1aa17d55d8bca3a
% Construct a pose graph for Graph SLAM % % Author : Soonhac Hong ([email protected]) % History : % 3/26/14 : Created function [graph,initial] = construct_pose_graph(vro_result, vro_pose_std, graph, initial) import gtsam.* n=size(vro_result,1); N=n; pose_size=max(vro_result(:,2)); first_index_offset = 1; step_threshold = 2; sigma_level = 1; node_count=0; edge_count=0; for i=1:n e=vro_result(i,:); i1=e(1)-first_index_offset; i2=e(2)-first_index_offset; t = gtsam.Point3(e(6), e(7), e(8)); R = gtsam.Rot3.Ypr(e(5), e(3), e(4)); dpose = gtsam.Pose3(R,t); pose_std = vro_pose_std(i,3:end)'; %[ry rx rz tx ty tz] pose_std =[pose_std(4:6); pose_std(2); pose_std(1); pose_std(3)]; if (abs(i2-i1)==1) || check_reliability_static7(pose_std, sigma_level) == 1 pose_noise_model = noiseModel.Diagonal.Sigmas(pose_std); graph.add(BetweenFactorPose3(i1, i2, dpose, pose_noise_model)); edge_count = edge_count + 1; if abs(i2-i1)==1 if i2>i1 initial.insert(i2,initial.at(i1).compose(dpose)); else initial.insert(i1,initial.at(i2).compose(dpose.inverse)); end end 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
github
rising-turtle/slam_matlab-master
plot_graph_initial_result.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot_graph_initial_result.m
2,568
utf_8
48f6abd5162643f1f8d96e7f6012a8ec
% 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(gtsam_pose_initial, gtsam_pose_result, location_flag, location_file_index, location_info_history) import gtsam.* keys = KeyVector(gtsam_pose_initial.keys); 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 [location_info, location_file_index] = generate_location_info([], plot_xyz_result, location_file_index); % for finding rooms 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); text(plot_xyz_result(1,1)-1.5,plot_xyz_result(1,2)-1.5,'Start','Color',[0 0 0]); xlabel('X');ylabel('Y'); % Modify size of x in the graph %xlim([-7 15]); % for etas523_exp2 %xlim([-15 5]); % for Amir's exp1 xlim([-10 10]); % for etas523_exp2_lefthallway ylim([-5 15]); % Display location information text_offset=[1,0; -6.5,0; -1,2; -1,-1.5; 0,-1.5]; % etas etas 523 exp2 %text_offset=[-6,0; 1,0; 1,0; 1,0; 0,2]; % etas etas 523 lefthallway 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
pose_optimization_example_2d.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/pose_optimization_example_2d.m
4,277
utf_8
75b4771c3e2e5f8defec05bbcc23317e
% 2D Example of Pose Graph Optimization % Data : 4/12/12 % Author : Soonhac Hong ([email protected]) function pose_optimization_example_2d() % 2D case pose_data=[1 1 0 0 0; 1 2 2 0 0 ; 2 3 2 0 pi/2; 3 4 2 0 pi/2; 4 5 2 0 pi/2 ; 5 2 2 0 pi/2]; % [first pose, second pose, constraint[x,y,theta]] xinit = [0.5; 0.0; 0.2; 2.3; 0.1; -0.2; 4.1; 0.1; pi/2; 4.0; 2.0; pi; 2.1; 2.1; -pi/2] motion_noise = [0.3;0.3;0.1]; variable_size = (size(pose_data,2)-2); % size of each variable [x, y, r] pose_num = size(unique(pose_data(:,1:2)),1)*variable_size; % first position is not optimized. Omega = zeros(pose_num,pose_num); Xi = zeros(pose_num,1); Odometry=zeros(pose_num,1); %Odometry = zeros(pose_num,1); % Fill the elements of Omega and Xi % Initial point for i=1:variable_size Omega(i,i) = 1; Xi(i) = pose_data(1,i+2); Odometry(i) = pose_data(1,i+2); end for i=2:size(pose_data,1) unit_data = pose_data(i,:); current_index = unit_data(1); next_index = unit_data(2); movement = unit_data(3:2+variable_size); previous_theta = pose_data(i-1,2+variable_size); % Adjust index according to the size of each variable if current_index ~= 1 current_index = (current_index - 1) * variable_size + 1; end if next_index ~= -1 next_index = (next_index - 1) * variable_size + 1; end for j=0:variable_size-1 % Fill diagonal elements of Omega switch j case 0 diagonal_factor = cos(movement(3)); offdiagonal_factor = 1; case 1 diagonal_factor = cos(movement(3)); offdiagonal_factor = -1; case 2 diagonal_factor = 1; offdiagonal_factor = -1; end Omega(current_index+j,current_index+j) = Omega(current_index+j,current_index+j) + diagonal_factor*motion_noise(j+1); Omega(next_index+j,next_index+j) = Omega(next_index+j,next_index+j) + 1/motion_noise(j+1); % Fill Off-diagonal elements of Omega Omega(current_index+j,next_index+j) = Omega(current_index+j,next_index+j) + (-1)/motion_noise(j+1); Omega(next_index+j,current_index+j) = Omega(next_index+j,current_index+j) + (-1)*diagonal_factor/motion_noise(j+1); if j <= 1 Omega(current_index+j,current_index+j+offdiagonal_factor) = Omega(current_index+j,next_index+j+offdiagonal_factor) + (-1)*offdiagonal_factor*sin(movement(3))/motion_noise(j+1); Omega(next_index+j,current_index+j+offdiagonal_factor) = Omega(next_index+j,current_index+j+offdiagonal_factor) + offdiagonal_factor*sin(movement(3))/motion_noise(j+1); end % Fill Xi Xi(current_index+j) = Xi(current_index+j) + (-1)*movement(j+1)/motion_noise(j+1); Xi(next_index+j) = Xi(next_index+j) + movement(j+1)/motion_noise(j+1); end % Update Odometry if abs(current_index - next_index) == 3 translation=[0 0 1]'; for t=i:-1:2 unit_movement=pose_data(t,3:5); translation = [cos(unit_movement(3)) -sin(unit_movement(3)) unit_movement(1); sin(unit_movement(3)) cos(unit_movement(3)) unit_movement(2); 0 0 1]*translation; end %translation = Odometry(current_index:current_index+1) + movement(1:2)'; Odometry(next_index:next_index+1) = translation(1:2); orientation = Odometry(current_index+2) + movement(3); if orientation > pi*2 orientation = orientation - pi*2; end Odometry(next_index+2) = orientation; end end %Omega %Xi %mu = Omega^-1 * Xi % Using LM xdata = Omega; ydata = Xi; %myfun = @(x,xdata)Rot(x(1:3))*xdata+repmat(x(4:6),1,length(xdata)); myfun = @(x,xdata)xdata*x(1:size(xdata,1)); options = optimset('Algorithm', 'levenberg-marquardt'); %x = lsqcurvefit(myfun, zeros(6,1), p, q, [], [], options); x = lsqcurvefit(myfun, xinit, xdata, ydata, [], [], options) x_mat = vec2mat(x,3); Odometry_mat = vec2mat(Odometry,3); xinit_mat = vec2mat(xinit,3); plot(xinit_mat(:,1), xinit_mat(:,2) ,'bd-'); hold on; plot(Odometry_mat(:,1), Odometry_mat(:,2) ,'gd-'); plot(x_mat(:,1), x_mat(:,2) ,'ro-'); hold off; legend('Initial','Odometry','Optimized'); %legend('Initial','Optimized'); end
github
rising-turtle/slam_matlab-master
plot_g2o.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot_g2o.m
3,805
utf_8
7e0fcebfeb6496b1ba99eb889d50d7af
% Plot the result of graph SLAM, g2o % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function plot_g2o(org_file_name, opt_file_name, feature_flag) [ org_poses org_edges org_fpts_poses org_fpts_edges] = load_graph_g2o(org_file_name); [ opt_poses opt_edges opt_fpts_poses opt_fpts_edges] = load_graph_g2o(opt_file_name); % Show the pose start_index = 1; end_index = min(size(org_poses,1), size(opt_poses)); %80; if size(org_poses,2) == 3 % SE2 figure; %plot(org_poses(start_index:end_index,1), org_poses(start_index:end_index,2),'b.-','LineWidth',2); plot(org_poses(:,1), org_poses(:,2),'b.-','LineWidth',2); if ~isempty(org_fpts_poses) && feature_flag == 1 hold on; plot(org_fpts_poses(:,1), org_fpts_poses(:,2), 'bd'); end %xlabel('X [m]'); %ylabel('Y [m]'); %grid; %figure; hold on; %plot(opt_poses(start_index:end_index,1), opt_poses(start_index:end_index,2),'r.-','LineWidth',2); plot(opt_poses(:,1), opt_poses(:,2),'r.-','LineWidth',2); if ~isempty(opt_fpts_poses) && feature_flag == 1 plot(opt_fpts_poses(:,1), opt_fpts_poses(:,2), 'rd'); end %plot_groundtruth(); xlabel('X [m]'); ylabel('Y [m]'); grid; %legend('vro','vro fpts', 'g2o', 'g2o fpts','eGT'); legend('vro','g2o'); %legend('vro','g2o'); %xlim([-0.1 0.2]); %ylim([-0.1 0.4]); axis equal; hold off; elseif size(org_poses,2) == 7 % SE3:QUAT figure; plot3(org_poses(start_index:end_index,1), org_poses(start_index:end_index,2), org_poses(start_index:end_index,3), 'b-'); %xlabel('X [m]'); %ylabel('Y [m]'); %zlabel('Z [m]'); %grid; %figure; hold on; plot3(opt_poses(start_index:end_index,1), opt_poses(start_index:end_index,2), opt_poses(start_index:end_index,3), 'r-'); xlabel('X [m]'); ylabel('Y [m]'); zlabel('Z [m]'); grid; axis equal; hold off; end end function plot_groundtruth() gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; gt_x = gt_x / 1000; % [mm] -> [m] gt_y = gt_y / 1000; % [mm] -> [m] plot(gt_x,gt_y,'g-','LineWidth',2); end % function [poses edges] = load_graph(file_name) % fid = fopen(file_name); % data = textscan(fid, '%s %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 %f %f %f'); % 2D format % fclose(fid); % % % Convert data % % Pose % data_name = data{1}; % data_name_list = {'VERTEX_SE2','EDGE_SE2','VERTEX_SE3:QUAT','EDGE_SE3:QUAT'}; % vertex_index = 1; % edge_index = 1; % for i = 1 : size(data_name,1) % if strcmp(data_name{i}, data_name_list{1}) % VERTEX_SE2 % unit_data =[]; % for j=3:5 % unit_data = [unit_data data{j}(i)]; % end % poses(vertex_index,:) = unit_data; % vertex_index = vertex_index + 1; % elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % unit_data =[]; % for j=2:12 % unit_data = [unit_data data{j}(i)]; % end % edges(edge_index,:) = unit_data; % edge_index = edge_index + 1; % elseif strcmp(data_name{i}, data_name_list{3}) % VERTEX_SE3:QUAT % unit_data =[]; % for j=3:9 % unit_data = [unit_data data{j}(i)]; % end % poses(vertex_index,:) = unit_data; % vertex_index = vertex_index + 1; % elseif strcmp(data_name{i}, data_name_list{4}) % EDGE_SE3:QUAT % unit_data =[]; % for j=2:31 % unit_data = [unit_data data{j}(i)]; % end % edges(edge_index,:) = unit_data; % edge_index = edge_index + 1; % end % % end % end
github
rising-turtle/slam_matlab-master
generate_location_info_v2.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/generate_location_info_v2.m
1,803
utf_8
636d5ba368cd57e0ff5b309c1a1ab788
% Generate the location infomation for Text-To-Speech and plots % % Author : Soonhac Hong ([email protected]) % History : % 8/27/14 : Created % function [location_info, location_file_index] = generate_location_info_v2(gtsam_pose_result, plot_xyz_result, location_file_index) import gtsam.* location_info=[]; % Extract the optimized pose from gtsam data structure if the optimized pose is not available if isempty(plot_xyz_result) keys = KeyVector(gtsam_pose_result.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_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 end if size(plot_xyz_result,1) < 50 % Avoid adjacency of first n steps with respect to the starting point return; end %% Generate the location information location_info_list={'You return to the starting point;'}; short_location_info_list={'Start'}; location_info_xy=[0, 0]; % unit : [m] location_threshold = 0.4; % [m] location_info_file_name = sprintf('C:\\SC-DATA-TRANSFER\\location_info_%d.txt', location_file_index); current_position = [plot_xyz_result(end,1),plot_xyz_result(end,2),plot_xyz_result(end,3)]; % [x, y, z] for i=location_file_index:size(location_info_xy,1) distance = norm(current_position(1, 1:2) - location_info_xy(i,:)); if distance < location_threshold location_info = short_location_info_list{i}; % Write the location information to the location_info.txt fd = fopen(location_info_file_name, 'w'); fprintf(fd,'%s',location_info_list{i}); fclose(fd); location_file_index = location_file_index + 1; break; end end end
github
rising-turtle/slam_matlab-master
convert_isp2ply.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/convert_isp2ply.m
1,477
utf_8
156009055f11b3be476e3513612330c7
% Conver isp to ply for meshlab % % Author : Soonhac Hong ([email protected]) % Date : 4/1/13 function convert_isp2ply(isp_file_name, file_index, dynamic_index, isgframe, vro_name) [poses] = load_graph_isp(isp_file_name); isp_finder = strfind(isp_file_name,'isp'); if(isempty(isp_finder)) ply_file_name=strrep(isp_file_name, 'opt','ply') if strcmp(vro_name, 'vro') == 1 color=[255, 0, 0]; % red else color=[0, 0, 255]; % blue end is_opt_file = 1; else ply_file_name=strrep(isp_file_name, 'isp','ply') color=[0, 255, 0]; % green is_opt_file = 0; end fd = fopen(ply_file_name, 'w'); % Write header element_vertex_n = sprintf('element vertex %d',size(poses,1)); ply_headers={'ply','format ascii 1.0','comment Created with XYZRGB_to_PLY', element_vertex_n, 'property float x', 'property float y','property float z','property uchar red','property uchar green','property uchar blue','end_header'}; for i=1:size(ply_headers,2) fprintf(fd,'%s\n',ply_headers{i}); end % Write data for j=1:size(poses,1) fprintf(fd,'%f %f %f %d %d %d\n',poses(j,1:3), color); end fclose(fd) if(is_opt_file == 1) convert_pc2ply(ply_headers, ply_file_name, poses, file_index, dynamic_index, isgframe); %convert_pc2ply_map_registration(ply_headers, ply_file_name, poses, file_index, dynamic_index, isgframe); %convert_pc2ply_map_registration_v2(ply_headers, ply_file_name, poses, file_index, dynamic_index, isgframe); end end
github
rising-turtle/slam_matlab-master
gslam_plot_comparison.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/gslam_plot_comparison.m
10,628
utf_8
ab0569c4aae179bf191b516d557a3428
% plot comparison of g2o and isam function gslam_plot_comparison() % file_index = 5; % 5 = whitecane % dynamic_index = 16; file_index = 9; % 5 = whitecane 6 = etas dynamic_index = 1; % 15:square_500, 16:square_700, 17:square_swing etas_nFrame_list = [979 1479 979 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]; compensation_option ={'Replace','Linear'}; feature_flag = 0; etas_vro_size_list = [1260 0 1665 0 9490 0]; %1974 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]; vro_name_list={'vro','vro_icp','vro_icp_ch','icp'}; vro_name_index = 3; vro_name=vro_name_list{vro_name_index}; loops2_nFrame_list = [582 398 398 832]; %2498 578 loops2_vro_size_list = [2891 0 0 5754]; %4145 loops2_pose_size_list = [582 0 0 832]; 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 = 1260; %etas_vro_size_list(dynamic_index); %1951; 1942; %5382; %46; %5365; %5169; 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); end if feature_flag == 1 feature_pose_name = 'pose_feature'; else feature_pose_name = 'pose_zero'; end [g2o_result_dir_name, isam_result_dir_name, vro_dir_name, dynamic_dir_name, toro_dir_name] = get_file_names(file_index, dynamic_index); % switch dynamic_index % case 15 % vro_size = 3616; % case 16 % vro_size = 5169; % case 11 % vro_size = 84; % end %vro_file_name = sprintf('%s%s_%s_%s_%d.g2o', vro_dir_name, dynamic_dir_name, compensation_option{2}, feature_pose_name, vro_size); %g2o_result_file_name = sprintf('%s%s_%d.opt', g2o_result_dir_name, dynamic_dir_name, vro_size); %isam_result_file_name = sprintf('%s%s_%s_%s_zero_%d_isam.opt', isam_result_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, vro_size); %isp_file_name = sprintf('%s%s_%s_%s_zero_%d.isp', vro_dir_name, dynamic_dir_name, compensation_option{2}, feature_pose_name, 1974); %isp_file_name_plus1 = sprintf('%s%s_%s_%s_zero_%d_329.isp', vro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, vro_size); %isp_file_name_plus2 = sprintf('%s%s_%s_%s_zero_%d_610.isp', vro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, vro_size); %isp_file_name_plus3 = sprintf('%s%s_%s_%s_zero_%d_325.isp', vro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, vro_size); %isp_file_name_plus1_minlength = sprintf('%s%s_%s_%s_zero_%d.isp', vro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, 118); %isp_file_name_plus1_minlength2 = sprintf('%s%s_%s_%s_zero_%d.isp', vro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, 108); gtsam_isp_file_name_icp = sprintf('%s%s_%s_%s_%d_%s_gtsam.isp', vro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, 2873, vro_name_list{2}); %5763 gtsam_isp_file_name_icp_ch = sprintf('%s%s_%s_%s_%d_%s_gtsam.isp', vro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, vro_size, vro_name_list{3}); icp_ct_file_name = sprintf('%s%s_%s_%s_%d_%d_%s_icp.ct', vro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, 2873, pose_size, vro_name_list{2}); %5763 icp_ct_file_name_ch = sprintf('%s%s_%s_%s_%d_%d_%s_icp.ct', vro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, vro_size, pose_size, vro_name_list{3}); %gtsam_result_file_name = sprintf('%s%s_%s_%s_zero_%d_gtsam.opt', isam_result_dir_name, dynamic_dir_name, compensation_option{2}, feature_pose_name, vro_size); %isp_file_name2 = sprintf('%s%s_%s_%s_%d.isp', vro_dir_name, dynamic_dir_name, compensation_option{2}, feature_pose_name, vro_size); %isam_result2_file_name = sprintf('%s%s_%s_%s_%d_isam.opt', isam_result_dir_name, dynamic_dir_name, compensation_option{2}, feature_pose_name, vro_size); %isp2_file_name = sprintf('%s%s_%s_%s_%d.isp', vro_dir_name, dynamic_dir_name, compensation_option{2}, feature_pose_name, vro_size); %toro_result_file_name = sprintf('%s%s_%s_%s_%d-treeopt-final.graph', toro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, vro_size); %toro_vro_file_name = sprintf('%s%s_%s_%s_%d.graph', toro_dir_name, dynamic_dir_name, compensation_option{1}, feature_pose_name, vro_size); %toro_result2_file_name = sprintf('%s%s_%s_%s_%d-treeopt-final.graph', toro_dir_name, dynamic_dir_name, compensation_option{2}, feature_pose_name, vro_size); %isp_file_name3 = sprintf('%s%s_%s_%s_zero_%d.isp', vro_dir_name, dynamic_dir_name, compensation_option{2}, feature_pose_name, vro_size); %isam_result3_file_name = sprintf('%s%s_%s_%s_zero_%d_isam.opt', isam_result_dir_name, dynamic_dir_name, compensation_option{2}, feature_pose_name, vro_size); %[vro_poses vro_edges] = load_graph_g2o(vro_file_name); %[g2o_poses g2o_edges] = load_graph_g2o(g2o_result_file_name); [vro_poses] = load_graph_isp(gtsam_isp_file_name_icp); [vro_poses2] = load_graph_isp(gtsam_isp_file_name_icp_ch); [vro_ct] = load(icp_ct_file_name); [vro_ct_ch] = load(icp_ct_file_name_ch); [ct_mean, ct_median, ct_std] = compute_ct_statistics(vro_ct); [ct_mean_ch, ct_median_ch, ct_std_ch] = compute_ct_statistics(vro_ct_ch); figure; %errorbar(ct_mean, ct_std,'k','LineWidth',2); %,'k*-' plot(ct_median,'gd-','LineWidth',2); hold on; %errorbar(ct_mean_ch, ct_std_ch,'g','LineWidth',2); plot(ct_median_ch,'k*-','LineWidth',2); legend('ICP','Fast ICP'); x_interval=1:5; set(gca,'XTick',x_interval,'FontSize',12,'FontWeight','bold'); h_xlabel = get(gca,'XLabel'); set(h_xlabel,'FontSize',12,'FontWeight','bold'); h_ylabel = get(gca,'YLabel'); set(h_ylabel,'FontSize',12,'FontWeight','bold'); xlabel('Step'); ylabel('Computational Time [sec]'); ylim([2.5 6]); grid; hold off; %[vro_poses] = load_graph_isp(isp_file_name); %[vro_poses2] = load_graph_isp(isp_file_name_plus1); %[vro_poses] = load_graph_isp(isp_file_name_plus2); %[vro_poses3] = load_graph_isp(isp_file_name_plus3); %[vro_poses3] = load_graph_isp(isp_file_name_plus1_minlength); %[vro_poses4] = load_graph_isp(isp_file_name_plus1_minlength2); %[vro_poses2] = load_graph_isp(isp_file_name2); %[gtsam_poses] = load_graph_isp(gtsam_result_file_name); %[isam_poses2] = load_graph_isam(isam_result2_file_name); %[toro_poses toro_edges toro_fpts_poses toro_fpts_edges] = load_graph_toro(toro_result_file_name); %[toro_poses2 toro_edges2 toro_fpts_poses2 toro_fpts_edges2] = load_graph_toro(toro_result2_file_name); %[vro_poses3] = load_graph_isp(isp_file_name3); %[isam_poses3] = load_graph_isam(isam_result3_file_name); %isam_poses(133:size(isam_poses,1),:) = isam_poses(133:size(isam_poses,1),:) + repmat(isam_poses(132,:), size(isam_poses,1)-132, 1); %gt_name = sprintf('../data/dynamic/%s/d1_gt.dat',dynamic_dir_name); %gt = {load(gt_name)}; %gt_x = cumsum(diff(gt{1,1}(6:20,1)))/1000; start_index = 1; %end_index = min([size(vro_poses,1) size(toro_poses,1) size(isam_poses,1)]); %80; end_index = min([size(vro_poses,1) size(vro_poses2,1)]); %80; if size(vro_poses,2) >= 3 % SE3 figure; %plot3(vro_poses(start_index:end_index,1), vro_poses(start_index:end_index,2), vro_poses(start_index:end_index,3),'b-','LineWidth',2); %plot3(vro_poses(:,1), vro_poses(:,2), vro_poses(:,3),'b-','LineWidth',2); plot(vro_poses(:,1), vro_poses(:,2), 'g-','LineWidth',2); hold on; %plot3(vro_poses2(start_index:end_index,1), vro_poses2(start_index:end_index,2), vro_poses2(start_index:end_index,3), 'm-','LineWidth',2); %plot3(vro_poses3(:,1), vro_poses3(:,2), vro_poses3(:,3), 'g-','LineWidth',2); plot(vro_poses2(:,1), vro_poses2(:,2), 'k-','LineWidth',2); %plot3(vro_poses2(:,1), vro_poses2(:,2), vro_poses2(:,3), 'm-','LineWidth',2); %plot3(vro_poses3(1:98,1), vro_poses3(1:98,2), vro_poses3(1:98,3), 'r-','LineWidth',2); %plot3(vro_poses4(1:98,1), vro_poses4(1:98,2), vro_poses4(1:98,3), 'g-','LineWidth',2); %hold on; %plot(vro_poses3(:,1), vro_poses3(:,2),'k-','LineWidth',2); %plot(vro_poses(start_index:end_index,1), 'b*-','LineWidth',2); %xlabel('X [m]'); %ylabel('Y [m]'); %grid;[e_t_pose e_o_pose] = convert_o2p(f_index, t_pose, o_pose) %figure; %hold on; %plot3(toro_poses(:,1), toro_poses(:,2), toro_poses(:,3),'g-','LineWidth',2); %plot(toro_poses2(:,1), toro_poses2(:,2),'r-','LineWidth',2); %plot3(isam_poses(:,1), isam_poses(:,2), isam_poses(:,3),'m-','LineWidth',2); %plot3(gtsam_poses(:,1), gtsam_poses(:,2), gtsam_poses(:,3),'b-','LineWidth',2); %plot(isam_poses2(:,1), isam_poses2(:,2),'c-','LineWidth',2); %plot(isam_poses3(:,1), isam_poses3(:,2),'m-','LineWidth',2); %plot(g2o_poses(start_index:end_index,1), 'ro-','LineWidth',2); %plot(isam_poses(start_index:end_index,1), 'md-','LineWidth',2); %plot(gt_x, 'g+-','LineWidth',2); %plot_groundtruth(); %plot_gt_etas(); xlabel('X [m]'); ylabel('Y [m]'); zlabel('Z [m]'); grid; legend('ICP','Fast ICP'); %,'iSAM_R','GT_e'); %legend('VRO_R','VRO_L','GT_e'); %legend('vro','Toro_R','Toro_L','isam_R','isam_L','gt_e'); %legend('VRO Dense','VRO Sparse','VRO Adaptive'); %,'iSAM_R','GT_e'); %legend('VRO','TORO_R','TORO_L','GT_e'); %legend('VRO','iSAM_R','iSAM_L','GT_e'); %legend('VRO_L','TORO_L','iSAM_L','GT_e'); %legend('VRO_L','VRO_Zeor','TORO_L','iSAM_L','iSAM_zero','GT_e'); %xlim([-0.1 0.6]); %ylim([-0.1 0.6]); set(gca,'FontSize',12,'FontWeight','bold'); h_xlabel = get(gca,'XLabel'); set(h_xlabel,'FontSize',12,'FontWeight','bold'); h_ylabel = get(gca,'YLabel'); set(h_ylabel,'FontSize',12,'FontWeight','bold'); h_zlabel = get(gca,'ZLabel'); set(h_zlabel,'FontSize',12,'FontWeight','bold'); hold off; axis equal; end end function plot_groundtruth() gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; gt_x = gt_x / 1000; % [mm] -> [m] gt_y = gt_y / 1000; % [mm] -> [m] plot(gt_x,gt_y,'g-','LineWidth',2); end
github
rising-turtle/slam_matlab-master
get_global_transformation_single.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/get_global_transformation_single.m
517
utf_8
f3c4ebbcb15dd51122b659ed76b7d39e
% Get global transformation for each data set with the first frame % % Author : Soonhac Hong ([email protected]) % Date : 3/27/14 function [h_global] = get_global_transformation_single(data_name) addpath('D:\Soonhac\SW\slamtoolbox\slamToolbox_11_09_08\FrameTransforms\Rotations'); % rx, ry, rz : [degree] % tx, ty, tz : [mm] rx=0; ry=0; rz=0; tx=0; ty=0; tz=0; euler=plane_fit_to_data_single(data_name); rx=euler(1); ry=euler(2); rz=euler(3); h_global = [euler_to_rot(rz, rx, ry) [tx ty tz]'; 0 0 0 1]; end
github
rising-turtle/slam_matlab-master
plot_toro.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot_toro.m
5,122
utf_8
b208119b20ac256877227aa33a31c7eb
% Plot the result of graph SLAM, g2o % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function plot_toro(org_file_name, opt_file_name, feature_flag) [ org_poses org_edges org_fpts_poses org_fpts_edges] = load_graph_toro(org_file_name); [ opt_poses opt_edges opt_fpts_poses opt_fpts_edges] = load_graph_toro(opt_file_name); % Show the pose start_index = 1; end_index = min(size(org_poses,1), size(opt_poses,1)); %80; if size(org_poses,2) == 3 % SE2 figure; %plot(org_poses(start_index:end_index,1), org_poses(start_index:end_index,2),'b.-','LineWidth',2); plot(org_poses(:,1), org_poses(:,2),'b.-','LineWidth',2); if ~isempty(org_fpts_poses) && feature_flag == 1 hold on; plot(org_fpts_poses(:,1), org_fpts_poses(:,2), 'bd'); end %xlabel('X [m]'); %ylabel('Y [m]'); %grid; %figure; hold on; %plot(opt_poses(start_index:end_index,1), opt_poses(start_index:end_index,2),'r.-','LineWidth',2); plot(opt_poses(:,1), opt_poses(:,2),'r.-','LineWidth',2); if ~isempty(opt_fpts_poses) && feature_flag == 1 plot(opt_fpts_poses(:,1), opt_fpts_poses(:,2), 'rd'); end %plot_groundtruth(); xlabel('X [m]'); ylabel('Y [m]'); grid; %legend('vro','vro fpts', 'g2o', 'g2o fpts','eGT'); legend('vro','toro'); %legend('vro','g2o'); %xlim([-0.1 0.2]); %ylim([-0.1 0.4]); hold off; elseif size(org_poses,2) == 6 % 3D figure; plot3(org_poses(:,1), org_poses(:,2), org_poses(:,3), 'b:', 'LineWidth',2); %xlabel('X [m]'); %ylabel('Y [m]'); %zlabel('Z [m]'); %grid; %figure; hold on; plot3(opt_poses(:,1), opt_poses(:,2), opt_poses(:,3), 'r-.', 'LineWidth',2); %plot_groundtruth_3D(); %plot_gt_etas(); xlabel('X [m]'); ylabel('Y [m]'); zlabel('Z [m]'); %legend('vro','TORO','GT_e'); legend('vro','TORO','GT_e'); grid; axis equal; hold off; show_errors(org_poses, opt_poses); end end function show_errors(org_poses, opt_poses) % Show last position last_org = org_poses(end,:) last_opt = opt_poses(end,:) distance_org = sqrt(sum(org_poses(end,1:3).^2)) distance_opt = sqrt(sum(opt_poses(end,1:3).^2)) z_rmse_org = sqrt(mean(org_poses(:,3).^2)) z_rmse_opt = sqrt(mean(opt_poses(:,3).^2)) z_me_org = mean(abs(org_poses(:,3))) z_me_opt = mean(abs(opt_poses(:,3))) end function plot_groundtruth() gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; gt_x = gt_x / 1000; % [mm] -> [m] gt_y = gt_y / 1000; % [mm] -> [m] plot(gt_x,gt_y,'g-','LineWidth',2); end function plot_groundtruth_3D() % inch2mm = 304.8; % 1 cube = 12 inch = 304.8 mm % gt_x = [0 0 13*inch2mm 13*inch2mm 0]; % gt_y = [-1*inch2mm 6*inch2mm 6*inch2mm -1*inch2mm -1*inch2mm]; % %gt_x = [0 0 2135 2135 0]; % %gt_y = [0 1220 1220 0 0]; % gt_z = [0 0 0 0 0]; % gt_x = gt_x / 1000; % [mm] -> [m] % gt_y = gt_y / 1000; % [mm] -> [m] % gt_z = gt_z / 1000; % [mm] -> [m] 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; gt_z = zeros(length(gt_x),1); plot3(gt_x,gt_y,gt_z,'g-','LineWidth',2); end % function [poses edges] = load_graph(file_name) % fid = fopen(file_name); % data = textscan(fid, '%s %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 %f %f %f'); % 2D format % fclose(fid); % % % Convert data % % Pose % data_name = data{1}; % data_name_list = {'VERTEX_SE2','EDGE_SE2','VERTEX_SE3:QUAT','EDGE_SE3:QUAT'}; % vertex_index = 1; % edge_index = 1; % for i = 1 : size(data_name,1) % if strcmp(data_name{i}, data_name_list{1}) % VERTEX_SE2 % unit_data =[]; % for j=3:5 % unit_data = [unit_data data{j}(i)]; % end % poses(vertex_index,:) = unit_data; % vertex_index = vertex_index + 1; % elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % unit_data =[]; % for j=2:12 % unit_data = [unit_data data{j}(i)]; % end % edges(edge_index,:) = unit_data; % edge_index = edge_index + 1; % elseif strcmp(data_name{i}, data_name_list{3}) % VERTEX_SE3:QUAT % unit_data =[]; % for j=3:9 % unit_data = [unit_data data{j}(i)]; % end % poses(vertex_index,:) = unit_data; % vertex_index = vertex_index + 1; % elseif strcmp(data_name{i}, data_name_list{4}) % EDGE_SE3:QUAT % unit_data =[]; % for j=2:31 % unit_data = [unit_data data{j}(i)]; % end % edges(edge_index,:) = unit_data; % edge_index = edge_index + 1; % end % % end % end
github
rising-turtle/slam_matlab-master
check_duplication.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/check_duplication.m
618
utf_8
a80eb6b224d62975425c043d78830e0d
% Check single data duplication in data set % Author : Soonhac Hong ([email protected]) % Date : 3/21/12 function [duplication_index, duplication_flag] = check_duplication(data_set, data) duplication_index = 0; duplication_flag = 0; distance_threshold = 41; % [mm]; typical absolute accuracy + 3 * typical repeatibility of SR4000 = 20 + 3 * 7 = 41 for i=1:size(data_set,1) distance = sqrt(sum((data_set(i,2:4)-data(2:4)).^2)); if distance <= distance_threshold duplication_flag = 1; duplication_index = data_set(i,1); break; end end end
github
rising-turtle/slam_matlab-master
load_graph_isam.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/load_graph_isam.m
1,876
utf_8
4136a74c81fcb67ebfd3066b75051e13
% Load the graph of isam function [poses] = load_graph_isam(file_name) fid = fopen(file_name); % Convert data % Pose data_name_list = {'Pose2d_Node','Pose2d_Pose2d_Factor','Pose3d_Node'}; vertex_index = 1; edge_index = 1; while ~feof(fid) %for i = 1 : size(data_name,1) header = textscan(fid, '%s',1); % 2D format data_name = header{1}; if strcmp(data_name, data_name_list{1}) % VERTEX_SE2 data = textscan(fid, '%f (%f,%f,%f)'); unit_data =[]; for j=1:4 unit_data = [unit_data data{j}]; end f_index(vertex_index, :) = unit_data(1); t_pose(vertex_index,:) = unit_data(2:3); o_pose(vertex_index,:) = unit_data(4); vertex_index = vertex_index + 1; % elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % unit_data =[]; % for j=4:12 % unit_data= [unit_data data{j}(i)]; % end % edges(edge_index,:) = unit_data; % edge_index = edge_index + 1; elseif strcmp(data_name, data_name_list{3}) % VERTEX_SE3:QUAT data = textscan(fid, '%f (%f,%f,%f;%f,%f,%f)'); unit_data =[]; for j=2:7 unit_data = [unit_data data{j}]; end t_pose(vertex_index,:) = unit_data(1:3); o_pose(vertex_index,:) = unit_data(4:6); vertex_index = vertex_index + 1; % elseif strcmp(data_name{i}, data_name_list{4}) % EDGE_SE3:QUAT % unit_data =[]; % for j=2:31 % unit_data = [unit_data data{j}(i)]; % end % edges(edge_index,:) = unit_data; % edge_index = edge_index + 1; end end fclose(fid); poses = [t_pose o_pose]; end
github
rising-turtle/slam_matlab-master
plot_icp_ct.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot_icp_ct.m
560
utf_8
0caa9c7fd9f9245a8cd86987ab0e4426
% Plot the result of computational time of icp % % Author : Soonhac Hong ([email protected]) % Date : 1/22/13 function plot_icp_ct(file_name) ct_data = load(file_name); ct = ct_data(:,3); figure; plot(ct,'b.'); ylabel('Computatoinal Time [sec]') set(gca,'FontSize',12,'FontWeight','bold'); h_ylabel = get(gca,'YLabel'); set(h_ylabel,'FontSize',12,'FontWeight','bold'); [ct_mean, ct_std] = compute_ct_statistics(ct_data); figure; errorbar(ct_mean, ct_std,'r'); icp_ct_max = max(ct) icp_ct_mean = mean(ct) icp_ct_median = median(ct) icp_ct_min = min(ct) end
github
rising-turtle/slam_matlab-master
show_camera_pose.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/show_camera_pose.m
2,064
utf_8
7cb0989642cf704f0bc47753fbb09e02
% Show camera pose with coordinates % % Author : Soonhac Hong ([email protected]) % Date : 2/11/13 function show_camera_pose(poses, is_new_figure, isVRO, isROS_SBA, isCoordinateOn, symbol_color ) % poses : n x 6D (n : number of poses) if is_new_figure figure; end if strcmp(isROS_SBA, 'ros_sba') new_poses=[]; for i=1:size(poses,1) T=[e2R([poses(i,4),poses(i,5),poses(i,6)]) [poses(i,1),poses(i,2),poses(i,3)]'; 0 0 0 1]; sba_T= inv(T); new_poses(i,:)=[sba_T(1:3,4)' R2e(sba_T(1:3,1:3))']; end poses = new_poses; end plot3(poses(:,1), poses(:,2), poses(:,3),symbol_color, 'LineWidth', 2); if strcmp(isCoordinateOn, 'on') hold on; %draw coordinates at each pose scale_unit = 0.05 * max(max(poses(:,1:3))); %[m] o_unit = [0 0 0 1]'; x_unit = [scale_unit 0 0 1]'; y_unit = [0 scale_unit 0 1]'; z_unit = [0 0 scale_unit 1]'; axis_unit = [o_unit, x_unit, o_unit, y_unit, o_unit, z_unit]; for i=1:size(poses,1) if strcmp(isVRO, 'vro') T = p2T(poses(i,:)); else rot = e2R(poses(i,4:6)); T = [rot poses(i,1:3)'; 0 0 0 1]; end hat_axis_unit = T*axis_unit; plot3(hat_axis_unit(1,1:2), hat_axis_unit(2,1:2), hat_axis_unit(3,1:2),'r-','LineWidth',2); %x axis plot3(hat_axis_unit(1,3:4), hat_axis_unit(2,3:4), hat_axis_unit(3,3:4),'g-','LineWidth',2); %y axis plot3(hat_axis_unit(1,5:6), hat_axis_unit(2,5:6), hat_axis_unit(3,5:6),'b-','LineWidth',2); %z axis end hold off; end axis equal; grid; xlabel('X'); ylabel('Y'); zlabel('Z'); end function T = 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
run_gslam.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/run_gslam.m
7,387
utf_8
78718a0ddde1865e57f3e6723649741f
% Conver the results of VRO to the vertex and edges for g2o % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function [vro_size] = run_gslam(data_index, dynamic_index, nFrame, g2o_file_name, g2o_dir_name, feature_flag, index_interval, dis) if nargin < 8 dis = 0; end % Load the result of VRO disp('Load the result from VRO.'); [f_index, t_pose, o_pose, feature_points] = load_vro(data_index,dynamic_index, nFrame, feature_flag); % t_pose[mm], o_pose[degree] if isempty(feature_points) feature_flag = 0; end vro_size = size(t_pose,1) % Convert the odometry and feature points to the global poses disp('Convert the VRO and feauture points w.r.t the glabal frame.'); [pose_index, e_t_pose e_o_pose e_ftps] = convert_o2p(f_index, t_pose, o_pose, feature_points); % graph slam % Set the dimension of the filter N = 20; num_landmarks = 0; %dim = 2 * (N + num_landmarks); % x1,y1,x2,y2..... dim = 3 * (N + num_landmarks); % x1,y1,z1,x2,y2,z2..... motion_noise = 34; % [mm] o_noise = 0.24 * 2; % make the constraint information matrix and vector Omega = zeros(dim, dim); Omega(1,1) = 1.0; Omega(2,2) = 1.0; Omega(3,3) = 1.0; Xi = zeros(dim, 1); Xi(1:3) = 0; % first frame locate at (0,0) data_index = min(find(f_index(:,2) == N)); %data_index = min(find(f_index(:,1) == (N-1))); % process the data for k = 0 : data_index-1 % n is the index of the robot pose in the matrix/vector %n = k * 2; %n1 = (f_index(k+1,1)-1)*2; %n2 = (f_index(k+1,2)-1)*2; %if abs(f_index(k+1,1) - f_index(k+1,2)) >= 2 && abs(f_index(k+1,1) - f_index(k+1,2)) <= 3 if (max(abs((t_pose(k+1,1) - t_pose(k+1,2)))) >= motion_noise || max(abs((o_pose(k+1,1) - o_pose(k+1,2)))) >= o_noise) ... && (max(abs((t_pose(k+1,1) - t_pose(k+1,2)))) <= motion_noise*3 || max(abs((o_pose(k+1,1) - o_pose(k+1,2)))) <= o_noise*3) n = k * 3; n1 = (f_index(k+1,1)-1)*3 n2 = (f_index(k+1,2)-1)*3 %measurement = feature_points(k+1,:); %data[k][0] %motion = t_pose(k+1,1:2); %data[k][1] motion = t_pose(k+1,:); %data[k][1] R = euler_to_rot(o_pose(k+1,1), o_pose(k+1,2), o_pose(k+1,3)); % integrate the measurements % for i = 1: size(feature_points) % m is the index of the landmark coordinate in the matrix/vector %m = 2 * (N + measurement[i][0]) %update the information maxtrix/vector based on the measurement % for b in range(2): % Omega.value[n+b][n+b] += 1.0 / measurement_noise % Omega.value[m+b][m+b] += 1.0 / measurement_noise % Omega.value[n+b][m+b] += -1.0 / measurement_noise % Omega.value[m+b][n+b] += -1.0 / measurement_noise % Xi.value[n+b][0] += -measurement[i][1+b] / measurement_noise % Xi.value[m+b][0] += measurement[i][1+b] / measurement_noise %update the information maxtrix/vector based on the robot motion % for b = 1:2 % %Omega(n+b, n+b) = Omega(n+b, n+b) + 1.0 / motion_noise; % (x1,x1), (y1,y1), (x2,x2), (y2,y2) % Omega(n1+b, n1+b) = Omega(n1+b, n1+b) + 1.0 / motion_noise; %(x1,x1), (y1,y1), (x2,x2), (y2,y2) % Omega(n2+b, n2+b) = Omega(n2+b, n2+b) + 1.0 / motion_noise; %(x1,x1), (y1,y1), (x2,x2), (y2,y2) % end % % for b = 1:2 % Omega(n1+b,n2+b) = Omega(n1+b, n2+b) + (-1.0) / motion_noise; % Omega(n2+b, n1+b) = Omega(n2+b, n1+b) + (-1.0) / motion_noise; % Xi(n1+b)= Xi(n1+b) - motion(b) / motion_noise; % Xi(n2+b)= Xi(n2+b) + motion(b) / motion_noise; % end for b = 1:3 %Omega(n+b, n+b) = Omega(n+b, n+b) + 1.0 / motion_noise; % (x1,x1), (y1,y1), (x2,x2), (y2,y2) Omega(n1+b, n1+b) = Omega(n1+b, n1+b) + 1.0 / motion_noise; %(x1,x1), (y1,y1), (z1,z1) % Omega(n2+b, n2+b) = Omega(n2+b, n2+b) + (1.0) / motion_noise; %(x2,x2), (y2,y2), (z2, z2) Omega(n2+b, n2+b) = Omega(n2+b, n2+b) + (1.0)*R(b,b) / motion_noise; %(x2,x2), (y2,y2), (z2, z2) d_index = [1 2 3]; b_index = find(d_index == b); d_index(b_index)=[]; for d = 1:size(d_index,2) Omega(n2+b, n2+d_index(d)) = Omega(n2+b, n2+d_index(d)) + (1.0)*R(b,d_index(d)) / motion_noise; end end for b = 1:3 % Omega(n1+b,n2+b) = Omega(n1+b, n2+b) + (-1.0) / motion_noise; Omega(n1+b,n2+b) = Omega(n1+b, n2+b) + (-1.0)*R(b,b) / motion_noise; d_index = [1 2 3]; b_index = find(d_index == b); d_index(b_index)=[]; for d = 1:size(d_index,2) Omega(n1+b, n2+d_index(d)) = Omega(n1+b, n2+d_index(d)) + (-1.0)*R(b,d_index(d)) / motion_noise; end Omega(n2+b,n1+b) = Omega(n2+b, n1+b) + (-1.0) / motion_noise; Xi(n1+b)= Xi(n1+b) - motion(b) / motion_noise; Xi(n2+b)= Xi(n2+b) + motion(b) / motion_noise; end end end %compute best estimate mu = (Omega^-1) * Xi; g_t_pose=[]; temp_index = 1; for i=1:3:size(mu,1) g_t_pose(temp_index,:) = [mu(i), mu(i+1), mu(i+2)]; temp_index = temp_index + 1; end %Show the result figure; plot(g_t_pose(:,1), g_t_pose(:,2),'r*-'); hold on; plot(e_t_pose(1:N,1), e_t_pose(1:N,2),'bo-'); hold off end function [isExist previous_index] = getPreviousIndex(data_set,pts) isExist = 0; previous_index = 0; distance_threshold = 41; % [mm]; typical absolute accuracy + 3 * typical repeatibility of SR4000 = 20 + 3 * 7 = 41 for i=1:size(data_set,1) if data_set(i,1) > 0 && data_set(i,1) == pts(1) % Skip non-valid data distance = sqrt(sum((data_set(i,3:5)-pts(4:6)).^2)); if distance <= distance_threshold isExist = 1; previous_index = data_set(i,2); break; end end end end function plot_trajectory(e_pose, fpts) figure; gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; plot(e_pose(:,1),e_pose(:,2),'bo-'); hold on; plot(gt_x,gt_y,'r-','LineWidth',2); if ~isempty(fpts) plot(fpts(:,2),fpts(:,3),'gd'); legend('Estimated Pose','Estimated Truth','feature points'); else legend('Estimated Pose','Estimated Truth'); end xlabel('X [mm]'); ylabel('Y [mm]'); 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'); hold off; figure; gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; gt_z = [0 0 0 0 0]; plot3(e_pose(:,1),e_pose(:,2),e_pose(:,3),'bo-'); hold on; plot3(gt_x,gt_y,gt_z,'r-','LineWidth',2); if ~isempty(fpts) plot3(fpts(:,2),fpts(:,3),fpts(:,4),'gd'); legend('Estimated Pose','Estimated Truth','feature points'); else legend('Estimated Pose','Estimated Truth'); end xlabel('X [mm]'); ylabel('Y [mm]'); zlabel('Z [mm]'); 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'); end
github
rising-turtle/slam_matlab-master
generate_video.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/generate_video.m
5,239
utf_8
1e4f4012d3f049bf499b74bcb98967b4
% Conver isp to ply for meshlab % % Author : Soonhac Hong ([email protected]) % Date : 4/1/13 function generate_video(isp_file_name, opt_file_name, file_index, dynamic_index, isgframe, vro_name) close all; [poses] = load_graph_isp(isp_file_name); [opt_poses] = load_graph_isp(opt_file_name); % convert_feature2ply(ply_headers, ply_file_name, poses, file_index, dynamic_index, isgframe); data_name_list={'pitch', 'pan', 'roll','x2', 'y2', 'c1', 'c2','c3','c4','m','etas','loops2','kinect_tum','sparse_feature','swing'}; % Write headers pose_interval = 4; sample_interval = 3; image_width = 176; 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(opt_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([opt_poses(i,4), opt_poses(i,5), opt_poses(i,6)]) opt_poses(i,1:3)'; 0 0 0 1]; % e2R([rx,ry,rz]) [radian] else h{i} = [euler_to_rot(opt_poses(i,5)*180/pi, opt_poses(i,4)*180/pi, opt_poses(i,6)*180/pi) opt_poses(i,1:3)'; 0 0 0 1]; % euler_to_rot(ry, rx, rz) [degree] end end distance_threshold_max = 5; distance_threshold_min = 0.8; x_min = min(opt_poses(:,1)) - 1; x_max = max(opt_poses(:,1)) + 1; y_min = min(opt_poses(:,2)) - 1; y_max = max(opt_poses(:,2)) + 1; z_min = min(opt_poses(:,3)) - 1; z_max = max(opt_poses(:,3)) + 1; scrsz = get(0,'ScreenSize'); % figure(video_figure); video_figure=figure('Position',[scrsz(3)/4 scrsz(4)/4 scrsz(3)/2 scrsz(4)/2]); [prefix, confidence_read] = get_sr4k_dataset_prefix(data_name_list{file_index+3}, dynamic_index); vidObj = VideoWriter(sprintf('%s_gslam_vf.avi', prefix)); vidObj.Quality=100; vidObj.FrameRate=5; %vidObj.Height=scrsz(4)/2; %vidObj.Width=scrsz(3)/2; open(vidObj); for i=1:size(opt_poses,1) i % show images if check_stored_visual_feature(data_name_list{file_index+3}, dynamic_index, i, true, 'intensity') == 0 [img, x, y, z, c, elapsed_pre] = LoadSR(data_name_list{file_index+3}, '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{file_index+3}, dynamic_index, i, true, 'intensity'); if i>=2 [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_list{file_index+3}, dynamic_index, i-1, i, 'none', true); end end subplot(1,2,1);imshow(img);colormap(gray); if i>=2 hold on; for j=1:size(op_pset2_image_index,1) subplot(1,2,1);plot(round(op_pset2_image_index(j,1))+1, round(op_pset2_image_index(j,2))+1,'r+','Markersize',10); end end axis image; % set(gca,'XTick',[]); % set(gca,'YTick',[]); % show poses subplot(1,2,2);plot3(poses(i,1),poses(i,2),poses(i,3),'g.','LineWidth', 2); hold on; subplot(1,2,2);plot3(opt_poses(i,1),opt_poses(i,2),opt_poses(i,3),'r.', 'LineWidth',2); grid on; axis equal; axis([x_min x_max y_min y_max z_min z_max]); xlabel('X');ylabel('Y');zlabel('Z'); %axis equal; %hold off; % if mod(i,pose_interval) == 1 % % confidence_threshold = floor(max(max(c))/2); % % 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 unit_pose(3) <= -0.1 % if c(row_idx,col_idx) >= confidence_threshold && unit_pose_distance < distance_threshold_max && unit_pose_distance > distance_threshold_min % unit_pose_global = h{i}*[unit_pose, 1]'; % unit_color = [img(row_idx, col_idx),img(row_idx, col_idx),img(row_idx, col_idx)]./255; % %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; % subplot(1,2,2);plot3(unit_pose_global(1,1),unit_pose_global(2,1),unit_pose_global(3,1),'Color',unit_color); % grid; % end % end % end % end % end currFrame = getframe(video_figure); writeVideo(vidObj,currFrame); drawnow; end hold off; close(vidObj); end
github
rising-turtle/slam_matlab-master
plot_kinect_tum.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/plot_kinect_tum.m
3,022
utf_8
e0bff3482681f917c9d1b66f877a96f7
% Plot the result of graph SLAM for kinect_tum data % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function plot_kinect_tum(org_file_name, opt_file_name, optimizer_name, dir_index, nFrame) switch optimizer_name case 'isam' [org_poses] = load_graph_isp(org_file_name); if ~strcmp(opt_file_name, 'none') [opt_poses] = load_graph_isam(opt_file_name); end case 'toro' [org_poses org_edges org_fpts_poses org_fpts_edges] = load_graph_toro(org_file_name); [opt_poses opt_edges opt_fpts_poses opt_fpts_edges] = load_graph_toro(opt_file_name); case 'g2o' [org_poses org_edges org_fpts_poses org_fpts_edges] = load_graph_g2o(org_file_name); [opt_poses opt_edges opt_fpts_poses opt_fpts_edges] = load_graph_g2o(opt_file_name); end %load ground truth [gt rgbdslam rtime] = Load_kinect_gt(dir_index); first_timestamp = get_timestamp_kinect_tum(dir_index,1); gt_start_index = find(gt(:,1) > first_timestamp, 1); if gt(gt_start_index,1) - first_timestamp > first_timestamp - gt(gt_start_index-1,1) gt_start_index = gt_start_index - 1; end %gt(gt_start_index,:) last_timestamp = get_timestamp_kinect_tum(dir_index,nFrame); gt_last_index = find(gt(:,1) > last_timestamp, 1); if gt(gt_last_index,1) - last_timestamp > last_timestamp - gt(gt_last_index-1,1) gt_last_index = gt_last_index - 1; end % Show the pose start_index = 1; if ~strcmp(opt_file_name, 'none') end_index = min(size(org_poses,1), size(opt_poses)); %80; else end_index = size(org_poses,1); end if size(org_poses,2) == 2 % SE2 figure; plot(org_poses(start_index:end_index,1), org_poses(start_index:end_index,2),'g:-'); hold on; if ~strcmp(opt_file_name, 'none') plot(opt_poses(start_index:end_index,1), opt_poses(start_index:end_index,2),'b.-','LineWidth',2); end plot(gt(:,2), gt(:,3),'r.-','LineWidth',2); xlabel('X [m]'); ylabel('Y [m]'); grid; if ~strcmp(opt_file_name, 'none') legend('vro',optimizer_name,'GT'); else legend('vro','GT'); end hold off; elseif size(org_poses,2) == 3 % SE3:QUAT figure; plot3(org_poses(start_index:end_index,1), org_poses(start_index:end_index,2), org_poses(start_index:end_index,3), 'g-', 'LineWidth',1); hold on; if ~strcmp(opt_file_name, 'none') plot3(opt_poses(start_index:end_index,1), opt_poses(start_index:end_index,2), opt_poses(start_index:end_index,3), 'b.-', 'LineWidth',2); end plot3(gt(gt_start_index:gt_last_index,2), gt(gt_start_index:gt_last_index,3), gt(gt_start_index:gt_last_index,4), 'r-','LineWidth',1); %plot3(rgbdslam(start_index:end_index,2), rgbdslam(start_index:end_index,3), rgbdslam(start_index:end_index,4), 'b:', 'LineWidth',1); xlabel('X [m]'); ylabel('Y [m]'); zlabel('Z [m]'); if ~strcmp(opt_file_name, 'none') legend('vro',optimizer_name,'GT_e'); else legend('vro','GT'); end grid; axis equal; hold off; end end
github
rising-turtle/slam_matlab-master
generate_map.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/generate_map.m
1,184
utf_8
3157a39500f461ed019f656d17af83e5
% Generate *.ply files for visualization % % Author : Soonhac Hong ([email protected]) % Date : 6/5/14 function generate_map() graphslam_addpath; file_index = 12; %16; % 5 = whitecane 6 = etas 7 = loops 8 = kinect_tum 9 = loops2 10= amir_vro 11 = sparse_feature 12 = swing 13 = swing2 14 = motive 15 = object_recognition 16=map 17=it dynamic_index = 25; %5; isgframe='none'; vro_name='vro'; %gtsam_isp_file_name='data\3d\whitecane\revisiting2_10m_Replace_pose_zero_411_vro_gtsam.isp'; %gtsam_opt_file_name='results\isam\3d\map5_Replace_pose_zero_3842_vro_gtsam.opt'; %gtsam_opt_file_name='results/isam/3d/revisiting2_10m_Replace_pose_zero_411_vro_gtsam.opt'; %18 %gtsam_opt_file_name='results/isam/3d/revisiting6_10m_Replace_pose_zero_910_vro_gtsam.opt'; %22 gtsam_opt_file_name='results/isam/3d/revisiting9_10m_Replace_pose_zero_827_vro_gtsam.opt'; %25 %gtsam_opt_file_name='results/isam/3d/revisiting8_10m_Replace_pose_zero_1084_vro_gtsam.opt'; %24 % VRO trajectory %convert_isp2ply(gtsam_isp_file_name, file_index, dynamic_index, isgframe, vro_name); % PGO trajectory and its map convert_isp2ply(gtsam_opt_file_name, file_index, dynamic_index, isgframe, vro_name); end
github
rising-turtle/slam_matlab-master
run_pose_graph_optimization_v0.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/run_pose_graph_optimization_v0.m
989
utf_8
7b2b6f882f54303b50a4255b1264f1df
% Run pose graph optimization % % Author : Soonhac Hong ([email protected]) % History : % 3/26/14 : Created function [result, graph, initial, h_global]=run_pose_graph_optimization_v0(data_name, dynamic_index, vro_result, vro_pose_std, graph, initial, h_global, dis) import gtsam.* t = gtsam.Point3(0, 0, 0); if isempty(h_global) h_global = get_global_transformation_dataname(data_name, dynamic_index, 'none'); rot = h_global(1:3,1:3); R = gtsam.Rot3(rot); origin= gtsam.Pose3(R,t); initial.insert(0,origin); end pgc_t=tic; [graph,initial] = construct_pose_graph(vro_result, vro_pose_std, graph, initial); first = initial.at(0); pgc_ct =toc(pgc_t) graph.add(NonlinearEqualityPose3(0, first)); gtsam_t=tic; optimizer = LevenbergMarquardtOptimizer(graph, initial); result = optimizer.optimizeSafely(); gtsam_ct =toc(gtsam_t) % Show the results in the plot and generate location information if dis==true plot_graph_initial_result_v0(initial, result); end end
github
rising-turtle/slam_matlab-master
get_timestamp_kinect_tum_color.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/get_timestamp_kinect_tum_color.m
572
utf_8
cd7c6a57abe82b21dac2db599552499f
% Get time stamp of color image in kinect_tum dataset % % Author : Soonhac Hong ([email protected]) % Date : 12/20/12 function [time_stamp] = get_timestamp_kinect_tum_color(dm,j) dir_name = get_kinect_tum_dir_name(); [depth_data_dir, err] = sprintf('E:/data/kinect_tum/%s/rgb',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',file_list{j}); time_stamp = str2num(strrep(file_name, '.png','')); end
github
rising-turtle/slam_matlab-master
pose_optimization_example_1d.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/pose_optimization_example_1d.m
1,981
utf_8
692c2cb99f72f86abae593d592dbdb8f
% 1D Example of Pose Graph Optimization % Data : 4/12/12 % Author : Soonhac Hong ([email protected]) function pose_optimization_example_1d() % 1D case pose_data=[1 1 0; 1 2 9 ; 2 3 5; 3 4 8; 1 3 11; 1 4 19; 2 4 12]; % [first pose, second pose, constraint] xinit = [0 9 14 22]'; motion_noise = 0.3; pose_num = size(unique(pose_data(:,1:2)),1); % first position is not optimized. Omega = zeros(pose_num,pose_num); Xi = zeros(pose_num,1); Odometry=zeros(pose_num,1); %Odometry = zeros(pose_num,1); % Fill the elements of Omega and Xi % Initial point Omega(1,1) = 1; Xi(1) = pose_data(1,3); Odometry(1) = pose_data(1,3); for i=2:size(pose_data,1) unit_data = pose_data(i,:); current_index = unit_data(1); next_index = unit_data(2); movement = unit_data(3); % Fill diagonal elements of Omega Omega(current_index,current_index) = Omega(current_index,current_index) + 1/motion_noise; Omega(next_index,next_index) = Omega(next_index,next_index) + 1/motion_noise; % Fill Off-diagonal elements of Omega Omega(current_index,next_index) = Omega(current_index,next_index) + (-1)/motion_noise; Omega(next_index,current_index) = Omega(next_index,current_index) + (-1)/motion_noise; % Fill Xi Xi(current_index) = Xi(current_index) + (-1)*movement/motion_noise; Xi(next_index) = Xi(next_index) + movement/motion_noise; % Update Odometry if abs(current_index - next_index) == 1 Odometry(next_index) = Odometry(next_index-1) + movement; end end %Omega %Xi %mu = Omega^-1 * Xi % Using LM %myfun = @(x,xdata)Rot(x(1:3))*xdata+repmat(x(4:6),1,length(xdata)); myfun = @(x,xdata)xdata*x(1:size(xdata,1)); xdata = Omega; ydata = Xi; options = optimset('Algorithm', 'levenberg-marquardt'); %x = lsqcurvefit(myfun, zeros(6,1), p, q, [], [], options); x = lsqcurvefit(myfun, xinit, xdata, ydata, [], [], options); plot(Odometry,'bd-'); hold on; plot(x,'ro-'); hold off; legend('Odometry','Optimized'); end
github
rising-turtle/slam_matlab-master
convert_isam2rossba.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/convert_isam2rossba.m
15,493
utf_8
039d105831c4081ddbc63fca4bd798e9
% Convert *.isp and *.sam to files for ROS sba(http://www.ros.org/wiki/sba/Tutorials/IntroductionToSBA) % % Author : Soonhac Hong ([email protected]) % Date : 2/11/13 function convert_isam2rossba() 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'); %% Load isam data %sam_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\3d\whitecane\exp8__Replace_pose_feature_76_18_vro_cov.sam'; %isp_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\3d\whitecane\exp8__Replace_pose_feature_76_18_vro.isp'; %sam_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\3d\whitecane\exp8__Replace_pose_feature_10138_580_vro_cov.sam'; %isp_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\3d\whitecane\exp8__Replace_pose_feature_10138_580_vro.isp'; %isp_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\3d\whitecane\exp3_bus_straight_150_Replace_pose_feature_1385_84_vro_icp_ch.isp'; %sam_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\3d\whitecane\exp3_bus_straight_150_Replace_pose_feature_1385_84_vro_icp_ch_cov.sam'; file_index = 9; % 5 = whitecane 6 = etas 7 = loops 8 = kinect_tum 9 = loops2 10= amir_vro 11 = sparse_feature dynamic_index =1; % 15:square_500, 16:square_700, 17:square_swing vro_name_list={'vro','vro_icp','vro_icp_ch','icp'}; vro_name_index = 1; vro_name=vro_name_list{vro_name_index}; compensation_option ={'Replace','Linear'}; compensation_index = 1; feature_pose_name = 'pose_feature'; vro_size = 426; %1614; %1632; pose_size = 48; %101; %104; isgframe = 'gframe'; [g2o_result_dir_name, isam_result_dir_name, vro_dir_name, dynamic_dir_name] = get_file_names(file_index, dynamic_index); sam_filename = sprintf('%s%s_%s_%s_%d_%d_%s_cov.sam', vro_dir_name, dynamic_dir_name, compensation_option{compensation_index}, feature_pose_name, vro_size, pose_size, vro_name); isp_filename = sprintf('%s%s_%s_%s_%d_%d_%s.isp', vro_dir_name, dynamic_dir_name, compensation_option{compensation_index}, feature_pose_name, vro_size, pose_size, vro_name); sba_filename =sprintf('data/ba/ros_sba/%s_%s_%s_%d_%d_ros_sba.out',dynamic_dir_name, compensation_option{compensation_index}, feature_pose_name, vro_size, pose_size); %sam_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\3d\whitecane\exp1_bus_door_straight_150_Replace_pose_zero_1632_104_vro_icp_ch_cov.sam'; %isp_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\3d\whitecane\exp1_bus_door_straight_150_Replace_pose_zero_1632_104_vro_icp_ch.isp'; %sba_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\ba\ros_sba\exp8__Replace_pose_feature_10138_580_ros_sba.out'; [landmarks, initial_landmarks] = load_landmark_vro(sam_filename); [initial_camera_pose] = load_camera_pose(isp_filename); % x, y, z, rx, ry, rz sr4k_parameter = initialize_cam(); %check_camera_projection(initial_camera_pose, landmarks, isgframe); %show_camera_pose(initial_camera_pose, true, 'vro', 'k.-'); %debug % show_camera_pose(initial_camera_pose,true, 'k.-'); % hold on; % plot3(initial_landmarks(:,2),initial_landmarks(:,3),initial_landmarks(:,4),'m*') % axis equal; %% Generate cameara pose % Data format (http://phototour.cs.washington.edu/bundler/bundler-v0.3-manual.html#S6) % # Bundle file v0.3 % <num_cameras> <num_points> [two integers] % <camera1> % <camera2> % ... % <cameraN> % <point1> % <point2> % ... % <pointM> % % <cameraI> % <f> <k1> <k2> [the focal length, followed by two radial distortion coeffs] % <R> [a 3x3 matrix representing the camera rotation] % <t> [a 3-vector describing the camera translation] % % Global coordindate % Z : depth % -------------> X % | % | % V % Y % fu = sr4k_parameter.f; u0 = sr4k_parameter.Cx; v0 = sr4k_parameter.Cy; kd = [sr4k_parameter.k1, sr4k_parameter.k2]; %ros_sba_T = inv(p2T([0,0,0,-90*pi/180,0,0])); ros_sba_T = sr4k_p2T([0,0,0,pi/2,0,0]); %ros_sba_R2 = e2R([-pi/2, 0, -pi/2]); %ros_sba_T = [ros_sba_R2 [0, 0, 0]'; 0 0 0 1]; %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); %filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\ba\ros_sba\exp8__Replace_pose_feature_76_18_ros_sba.out'; %sba_filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\ba\ros_sba\exp8__Replace_pose_feature_10138_580_ros_sba.out'; %filename = 'D:\soonhac\Project\PNBD\SW\ASEE\GraphSLAM\data\ba\ros_sba\exp3_bus_straight_150_Replace_pose_feature_1385_84_ros_sba.out'; converted_camera_pose=[]; cams_fd = fopen(sba_filename, 'w'); fprintf(cams_fd,'# Bundle file v0.3\n'); fprintf(cams_fd,'%d %d\n', size(initial_camera_pose,1), size(initial_landmarks,1)); %r2d = 180/pi; %first camera pose as the reference frame % rot = e2R([pi, 0, 0]); % trans = [0, 0, 0]'; % fprintf(cams_fd,'%f %f %f\n', fu, kd); % for r=1:3 % fprintf(cams_fd,'%f %f %f\n', rot(r,:)); % end % fprintf(cams_fd,'%f %f %f\n', trans(1), trans(2), trans(3)); % converted_camera_pose=[converted_camera_pose; trans(1:3)' [0, 0, 0]]; % ros_sba_T_camera = [rot trans; 0 0 0 1]; trans = [0 0 0]; rot = e2R([pi(), 0, 0]);%e2R([initial_camera_pose(1,4), initial_camera_pose(1,5), initial_camera_pose(1,6)]); bundler_T = [rot trans'; 0 0 0 1]; for i=1:size(initial_camera_pose,1) trans = initial_camera_pose(i,1:3); if strcmp(isgframe, 'gframe') rot = e2R([initial_camera_pose(i,4), initial_camera_pose(i,5), initial_camera_pose(i,6)]); else rot = euler_to_rot(initial_camera_pose(i,5)*180/pi,initial_camera_pose(i,4)*180/pi,initial_camera_pose(i,6)*180/pi); end T = [rot trans'; 0 0 0 1]; %T = ros_sba_T * inv(first_camera_T) * T; %T = ros_sba_T * T; %T = bundler_T*ros_sba_T * T; sba_T = inv(T); % ROS SBA convention !!!! camera N = inv(T)* camera N+1 if strcmp(isgframe, 'gframe') T = bundler_T*sba_T; % rotate 180 around x for Bundler frame else T = bundler_T*ros_sba_T*sba_T*inv(ros_sba_T); % rotate 180 around x to Bundler frame end trans = T(1:3,4)'; rot = T(1:3,1:3); %trans = ros_sba_T*[trans'; 1]; % convert coordinate %debug_rot = euler_to_rot(initial_camera_pose(i,5)*r2d,initial_camera_pose(i,4)*r2d,initial_camera_pose(i,6)*r2d); % [ry, rx, rz] %rot = e2R([initial_camera_pose(i,4), -initial_camera_pose(i,6), initial_camera_pose(i,5)]); %rot = e2R([0, 0, 0]); %rot = ros_sba_T_camera(1:3,1:3)*ros_sba_T(1:3,1:3)*e2R([initial_camera_pose(i,4), initial_camera_pose(i,5), initial_camera_pose(i,6)]); fprintf(cams_fd,'%f %f %f\n', fu, kd); for r=1:3 fprintf(cams_fd,'%f %f %f\n', rot(r,:)); end fprintf(cams_fd,'%f %f %f\n', trans(1), trans(2), trans(3)); %fprintf(cams_fd,'%f %f %f\n', trans); %converted_camera_pose=[converted_camera_pose; T(1:3,4)' R2e(T(1:3,1:3))']; converted_camera_pose=[converted_camera_pose; trans R2e(rot)']; end show_camera_pose(converted_camera_pose,true, 'typical', 'ros_sba', 'on', 'k.-'); %% Generate landmarks points % % <pointM> % <position> [a 3-vector describing the 3D position of the point] % <color> [a 3-vector describing the RGB color of the point] % <view list> [a list of views the point is visible in] % <view list> % <nlist> <camera> <key> <x> <y> .... [The pixel positions are floating point numbers in a coordinate system where the origin is the center of the image, the x-axis increases to the right, and the y-axis increases towards the top of the image.] % % Note : The reference coordinate of landmark point is the first camera coordinate !!!! %ros_sba_T_landmark = sr4k_p2T([0,0,0,-pi/2,0,0]); %TODO : initial_landmarks and landmarks position is different in position %and measured pixel converted_landmark=[]; color = [255, 255, 255]; key_offset = landmarks(1,2); for i=1:size(initial_landmarks,1) xyz = initial_landmarks(i,2:4); if strcmp(isgframe, 'gframe') xyz = [xyz'; 1]; else xyz = ros_sba_T*[xyz'; 1]; % convert coordinate because z-axis should represent the depth. end %xyz = bundler_T * ros_sba_T*[xyz'; 1]; % convert coordinate. See Note !!!! %xyz = ros_sba_T*inv(first_camera_T)*[xyz'; 1]; % convert coordinate. See Note !!!! landmark_idx = initial_landmarks(i,1); nframes_idx=find(landmarks(:,2)==landmark_idx); fprintf(cams_fd,'%f %f %f\n', xyz(1), xyz(2), xyz(3)); %fprintf(cams_fd,'%f %f %f\n', xyz); fprintf(cams_fd,'%d %d %d\n', color); %View list fprintf(cams_fd,'%d ', size(nframes_idx,1)); for c=1:size(nframes_idx,1) frame_idx = landmarks(nframes_idx(c,1),1); key_idx = landmarks(nframes_idx(c,1),2); img_idx = landmarks(nframes_idx(c,1),6:7); img_idx(1) = img_idx(1) - u0; % Adjust image coordinate for ROS SBA img_idx(2) = (-1) * (img_idx(2) - v0); % Adjust image coordinate for ROS SBA fprintf(cams_fd,'%d %d %f %f ', frame_idx, key_idx-key_offset, img_idx); converted_landmark=[converted_landmark; frame_idx, key_idx-key_offset, xyz(1), xyz(2), xyz(3),img_idx]; end fprintf(cams_fd,'\n'); %coverted_landmark=[coverted_landmark; xyz(1), xyz(2), xyz(3)]; end fclose(cams_fd); %Debug - show landmarks hold on; plot3(converted_landmark(:,3), converted_landmark(:,4), converted_landmark(:,5), 'm.'); hold off; axis equal; %check_camera_projection_with_converted_data(converted_camera_pose, converted_landmark, initial_camera_pose, landmarks, isgframe); end function check_camera_projection_with_converted_data(camera_poses, feature_points, initial_camera_pose, initial_landmarks, isgframe) cam = initialize_cam(); features_info=[]; ros_sba_T = sr4k_p2T([0,0,0,pi/2,0,0]); u0 = cam.Cx; v0 = cam.Cy; trans = [0 0 0]; rot = e2R([pi(), 0, 0]);%e2R([initial_camera_pose(1,4), initial_camera_pose(1,5), initial_camera_pose(1,6)]); bundler_T = [rot trans'; 0 0 0 1]; camera_index_list=unique(feature_points(:,1)); for i=1:size(camera_index_list,1) temp_t = camera_poses(i,1:3)'; initial_temp_t = initial_camera_pose(i,1:3)'; %temp_R = e2R(camera_poses(i,4:6)'); if strcmp(isgframe, 'gframe') temp_R = e2R(camera_poses(i,4:6)'); initial_temp_R = e2R(initial_camera_pose(i,4:6)'); else temp_R = euler_to_rot(camera_poses(i,5)*180/pi,camera_poses(i,4)*180/pi,camera_poses(i,6)*180/pi); end T = [temp_R, temp_t; 0 0 0 1]; T = bundler_T*T; % Convert VRO frame to SBA frame T = inv(T); temp_t = T(1:3,4); temp_R = T(1:3,1:3); abs(temp_t - initial_temp_t) abs(temp_R - initial_temp_R) initial_camera_index = camera_index_list(i); initial_data_index_list = find(initial_landmarks(:,1) == initial_camera_index); initial_unit_data = initial_landmarks(initial_data_index_list,:); initial_estimated_uv = []; initial_measured_uv = initial_unit_data(:,6:7); camera_index = camera_index_list(i); data_index_list = find(feature_points(:,1) == camera_index); unit_data = feature_points(data_index_list,:); estimated_uv = []; measured_uv = [unit_data(:,6)+u0, unit_data(:,7).*(-1) + v0]; for j=1:size(unit_data,1) %temp_p = ros_sba_T * [unit_data(j,3:5) 1]'; temp_p = [unit_data(j,3:5) 1]'; initial_temp_p = [initial_unit_data(j,3:5) 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 )'; %estimated_uv(j,:) = hi_cartesian_test(initial_temp_p(1:3), temp_t, temp_R, cam, features_info )'; initial_estimated_uv(j,:) = hi_cartesian_test(initial_temp_p(1:3), initial_temp_t, initial_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)+u0,unit_data(:,7).*(-1) + v0,'ro'); plot(measured_uv(:,1), measured_uv(:,2),'ro'); plot(initial_estimated_uv(:,1), initial_estimated_uv(:,2),'gd'); legend('Estimated','Measured','Init Estimated'); hold off; projection_error = sqrt(sum((estimated_uv - measured_uv).^2,2)); projection_error_mean_std(i,:) = [mean(projection_error), std(projection_error)]; initial_projection_error = sqrt(sum((initial_estimated_uv - initial_measured_uv).^2,2)); initial_projection_error_mean_std(i,:) = [mean(initial_projection_error), std(initial_projection_error)]; %compare with initial values %abs(projection_error - initial_projection_error) %abs(projection_error_mean_std - initial_projection_error_mean_std) end figure; errorbar(projection_error_mean_std(:,1), projection_error_mean_std(:,2),'b'); figure; errorbar(initial_projection_error_mean_std(:,1), initial_projection_error_mean_std(:,2),'r'); end function check_camera_projection(camera_poses, 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) temp_t = camera_poses(i,1:3)'; %temp_R = e2R(camera_poses(i,4:6)'); if strcmp(isgframe, 'gframe') temp_R = e2R(camera_poses(i,4:6)'); else temp_R = euler_to_rot(camera_poses(i,5)*180/pi,camera_poses(i,4)*180/pi,camera_poses(i,6)*180/pi); end % T = [temp_R, temp_t; 0 0 0 1]; % T = ros_sba_T*T; % Convert VRO frame to SBA frame % temp_t = T(1:3,4); % temp_R = T(1:3,1:3); camera_index = camera_index_list(i); data_index_list = find(feature_points(:,1) == camera_index); unit_data = feature_points(data_index_list,:); estimated_uv = []; for j=1:size(unit_data,1) %temp_p = ros_sba_T * [unit_data(j,3:5) 1]'; temp_p = [unit_data(j,3:5) 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 T = 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
sampling_feature_points.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/sampling_feature_points.m
2,203
utf_8
50716c6d229373f5a112bf5f9b1292e5
% Conver the results of VRO to the vertex and edges for isam % % Author : Soonhac Hong ([email protected]) % Date : 3/14/13 function new_feature_points = sampling_feature_points(feature_points, min_pixel_distance) camera_index_list=unique(feature_points(:,1)); temp_feature_points=[]; %min_pixel_distance = 2; 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,:); sampled_unit_data = sampling_unit_data(unit_data, min_pixel_distance); temp_feature_points(data_index_list,:) = sampled_unit_data; end sampled_index = find(temp_feature_points(:,end) == 1); new_feature_points = temp_feature_points(sampled_index,1:end-1); % Delete near feature points which distance is less than 0.8m for i=1:size(new_feature_points,1) distance = sqrt(sum(new_feature_points(:,4:6).^2,2)); end near_feature_idx = find(distance < 800); % 800 [mm] new_feature_points(near_feature_idx,:)=[]; end function sampled_unit_data_final = sampling_unit_data(unit_data, min_pixel_distance) sampled_unit_data = []; %sampled_data_index_list = []; center_data_index = find_nearest_center(unit_data(:,7:8)); %sampled_data_index_list = [sampled_data_index_list; center_data_index]; sampled_unit_data = [center_data_index, unit_data(center_data_index,7:8)]; for i=1:size(unit_data,1) [duplication_index, duplication_flag] = check_duplication_imgidx(sampled_unit_data, unit_data(i,7:8), min_pixel_distance); if duplication_flag == 0 % check duplicated points sampled_unit_data = [sampled_unit_data; [i, unit_data(i,7:8)]]; end end sampled_unit_data_final = unit_data; sampled_unit_data_final(sampled_unit_data(:,1), 9) = 1; end function data_index = find_nearest_center(unit_pixel_data) image_center_x = 176/2; image_center_y = 144/2; distance = sqrt(sum((unit_pixel_data- repmat([image_center_x, image_center_y], size(unit_pixel_data,1), 1)).^2, 2)); [~, data_index] = min(distance); end
github
rising-turtle/slam_matlab-master
modify_graph_isam.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/modify_graph_isam.m
3,121
utf_8
c0aacf62c3a5af46b5574b70ed447559
% Load the graph of isam function modify_graph_isam(input_file_name) temp_file_name = textscan(input_file_name,'%s','Delimiter','.'); output_file_name = sprintf('%s_modified.sam',temp_file_name{1}{1,1}); fid = fopen(input_file_name); % Convert data % Pose data_name_list = {'EDGE3','POINT3'}; vertex_index = 1; edge_index = 1; while ~feof(fid) %for i = 1 : size(data_name,1) %header = textscan(fid, '%s',1); % 2D format %data_name = header{1}; %if strcmp(data_name, data_name_list{1}) % VERTEX_SE2 data = textscan(fid, '%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'); % unit_data =[]; % for j=1:4 % unit_data = [unit_data data{j}]; % end % f_index(vertex_index, :) = unit_data(1); % t_pose(vertex_index,:) = unit_data(2:3); % o_pose(vertex_index,:) = unit_data(4); % vertex_index = vertex_index + 1; % elseif strcmp(data_name{i}, data_name_list{2}) % EDGE_SE2 % unit_data =[]; % for j=4:12 % unit_data= [unit_data data{j}(i)]; % end % edges(edge_index,:) = unit_data; % edge_index = edge_index + 1; %elseif strcmp(data_name, data_name_list{2}) % VERTEX_SE3:QUAT % data = textscan(fid, '%s %d %d %f %f %f %f %f %f %f %f %f\n'); % unit_data =[]; % for j=2:7 % unit_data = [unit_data data{j}]; % end % t_pose(vertex_index,:) = unit_data(1:3); % o_pose(vertex_index,:) = unit_data(4:6); % vertex_index = vertex_index + 1; % elseif strcmp(data_name{i}, data_name_list{4}) % EDGE_SE3:QUAT % unit_data =[]; % for j=2:31 % unit_data = [unit_data data{j}(i)]; % end % edges(edge_index,:) = unit_data; % edge_index = edge_index + 1; %end end fclose(fid); fod = fopen(output_file_name,'w'); pose_index = 0 ; for j=1:size(data{1},1) j for i=1:size(data{1},1) if strcmp(data{1}(i), data_name_list{1}) && data{1,2}(i) == pose_index unit_data=[]; for k=1:size(data,2) unit_data = [unit_data data{k}(i)]; end fprintf(fod,'%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',unit_data{1:30}); elseif strcmp(data{1}(i), data_name_list{2}) && data{1,2}(i) == (pose_index+1) unit_data=[]; for k=1:12 unit_data = [unit_data data{k}(i)]; end fprintf(fod,'%s %d %d %f %f %f %f %f %f %f %f %f\n',unit_data{1}, unit_data{2}-1, unit_data{3}-1, unit_data{4:12}); end end pose_index = pose_index + 1; end fclose(fod); %poses = [t_pose o_pose]; end
github
rising-turtle/slam_matlab-master
get_file_names.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/get_file_names.m
4,480
utf_8
a1283f12893ede7f6b3241f3fc754853
% Get file name, directory name and number of frame function [g2o_result_dir_name, isam_result_dir_name, vro_dir_name, dynamic_dir_name, toro_dir_name] = get_file_names(dir_index, dynamic_index) % Select Data Set vro_file_name_list ={'data/2d/manhattan3500/manhattanOlson3500.g2o', 'data/2d/intel/intel.g2o','data/3d/sphere/sphere_bignoise_vertex3.g2o','data/3d/garage/parking-garage.g2o','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/'}; isam_result_file_name_list ={'results/isam/2d/manhattanOlson3500.opt','results/isam/2d/intel.opt','results/isam/3d/sphere_bignoise_vertex3.opt','results/isam/3d/parking-garage.opt','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/','results/isam/3d/'}; g2o_result_file_name_list ={'results/g2o/2d/manhattanOlson3500.opt','results/g2o/2d/intel.opt','results/g2o/3d/sphere_bignoise_vertex3.opt','results/g2o/3d/parking-garage.opt','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/','results/g2o/3d/'}; toro_file_name_list={'2D/w10000-odom','3D/sphere_smallnoise','3D/sphere_mednoise','3D/sphere_bignoise','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/','data/3d/whitecane/'}; dynamic_name_list={'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'}; etas_name_list={'3th_straight','3th_swing','4th_straight','4th_swing','5th_straight','5th_swing'}; loops_name_list = {'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'}; kinect_tum_name_list = get_kinect_tum_dir_name(); loops2_name_list = get_loops2_filename(); sparse_feature_name_list = get_sparse_feature_filename(); swing_name_list = get_dir_name('swing'); %{'forward1','forward2','forward3','forward4','forward5','forward6'}; swing2_name_list = get_dir_name('swing2'); object_recognition_name_list = get_dir_name('object_recognition'); motive_name_list = get_dir_name('motive'); map_name_list=get_dir_name('map'); 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 = 3920; %1253; %5468; %2399; %1253; %2440; %829; %270; isam_result_dir_name = isam_result_file_name_list{dir_index}; g2o_result_dir_name = g2o_result_file_name_list{dir_index}; vro_dir_name = vro_file_name_list{dir_index}; toro_dir_name = toro_file_name_list{dir_index}; if dir_index == 5 dynamic_dir_name = dynamic_name_list{dynamic_index}; elseif dir_index == 6 dynamic_dir_name = etas_name_list{dynamic_index}; elseif dir_index == 7 dynamic_dir_name = loops_name_list{dynamic_index}; elseif dir_index == 8 dynamic_dir_name = kinect_tum_name_list{dynamic_index}; elseif dir_index == 9 || dir_index == 10 dynamic_dir_name = loops2_name_list{dynamic_index}; elseif dir_index == 11 dynamic_dir_name = sparse_feature_name_list{dynamic_index}; elseif dir_index == 12 dynamic_dir_name = swing_name_list{dynamic_index}; elseif dir_index == 13 dynamic_dir_name = swing2_name_list{dynamic_index}; elseif dir_index == 14 dynamic_dir_name = motive_name_list{dynamic_index}; elseif dir_index == 15 dynamic_dir_name = object_recognition_name_list{dynamic_index}; elseif dir_index == 16 dynamic_dir_name = map_name_list{dynamic_index}; else dynamic_dir_name = 'none'; end end
github
rising-turtle/slam_matlab-master
graphslam_addpath.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/graphslam_addpath.m
486
utf_8
9c4c53f3ba485b8dc6124acfb412717c
% Add the path for graph slam % % Author : Soonhac Hong ([email protected]) % Date : 10/16/12 function graphslam_addpath addpath('D:\Soonhac\SW\gtsam-toolbox-2.3.0-win64\toolbox'); addpath('D:\soonhac\SW\kdtree'); addpath('D:\soonhac\SW\LevenbergMarquardt'); addpath('D:\soonhac\SW\Localization'); addpath('D:\soonhac\SW\SIFT\sift-0.9.19-bin\sift'); addpath('D:\soonhac\SW\slamtoolbox\slamToolbox_11_09_08\FrameTransforms\Rotations'); addpath('D:\Soonhac\SW\plane_fitting_code'); end
github
rising-turtle/slam_matlab-master
Load_kinect_gt.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/Load_kinect_gt.m
1,147
utf_8
504b68074215f361df0680fcfb6e0467
% Load data from Kinect data % % 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 [gt rgbdslam rtime] = Load_kinect_gt(dm, dis) if nargin < 2 dis = 0; end t_load = tic; %dir_name={'rgbd_dataset_freiburg1_xyz'}; dir_name_list = get_kinect_tum_dir_name(); [file_name, err] = sprintf('E:/data/kinect_tum/%s/groundtruth.txt',dir_name_list{dm}); [time tx ty tz qx qy qz qw] = textread(file_name,'%f %f %f %f %f %f %f %f','commentstyle','shell'); prefix_name = strrep(dir_name_list{dm}, 'rgbd_dataset_',''); [rgbdslam_file_name, err] = sprintf('E:/data/kinect_tum/%s/%s-rgbdslam.txt',dir_name_list{dm},prefix_name); [stime stx sty stz sqx sqy sqz sqw] = textread(rgbdslam_file_name,'%f %f %f %f %f %f %f %f','commentstyle','shell'); rtime = toc(t_load); gt = [time tx ty tz qx qy qz qw]; rgbdslam = [stime stx sty stz sqx sqy sqz sqw]; if dis == 1 plot3(tx, ty, tz, 'r-'); hold on; plot3(stx, sty, stz, 'b:'); hold off; grid; xlabel('X'); ylabel('Y'); zlabel('Z'); end end
github
rising-turtle/slam_matlab-master
convert_vro_toro.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/convert_vro_toro.m
9,855
utf_8
e24f66fba9a7a135e5d337a5e0c131dc
% Conver the results of VRO to the vertex and edges for TORO % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function [vro_size] = convert_vro_toro(data_index, dynamic_index, nFrame, g2o_file_name, g2o_dir_name, feature_flag, index_interval, cmp_option, dense_index, sparse_interval, dis) if nargin < 9 dis = 0; end % Load the result of VRO disp('Load the result from VRO.'); [f_index, t_pose, o_pose, feature_points] = load_vro(data_index,dynamic_index, nFrame, feature_flag); % t_pose[mm], o_pose[degree] if isempty(feature_points) feature_flag = 0; end vro_size = size(t_pose,1) % Interploation for missing constraints %[f_index, t_pose, o_pose] = compensate_vro(f_index, t_pose, o_pose, cmp_option); % Interploation for missing constraints if feature_flag == 0 [f_index, t_pose, o_pose, feature_points] = compensate_vro(f_index, t_pose, o_pose, feature_points, cmp_option); else [f_index, t_pose, o_pose, feature_points(:,1:2)] = compensate_vro(f_index, t_pose, o_pose, feature_points(:,1:2), cmp_option); end % Convert the odometry and feature points to the global poses disp('Convert the VRO and feauture points w.r.t the glabal frame.'); %dense_index = 1; [pose_index, e_t_pose e_o_pose e_ftps] = convert_o2p(data_index, dynamic_index, f_index, t_pose, o_pose, feature_points, dense_index, sparse_interval); % Generate an index of feature points on the global poses disp('Generate an index of feature points on the global poses.'); g_fpts_edges = []; g_fpts = []; if feature_flag == 1 global_fpts_index = max(pose_index); for i=1:size(e_ftps,1) unit_cell = e_ftps{i,1}; for j = 1:size(unit_cell,1) if isempty(g_fpts_edges)/home/soonhac global_fpts_index = global_fpts_index + 1; new_index = global_fpts_index; g_fpts = [g_fpts; new_index unit_cell(j,2:4)]; else [duplication_index, duplication_flag] = check_duplication(g_fpts_edges(:,2:5), unit_cell(j,:)); if duplication_flag == 0 global_fpts_index = global_fpts_index + 1; new_index = global_fpts_index; g_fpts = [g_fpts; new_index unit_cell(j,2:4)]; else new_index = duplication_index; end end g_fpts_edges = [g_fpts_edges; unit_cell(j,1) new_index unit_cell(j,2:4)]; end end end % plot pose if dis == 1 if data_index == 10 || data_index == 11 gt_dis = 1; else gt_dis = 0; end plot_trajectory(e_t_pose, g_fpts, gt_dis, dynamic_index); end if feature_flag == 1 feature_pose_name = 'pose_feature'; else feature_pose_name = 'pose'; end % Write Vertexcies and Edges data_name_list = {'VERTEX2','EDGE2','VERTEX3','EDGE3'}; fpts_name_list ={'VERTEX_XY','EDGE_SE2_XY'}; g2o_file_name_final = sprintf('%s%s_%s_%s_%d.graph',g2o_file_name, g2o_dir_name, cmp_option, feature_pose_name, vro_size) g2o_fd = fopen(g2o_file_name_final,'w'); t_cov = 0.034; % [m] in SR4000 o_cov = 0.5 * pi / 180; % [rad] in SR4000 %cov_mat = [t_cov 0 0; 0 t_cov 0; 0 0 o_cov]; 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 = 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] %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 % % for i=1:size(e_o_pose,1) % temp_rot = euler_to_rot(e_o_pose(i,1), e_o_pose(i,2), e_o_pose(i,3)); % e_o_pose_quat(i,:) = R2q(temp_rot); % %e_o_pose_quat(i,:) = e2q([e_o_pose(i,2),e_o_pose(i,1),e_o_pose(i,3)]); % end if ~isempty(g_fpts) g_fpts(:,2:4) = g_fpts(:,2:4) / 1000; %[mm] -> [m] end if ~isempty(g_fpts_edges) g_fpts_edges(:,3:5) = g_fpts_edges(:,3:5) / 1000; % [mm] -> [m] end f_index(:,2) = f_index(:,2); % + index_interval; TODO : Generalize !!! for i=1:size(e_t_pose,1) %fprintf(g2o_fd,'%s %d %f %f %f\n', data_name_list{3}, pose_index(i)-1, e_t_pose(i,1:2), e_o_pose(i,3)); %if (max(t_pose(i,:)) >= t_cov *4) || (max(o_pose(i,:)) >= o_cov*4) fprintf(g2o_fd,'%s %d %f %f %f %f %f %f \n', data_name_list{3}, pose_index(i)-1, e_t_pose(i,1:3), e_o_pose(i,2), e_o_pose(i,1), e_o_pose(i,3)); %end end %TODO Change the format for 3D for i=1:size(f_index,1)-1 %if (max(t_pose(i,:)) >= t_cov *4) || (max(o_pose(i,:)) >= o_cov*4) %fprintf(g2o_fd,'%s %d %d %f %f %f %f %f %f %f %f %f\n', data_name_list{4}, f_index(i,1)-1, f_index(i,2)-1, t_pose(i,1), t_pose(i,2), o_pose(i,3), sqrt_info_mat(1,1), sqrt_info_mat(1,2), sqrt_info_mat(1,3), sqrt_info_mat(2,2), sqrt_info_mat(2,3), sqrt_info_mat(3,3)); %fprintf(g2o_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{4}, f_index(i,1)-1, f_index(i,2)-1, t_pose(i,1:3), 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)); fprintf(g2o_fd,'%s %d %d %f %f %f %f %f %f \n', data_name_list{4}, 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)); %end end if feature_flag == 1 for i=1:size(g_fpts,1) fprintf(g2o_fd,'%s %d %f %f \n', fpts_name_list{1}, g_fpts(i,1:3)); end for i=1:size(g_fpts_edges,1) fprintf(g2o_fd,'%s %d %d %f %f %f %f %f \n', fpts_name_list{2}, g_fpts_edges(i,1:4), t_covariance, 0, t_covariance); end end fclose(g2o_fd); end function [isExist previous_index] = getPreviousIndex(data_set,pts) isExist = 0; previous_index = 0; distance_threshold = 41; % [mm]; typical absolute accuracy + 3 * typical repeatibility of SR4000 = 20 + 3 * 7 = 41 for i=1:size(data_set,1) if data_set(i,1) > 0 && data_set(i,1) == pts(1) % Skip non-valid data distance = sqrt(sum((data_set(i,3:5)-pts(4:6)).^2)); if distance <= distance_threshold isExist = 1; previous_index = data_set(i,2); break; end end end end function plot_trajectory(e_pose, fpts, gt_dis, 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)]; 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.-','LineWidth',2); hold on; if gt_dis == 1 plot(gt_x,gt_y,'r-','LineWidth',2); end if ~isempty(fpts) plot(fpts(:,2),fpts(:,3),'gd'); if gt_dis == 1 legend('Estimated Pose','Estimated Truth','feature points'); else legend('Estimated Pose','feature points'); end else if gt_dis == 1 legend('Estimated Pose','Estimated Truth'); else legend('Estimated Pose'); end end xlabel('X [mm]'); ylabel('Y [mm]'); 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'); ylim([-18 6]); axis equal; hold off; figure; gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; gt_z = [0 0 0 0 0]; plot3(e_pose(:,1),e_pose(:,2),e_pose(:,3),'bo-'); hold on; plot3(gt_x,gt_y,gt_z,'r-','LineWidth',2); if ~isempty(fpts) plot3(fpts(:,2),fpts(:,3),fpts(:,4),'gd'); legend('Estimated Pose','Estimated Truth','feature points'); else legend('Estimated Pose','Estimated Truth'); end xlabel('X [mm]'); ylabel('Y [mm]'); zlabel('Z [mm]'); 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'); 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
get_timestamp_kinect_tum.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/get_timestamp_kinect_tum.m
568
utf_8
fd152c23df0229d3e879a91f12ea7ed7
% Get time stamp of depth image in kinect_tum dataset % % Author : Soonhac Hong ([email protected]) % Date : 12/20/12 function [time_stamp] = get_timestamp_kinect_tum(dm,j) dir_name = get_kinect_tum_dir_name(); [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',file_list{j}); time_stamp = str2num(strrep(file_name, '.png','')); end
github
rising-turtle/slam_matlab-master
analyze_pose_std.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/analyze_pose_std.m
2,255
utf_8
d715dbcac4fa5d655d84870c9c2162d4
% Analyze standard deviation of motion estimation by VRO, VRO_ICP. % % Author : Soonhac Hong ([email protected]) % Date : 3/1/13 function [median_pose_std, std_pose_std, unique_step, step1_pose_std_total, step1_pose_std] = analyze_pose_std(f_index, pose_std, verbosity) step = abs(f_index(:,1)-f_index(:,2)); unique_step = unique(step); plot_colors={'gd','k*','md','rs','bv','r+','m*','g^','b<','r>','mp','gh'}; title_list = {'ry','rx','rz','x','y','z'}; median_pose_std = zeros(size(unique_step,1),6); std_pose_std = zeros(size(unique_step,1),6); % Show all standard deviation for k=1:6 % if verbosity == 1 % figure; % end for i=1:size(unique_step,1) step_idx = find(step == unique_step(i)); % if verbosity == 1 % if k < 4 % plot(pose_std(step_idx,k).*180./pi,plot_colors{i}); % else % plot(pose_std(step_idx,k),plot_colors{i}); % end % hold on; % end median_pose_std(i,k) = median(pose_std(step_idx,k)); std_pose_std(i,k) = std(pose_std(step_idx,k)); end if verbosity == 1 %hold off; %title(title_list{k}); %legend('s1','s2','s3','s4','s5'); figure; %plot(median_pose_std(:,k),'o-'); if k < 4 errorbar(median_pose_std(:,k).*180./pi,std_pose_std(:,k).*180./pi,'bo-'); ylabel('[degree]'); else errorbar(median_pose_std(:,k),std_pose_std(:,k),'bo-'); ylabel('[m]'); end title(title_list{k}); end end %Save step1 pose std step1_pose_std_total=[]; step1_pose_std=[]; step1_pose_std_temp=[]; for i=1:size(step,1) if step(i) == 1 step1_pose_std_total(i,:) = pose_std(i,:); step1_pose_std_temp = pose_std(i,:); step1_pose_std = [step1_pose_std; pose_std(i,:)]; else if ~isempty(step1_pose_std_temp) step1_pose_std_total(i,:) = step1_pose_std_temp; else step1_pose_std_total(i,:) = pose_std(i,:); end end end % % plot step1 % figure(3); % plot(step1_pose_std_debug(:,1:3)); % legend('x','y','z'); % grid; % figure(4); % plot(step1_pose_std_debug(:,4:6).*(180/pi)); % legend('rx','ry','rz'); % grid; end
github
rising-turtle/slam_matlab-master
convert_vro_g2o.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/convert_vro_g2o.m
7,261
utf_8
c5b3ce08193f250cd2c7f03abd91f261
% Conver the results of VRO to the vertex and edges for g2o % % Author : Soonhac Hong ([email protected]) % Date : 2/22/12 function [vro_size] = convert_vro_g2o(data_index, dynamic_index, nFrame, g2o_file_name, g2o_dir_name, feature_flag, index_interval, cmp_option, dense_index, sparse_interval, dis) if nargin < 9 dis = 0; end % Load the result of VRO disp('Load the result from VRO.'); [f_index, t_pose, o_pose, feature_points] = load_vro(data_index,dynamic_index, nFrame, feature_flag); % t_pose[mm], o_pose[degree] 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] = compensate_vro(f_index, t_pose, o_pose, feature_points, cmp_option); else [f_index, t_pose, o_pose, feature_points(:,1:2)] = compensate_vro(f_index, t_pose, o_pose, feature_points(:,1:2), cmp_option); end % Convert the odometry and feature points to the global poses disp('Convert the VRO and feauture points w.r.t the glabal frame.'); %dense_index = 1; [pose_index, e_t_pose, e_o_pose, e_ftps] = convert_o2p(data_index, dynamic_index, f_index, t_pose, o_pose, feature_points, dense_index, sparse_interval); %convert_o2p(f_index, t_pose, o_pose, feature_points, dense_index); % e_t_pose [mm] % e_o_pose [radian] % Generate an index of feature points on the global poses disp('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); else g_fpts=[]; g_fpts_edges=[]; end % plot pose if dis == 1 if data_index == 10 gt_dis = 1; else gt_dis = 0; end plot_trajectory(e_t_pose, g_fpts, gt_dis); end % Write Vertexcies and Edges if feature_flag == 1 feature_pose_name = 'pose_feature'; else feature_pose_name = 'pose'; end data_name_list = {'VERTEX_SE2','EDGE_SE2','VERTEX_SE3:QUAT','EDGE_SE3:QUAT'}; fpts_name_list ={'VERTEX_XY','EDGE_SE2_XY'}; g2o_file_name_final = sprintf('%s%s_%s_%s_%d.g2o',g2o_file_name, g2o_dir_name, cmp_option, feature_pose_name, vro_size) g2o_fd = fopen(g2o_file_name_final,'w'); t_cov = 0.034; % [m] in SR4000 o_cov = 0.5 * pi / 180; % [rad] in SR4000 %cov_mat = [t_cov 0 0; 0 t_cov 0; 0 0 o_cov]; 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 = 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] e_o_pose = e_o_pose * 180 /pi; % [radian] -> [degree] %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)); % input(ry, rx, rz) [degree] 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 for i=1:size(e_o_pose,1) temp_rot = euler_to_rot(e_o_pose(i,1), e_o_pose(i,2), e_o_pose(i,3)); % input(ry, rx, rz) [degree] e_o_pose_quat(i,:) = R2q(temp_rot); %e_o_pose_quat(i,:) = e2q([e_o_pose(i,2),e_o_pose(i,1),e_o_pose(i,3)]); end if ~isempty(g_fpts) g_fpts(:,2:4) = g_fpts(:,2:4) / 1000; %[mm] -> [m] end if ~isempty(g_fpts_edges) g_fpts_edges(:,3:5) = g_fpts_edges(:,3:5) / 1000; % [mm] -> [m] end f_index(:,2) = f_index(:,2) + index_interval; for i=1:size(e_t_pose,1) %fprintf(g2o_fd,'%s %d %f %f %f\n', data_name_list{3}, pose_index(i)-1, e_t_pose(i,1:2), e_o_pose(i,3)); %if (max(t_pose(i,:)) >= t_cov *4) || (max(o_pose(i,:)) >= o_cov*4) %fprintf(g2o_fd,'%s %d %f %f %f %f %f %f %f\n', data_name_list{3}, pose_index(i)-1, e_t_pose(i,1:3), e_o_pose_quat(i,2), e_o_pose_quat(i,1), e_o_pose_quat(i,3)); fprintf(g2o_fd,'%s %d %f %f %f %f %f %f %f\n', data_name_list{3}, pose_index(i)-1, e_t_pose(i,1:3), e_o_pose_quat(i,:)); %end end for i=1:size(f_index,1)-1 %vro_size-1 %if (max(t_pose(i,:)) >= t_cov *4) || (max(o_pose(i,:)) >= o_cov*4) %fprintf(g2o_fd,'%s %d %d %f %f %f %f %f %f %f %f %f\n', data_name_list{4}, f_index(i,1)-1, f_index(i,2)-1, t_pose(i,1), t_pose(i,2), o_pose(i,3), sqrt_info_mat(1,1), sqrt_info_mat(1,2), sqrt_info_mat(1,3), sqrt_info_mat(2,2), sqrt_info_mat(2,3), sqrt_info_mat(3,3)); fprintf(g2o_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 %f\n', data_name_list{4}, f_index(i,1)-1, f_index(i,2)-1, t_pose(i,1:3), o_pose_quat(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 end if feature_flag == 1 for i=1:size(g_fpts,1) fprintf(g2o_fd,'%s %d %f %f \n', fpts_name_list{1}, g_fpts(i,1:3)); end for i=1:size(g_fpts_edges,1) fprintf(g2o_fd,'%s %d %d %f %f %f %f %f \n', fpts_name_list{2}, g_fpts_edges(i,1:4), t_covariance, 0, t_covariance); end end fclose(g2o_fd); end function [isExist previous_index] = getPreviousIndex(data_set,pts) isExist = 0; previous_index = 0; distance_threshold = 41; % [mm]; typical absolute accuracy + 3 * typical repeatibility of SR4000 = 20 + 3 * 7 = 41 for i=1:size(data_set,1) if data_set(i,1) > 0 && data_set(i,1) == pts(1) % Skip non-valid data distance = sqrt(sum((data_set(i,3:5)-pts(4:6)).^2)); if distance <= distance_threshold isExist = 1; previous_index = data_set(i,2); break; end end end end function plot_trajectory(e_pose, fpts, gt_dis) figure; gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; plot(e_pose(:,1),e_pose(:,2),'bo-'); hold on; if gt_dis == 1 plot(gt_x,gt_y,'r-','LineWidth',2); end if ~isempty(fpts) plot(fpts(:,2),fpts(:,3),'gd'); if gt_dis == 1 legend('Estimated Pose','Estimated Truth','feature points'); else legend('Estimated Pose','feature points'); end else if gt_dis == 1 legend('Estimated Pose','Estimated Truth'); else legend('Estimated Pose'); end end xlabel('X [mm]'); ylabel('Y [mm]'); 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'); hold off; figure; gt_x = [0 0 2135 2135 0]; gt_y = [0 1220 1220 0 0]; gt_z = [0 0 0 0 0]; plot3(e_pose(:,1),e_pose(:,2),e_pose(:,3),'bo-'); hold on; plot3(gt_x,gt_y,gt_z,'r-','LineWidth',2); if ~isempty(fpts) plot3(fpts(:,2),fpts(:,3),fpts(:,4),'gd'); legend('Estimated Pose','Estimated Truth','feature points'); else legend('Estimated Pose','Estimated Truth'); end xlabel('X [mm]'); ylabel('Y [mm]'); zlabel('Z [mm]'); 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'); end
github
rising-turtle/slam_matlab-master
load_rossba.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/load_rossba.m
5,851
utf_8
90b136e61c9c391804c988e74286a1b7
% Load input and output files of ROS SBA (http://www.ros.org/wiki/sba/Tutorials/IntroductionToSBA) % % Author : Soonhac Hong ([email protected]) % Date : 2/28/13 % Note : Camera pose, T, in input files and output files of ROS-SBA is inverse % transformaton from camera N to camera N+1. In other words, % camera0=inv(T)*camera1. So to speak, camera1 = T * camera0 function [camera_pose, camera_parameters, landmark_position, landmark_projection] = load_rossba(file_name) 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'); fid = fopen(file_name); if fid < 0 error(['load2D: Cannot open file ' 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); camera_pose_idx = 1; landmark_index=1; landmark_projection=[]; trans = [0 0 0]; rot = e2R([pi(), 0, 0]); % rotate 180 around x-axis from bundler frame to SBA frame; bundler_T = [rot trans'; 0 0 0 1]; for i=1:N line_i=lines{i}; %line_data = textscan(line_i,'%s','delimiter',' '); if i>=2 %line_data = str2num(line_data{1}); line_data = textscan(line_i,'%f %f %f',1); end if i==2 camera_index_total = line_data{1}; landmark_index_total = line_data{2}; elseif i>2 if camera_pose_idx <= camera_index_total % camera pose unit_idx = mod((i - 3),5); if unit_idx == 0 camera_parameters(camera_pose_idx,:)=[line_data{1}, line_data{2}, line_data{3}]; elseif unit_idx >=1 && unit_idx <=3 % rotation matrix unit_rot(unit_idx,:)=[line_data{1}, line_data{2}, line_data{3}]; elseif unit_idx == 4 %translation unit_trans = [line_data{1}, line_data{2}, line_data{3}]; T=[unit_rot unit_trans'; 0 0 0 1]; %T= bundler_T * inv(T); % Convert transform from ROS-SBA convention to VRO convention !!!!! T = inv(bundler_T * T); % Convert transform from ROS-SBA convention to VRO convention !!!!! unit_rot=T(1:3,1:3); unit_trans=T(1:3,4); [e] = R2e(unit_rot); camera_pose(camera_pose_idx,:) = [unit_trans', e(1), e(2), e(3) ]; camera_pose_idx = camera_pose_idx + 1; unit_rot=[]; % elseif unit_idx == 0 && i>=5 end else % landmark pose % unit_idx = mod((i-(3+camera_index_total*5)), 3); % if unit_idx == 0 % landmark_pose(landmark_idx,:) = [line_data{1}, line_data{2}, line_data{3}]; % landmark_idx = landmark_idx + 1; % end index_modulus = mod(i-(camera_index_total*5 + 2), 3); switch index_modulus case 1 % position v = textscan(line_i,'%f %f %f',1); landmark_position(landmark_index,:) = [v{1},v{2},v{3}]; case 2 % color v = textscan(line_i,'%d %d %d',1); landmark_color(landmark_index,:) = [v{1},v{2},v{3}]; case 0 % projected positions v = textscan(line_i,'%f','delimiter',' '); v = v{1}; for k=1:v(1) landmark_projection = [landmark_projection; v(2+(k-1)*4),v(3+(k-1)*4),v(4+(k-1)*4), v(5+(k-1)*4)]; end landmark_index = landmark_index + 1; end end end end % if nargin < 4, % successive=false; % end % % fid = fopen(file_name); % if fid < 0 % error(['load2D: Cannot open file ' file_name]); % end % % % scan all lines into a cell array % columns=textscan(fid,'%s','delimiter','\n'); % fclose(fid); % lines = columns{1}; % % camera_index = 1; % landmark_index = 1; % landmark_projection=[]; % transform = {}; % landmark_position=[]; % landmark_color=[]; % for i=1:size(lines,1) % line_i=lines{i}; % if i == 2 % v = textscan(line_i,'%d %d',1); % nCamera=v{1}; % nLandmarks=v{2}; % elseif i > 2 && i <= (nCamera*5 + 2) % camera pose % v = textscan(line_i,'%f %f %f',1); % index_modulus = mod(i-2,5); % switch index_modulus % case 1 % camera_parameters(camera_index,:)=[v{1},v{2},v{3}]; % case {2,3,4} % rotation_matrix(index_modulus-1,:) = [v{1},v{2},v{3}]; % case 0 % transform{camera_index} = [rotation_matrix, [v{1},v{2},v{3}]'; 0 0 0 1]; % camera_index = camera_index + 1; % end % elseif i >2 %landmark position % index_modulus = mod(i-(nCamera*5 + 2), 3); % switch index_modulus % case 1 % position % v = textscan(line_i,'%f %f %f',1); % landmark_position(landmark_index,:) = [v{1},v{2},v{3}]; % case 2 % color % v = textscan(line_i,'%d %d %d',1); % landmark_color(landmark_index,:) = [v{1},v{2},v{3}]; % case 0 % projected positions % v = textscan(line_i,'%f','delimiter',' '); % v = v{1}; % for k=1:v(1) % landmark_projection = [landmark_projection; v(2+(k-1)*4),v(3+(k-1)*4),v(4+(k-1)*4), v(5+(k-1)*4)]; % end % landmark_index = landmark_index + 1; % end % end % end % % %% Convert data to the VRO convention % camera_poses = []; % x, y, z, rx, ry, rz % for i=1:size(transform,2) % unit_transform = transform{i}; % camera_poses(i,:) = [unit_transform(1:3,4)' R2e(unit_transform(1:3,1:3))']; % end end
github
rising-turtle/slam_matlab-master
Convert_trajectory_threshold.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/Convert_trajectory_threshold.m
1,762
utf_8
72bcdd34eefa4c383e3ba6d58d35b109
% Convert the color of a trajectory in the polygon file format (*.ply) for Meshlab % % Input parameters : % input_file_name : Input file name in the polygon file format % output_file_name : Output file name in the polygon file format % threshold : Cut-off threshold of intensity values % Usage :Convert_trajectory_color('pm_trajectory.ply', 'pm_trajectory_new_color.ply', [0,0,255]) % % Author : Soonhac Hong ([email protected]) % Date : 5/16/14 function Convert_trajectory_threshold(input_file_name, output_file_name, threshold) %% Load an input file fid = fopen(input_file_name); if fid < 0 error(['Cannot open file ' input_file_name]); end % scan all lines into a cell array columns=textscan(fid,'%s','delimiter','\n'); lines=columns{1}; fclose(fid); %% Convert the color of a trajectory new_data=[]; for i=1:size(lines,1) i line_i=lines{i}; if i > 12 % check intensity data v = textscan(line_i,'%f %f %f %d %d %d',1); if v{4} > threshold new_data=[new_data; [v{1},v{2},v{3},double(v{4}),double(v{5}),double(v{6})]]; %fprintf(fd,'%f %f %f %d %d %d\n',v{1},v{2},v{3}, target_color); end end end %% Write data ply_headers={'ply','format ascii 1.0','comment Created with XYZRGB_to_PLY', 'element_vertex_dummy', 'property float x', 'property float y','property float z','property uchar red','property uchar green','property uchar blue','end_header'}; nply_data = size(new_data,1) element_vertex_n = sprintf('element vertex %d',nply_data); ply_headers{4} = element_vertex_n; fd = fopen(output_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',new_data(i,:)); end fclose(fd); end
github
rising-turtle/slam_matlab-master
run_pose_graph_optimization.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/run_pose_graph_optimization.m
1,292
utf_8
1836ed46d2469d0f4edec264b5926f13
% Run pose graph optimization % % Author : Soonhac Hong ([email protected]) % History : % 3/26/14 : Created function [result, graph, initial, h_global, location_file_index, location_info_history]=run_pose_graph_optimization(vro_result, vro_pose_std, graph, initial, h_global, dis, location_flag, location_file_index, location_info_history) import gtsam.* t = gtsam.Point3(0, 0, 0); if isempty(h_global) h_global = get_global_transformation_single('smart_cane'); rot = h_global(1:3,1:3); R = gtsam.Rot3(rot); origin= gtsam.Pose3(R,t); initial.insert(0,origin); end pgc_t=tic; [graph,initial] = construct_pose_graph(vro_result, vro_pose_std, graph, initial); first = initial.at(0); pgc_ct =toc(pgc_t) graph.add(NonlinearEqualityPose3(0, first)); gtsam_t=tic; optimizer = LevenbergMarquardtOptimizer(graph, initial); result = optimizer.optimizeSafely(); gtsam_ct =toc(gtsam_t) % Show the results in the plot and generate location information if dis==true [location_file_index, location_info_history]=plot_graph_initial_result(initial, result, location_flag, location_file_index, location_info_history); elseif location_flag == true [location_info, location_file_index] = generate_location_info(result,[], location_file_index); % for finding rooms end end
github
rising-turtle/slam_matlab-master
get_global_transformation.m
.m
slam_matlab-master/ground_truth_zh/GraphSLAM/get_global_transformation.m
11,998
utf_8
57e044f4869271c0316b4c195dadbd53
% Get global transformation for each data set % % Author : Soonhac Hong ([email protected]) % Date : 10/22/12 function [h_global] = get_global_transformation(data_index, dynamic_index, isgframe) addpath('..\slamtoolbox\slamToolbox_11_09_08\FrameTransforms\Rotations'); % rx, ry, rz : [degree] % tx, ty, tz : [mm] rx=0; ry=0; rz=0; tx=0; ty=0; tz=0; switch data_index case 10 % square switch dynamic_index case 16 %h_global = [euler_to_rot(0, -15.4, 0) [0 0 0]'; 0 0 0 1]; % square_700 rx = -15.4; end case 11 % etas switch dynamic_index case 1 %h_global = [euler_to_rot(0, -36.3, 0) [0 0 0]'; 0 0 0 1]; % etas %rx = -36.3; rx = -29.5089; ry = 1.1837; rz=3.6372; case 3 rx = -28.9278; ry = 1.1894; rz=0.8985; case 5 rx = -29.2181; ry = 1.1830; rz=1.8845; end case 12 % loops switch dynamic_index case 2 %h_global = [euler_to_rot(1.23, -25.6, 3.51) [0 0 0]'; 0 0 0 1]; % loops_2 rx=-25.6; ry=1.23; rz=3.51; case 3 %h_global =[euler_to_rot(1.2670, -24.3316, 4.6656) [0 0 0]'; 0 0 0 1]; %loops_3 rx=-24.3316; ry=1.2670; rz=0; %4.6656; case 13 rx=-25.6109; ry=1.2418; rx=3.8448 end case 13 % kinect_tum switch dynamic_index case 2 % start image : 13050033527.670034 % Groundtruth : 1305033527.6662 1.4906 -1.1681 0.6610 0.8959 0.0713 -0.0460 -0.4361 init_qauterion = [0.8959, 0.0713, -0.046, -0.4361]; % temp_rot = q2R(init_qauterion); % [r1, r2, r3] = rot_to_euler(temp_rot); % r2d = 180 / pi; % temp_rot = euler_to_rot(r2*r2d, r1*r2d, r3*r2d); temp_r = q2e(init_qauterion) * 180 / pi; %temp_rot = euler_to_rot(temp_r(2), temp_r(1), temp_r(3)); % degree %temp_rot = euler_to_rot(45, -45, 90) * temp_rot ; %[temp_r(2) temp_r(1) temp_r(3)] = rot_to_euler(temp_rot); temp_trans = [1.4906 -1.1681 0.661]*1000; %temp_r = temp_r * 180 / pi; rx = temp_r(1); ry = temp_r(2); rz = temp_r(3); %rx =0; ry =0; rz=0; tx = temp_trans(1); ty = temp_trans(2); tz = temp_trans(3); end case {14,15} % loops2, amir_vro switch dynamic_index case 1 %h_global =[euler_to_rot(1.2670, -24.3316, 4.6656) [0 0 0]'; 0 0 0 1]; %loops_3 rx=-24.4985419798496; ry=1.26190320102629; rz=4.69088809909393; %4.6656; case 2 rx=-23.3420; ry=1.2739; rz=4.3772; case 3 rx=-24.5234; ry=1.2565; rz=4.2682; case 4 rx=-24.2726; ry=1.2606; rz=2.7462; case 5 rx=-26.6191; ry=1.2173; rz=5.0601; %2.7462; case 6 rx=-25.7422; ry=1.2396; rz=3.0821; case 7 rx=-24.6791; ry=1.2562; rz=4.1917; %3.0821; case 8 %h_global =[euler_to_rot(1.2670, -24.3316, 4.6656) [0 0 0]'; 0 0 0 1]; %loops_3 rx=-23.8464; ry=1.2721; rz= 3.7964; %3.75437022813459; %init_qauterion = [0.977813222516827,-0.206522692608165,0.00392574917797234,0.0348463456121639]; %temp_r = q2e(init_qauterion) * 180 / pi; %rx = temp_r(1); ry = temp_r(2); rz = temp_r(3); case 9 rx=-25.6806; ry=1.2383; rz=3.4203; case 10 rx=-25.1216960394087; ry=1.25311495911881; rz=-0.909688742543562; case 11 %h_global = [euler_to_rot(1.23, -25.6, 3.51) [0 0 0]'; 0 0 0 1]; % loops_2 %rx=-25.6; ry=1.23; rz=3.51; rx=-33.7709; ry=1.0903; rz=3.0738; case 12 % same as exp 7 rx=-24.6791; ry=1.2562; rz=4.1917; %3.0821; end case 16 % sparse_feature switch dynamic_index case 1 rx=-29.9267; ry=1.1978; rz=0; %-2.6385; %4.69088809909393; %4.6656; case 2 rx=-28.7386; ry=1.2247; rz=0.8001; %-2.6385; %4.69088809909393; %4.6656; case 3 rx=-31.1218; ry=1.1713; rz=-1.7365; case 4 rx=-29.3799; ry=1.2133; rz=-2.4075; case {5,6,7,8} rx = -39.1930; ry = 1.0134; rz = -1.2122; case {9, 10, 11} rx = -37.1533; ry = 1.0455; rz = -3.0266; case {12,16} rx = -38.3570; ry = 1.0315; rz = -0.3114; case 13 rx=-28.3021; ry=1.2357; rz=-1.3391; case 14 rx=-29.1073; ry=1.2133; rz=-0.5520; end case {17,18} % swing switch dynamic_index case 1 rx=-32.2179; ry=1.1567; rz=-1.1344; case 2 rx=-28.6379; ry=1.2207; rz=-1.5099; case 3 rx=-33.3490; ry=1.1279; rz=-3.1225; case 4 rx=-31.0073; ry=1.1770; rz=-0.6052; case 5 rx=-31.7611; ry=1.1627; rz=-0.9156; case 7 rx=-19.2560; ry=0.8450; rz=0.5809; case 8 rx=-17.5219; ry=0.8546; rz=-4.5522; case 9 rx=-17.2286; ry=0.8616; rz=-3.4105; case 10 rx=-18.1945; ry=0.8501; rz=1.4029; case 11 rx=-18.2734; ry=0.8556; rz=0.2481; case 12 rx=-24.4356; ry=0.7918; rz=-0.9333; case 13 rx=-17.2649; ry=0.8549; rz=-2.8848; case 14 rx=-20.1519; ry=0.8284; rz=-1.3661; case 15 rx=-20.5691; ry=0.8302; rz=-0.7713; case 16 rx=-19.8892; ry=0.8389; rz=-1.3603; case 17 rx=-24.4211; ry=0.7959; rz=-3.0972; case 18 rx=-21.7207; ry=0.8163; rz=-4.3600; case 19 rx=-19.3202; ry=0.8454; rz=-2.7863; case 20 rx=-20.2662; ry=0.8354; rz=-2.5763; case 21 rx=-19.5310; ry=0.8403; rz=-1.9310; case 22 rx=-18.3081; ry=0.8536; rz=-4.6978; case 23 rx=-16.7653; ry=0.8678; rz=-4.2483; case 24 rx=-16.4797; ry=0.8697; rz=-2.3778; case 25 rx=-17.3060; ry=0.8587; rz=-3.1753; case 26 rx=-16.9306; ry=0.8576; rz=-2.6512; end case {19} % motive switch dynamic_index case 1 rx=-22.2924; ry=0.8198; rz=-4.3367; case 2 rx=-23.9217; ry=0.7990; rz=-3.1450; case 11 rx=-17.5025; ry=1.3989; rz=-1.5120; case 12 rx=-17.1856; ry=1.4018; rz=-0.3795; case 13 rx=-16.8428; ry=0.8657; rz=-4.1148; case 15 rx=-20.3861; ry=0.8323; rz=-4.4565; case 16 rx=-21.2226; ry=0.8261; rz=-6.5253; case 17 rx=-19.2100; ry=1.3724; rz=-4.0953; case 18 rx=-18.4614; ry=1.3822; rz=-2.2221; case 19 rx=-14.2685; ry=0.8810; rz=-2.4514; case 20 rx=-14.8030; ry=0.8806; rz=-3.6865; case 21 rx=-18.6913; ry=0.8436; rz=-1.3773; case 22 rx=-15.3041; ry=0.8815; rz=0.3623; case 23 %rx=-14.6923; ry=0.8813; rz=0.5994; rx=-15.8020; ry=0.8704; rz=-1.0940; case 24 %rx=-13.9262; ry=0.8867; rz=2.9371; rx=-13.4739; ry=0.8915; rz=-3.8607; case 25 %rx=-12.5003; ry=0.8973; rz=-1.6229; rx=-12.5852; ry=0.8966; rz=-1.7487; case 26 %rx=-13.1931; ry=0.8922; rz=0.3750; rx=-13.1931; ry=0.8922; rz=0.3750; case 27 rx=-13.7715; ry=0.8868; rz=0.7914; case 28 rx=-14.2207; ry=0.8836; rz=-1.8911; case 29 rx=-13.4205; ry=0.8920; rz=-1.8912; case 30 rx=-15.2320; ry=0.8793; rz=-0.8757; case 31 rx=-15.8020; ry=0.8704; rz=-1.0940; case 32 rx=-18.3082; ry=1.3832; rz=2.6882; case 33 rx=-18.3023; ry=1.3870; rz=-0.4907; case 34 rx=-16.3416; ry=1.4141; rz=-1.3016; case 35 rx=-15.9030; ry=1.4182; rz=-2.7589; case 36 rx=-18.8863; ry=1.3755; rz=-4.6635; case 37 rx=-15.9639; ry=1.4180; rz=0.1582; end case {20} % object_recognition switch dynamic_index case 1 rx=-37.7656; ry=1.0435; rz=-5.2416; case 2 rx=-9.4696; ry=0.9351; rz=8.0194; case 3 rx=-49.0312; ry=0.4693; rz=17.9271; case 4 rx = -102.3278; ry=-0.4342; rz=-4.9235; case 5 rx=-36.4384; ry=1.0755; rz=22.0853; case 6 rx=-36.8751; ry=1.0886; rz=24.7719; case 7 rx = -26.0697; ry=1.2667; rz=3.3011; case 8 rx = -34.3278; ry=0.6732; rz=3.7436; case 9 rx = -28.8132; ry=0.7380; rz=10.7045; case 10 rx = -35.7148; ry=0.6569; rz=-10.9565; case 11 rx = -27.3853; ry=0.7568; rz=-7.5140; end case {21} % map switch dynamic_index case 2 rx=-20.9872; ry=0.8237; rz= -1.6569; case 3 rx=-21.9661; ry=0.8124; rz=1.3211; case 4 rx=-20.0099; ry=0.8344; rz=3.4412; case 5 rx=-20.7988; ry=0.8285; rz=-1.4896; case 6 %rx=-20.8341; ry=0.8281; rz=-1.5208; rx=-17.5434; ry=1.4023; rz=-0.4495; case 7 rx=-19.7766; ry=1.3672; rz=-2.9528; case 8 rx=-20.7362; ry=1.3549; rz=-3.8060; case 9 rx=-17.1903; ry=1.4010; rz=0.2855; end end %h_global_tf = [euler_to_rot(0, 90, 0) [0 0 0]'; 0 0 0 1]; if strcmp(isgframe, 'gframe') h_global = [e2R([rx*pi/180, ry*pi/180, rz*pi/180]) [tx ty tz]'; 0 0 0 1]; else %h_global = [euler_to_rot(ry, rx, rz) [tx ty tz]'; 0 0 0 1]; h_global = [euler_to_rot(rz, rx, ry) [tx ty tz]'; 0 0 0 1]; end %h_global = h_global * h_global_tf; %h_global = [euler_to_rot(0, 0, 15) [tx ty tz]'; 0 0 0 1]; %h_global = [euler_to_rot(rz, rx, ry) [tx ty tz]'; 0 0 0 1]; %h_global = [euler_to_rot(0, 0, 0) [0 0 0]'; 0 0 0 1]; %h_global = [euler_to_rot(0, -23.8, 0) [0 0 0]'; 0 0 0 1]; % square_1000 %init_qauterion = [0.8959, 0.0695, -0.0461, -0.4364]; %temp_rot = q2R(init_qauterion); %[r1, r2, r3] = rot_to_euler(temp_rot); %r2d = 180 / pi; %temp_rot = euler_to_rot(r2*r2d, r1*r2d, r3*r2d); %temp_r = q2v(init_qauterion) * 180 / pi; %temp_rot = euler_to_rot(temp_r(2), temp_r(1), temp_r(3)); % degree %temp_trans = [1.4908 -1.1707 0.6603]*1000; %h_global = [temp_rot temp_trans'; 0 0 0 1]; % kinect_tum %h_global_temp = [euler_to_rot(90, 0, 90) [0 0 0]'; 0 0 0 1]; % ????? %h_global_temp = [[1 0 0; 0 0 -1; 0 1 0] [0 0 0]'; 0 0 0 1]; %h_global = h_global * h_global_temp; %h_global = [euler_to_rot(0, 0, 0) temp_trans'; 0 0 0 1]; end