-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #553 from Breakthru/kinfu_camera_pose
pcl_kinfu_app saves camera pose to csv file.
- Loading branch information
Showing
3 changed files
with
221 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Software License Agreement (BSD License) | ||
* | ||
* Point Cloud Library (PCL) - www.pointclouds.org | ||
* Copyright (c) 2014-, Open Perception, Inc. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above | ||
* copyright notice, this list of conditions and the following | ||
* disclaimer in the documentation and/or other materials provided | ||
* with the distribution. | ||
* * Neither the name of the copyright holder(s) nor the names of its | ||
* contributors may be used to endorse or promote products derived | ||
* from this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* Author: Marco Paladini <marco.paladini@ocado.com> | ||
* Date: March 2014 | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <Eigen/Core> | ||
#include <Eigen/Geometry> | ||
#include <fstream> | ||
|
||
/** | ||
* @brief The CameraPoseProcessor class is an interface to extract | ||
* camera pose data generated by the pcl_kinfu_app program. | ||
* Use the CameraPoseWriter implementation if writing the camera | ||
* pose to a file is all you need, or provide an alternative implementation. | ||
*/ | ||
class CameraPoseProcessor | ||
{ | ||
public: | ||
virtual ~CameraPoseProcessor () {} | ||
|
||
/// process the camera pose, this method is called at every frame. | ||
virtual void | ||
processPose (const Eigen::Affine3f &pose)=0; | ||
}; | ||
|
||
/** | ||
* @brief CameraPoseWriter writes all camera poses computed by | ||
* the KinfuTracker to a file on disk. | ||
* | ||
*/ | ||
class CameraPoseWriter : public CameraPoseProcessor | ||
{ | ||
std::string output_filename_; | ||
std::ofstream out_stream_; | ||
public: | ||
/** | ||
* @param output_filename name of file to write | ||
*/ | ||
CameraPoseWriter (std::string output_filename) : | ||
output_filename_ (output_filename) | ||
{ | ||
out_stream_.open (output_filename_.c_str () ); | ||
} | ||
|
||
~CameraPoseWriter () | ||
{ | ||
if (out_stream_.is_open ()) | ||
{ | ||
out_stream_.close (); | ||
std::cout << "wrote camera poses to file " << output_filename_ << std::endl; | ||
} | ||
} | ||
|
||
void | ||
processPose (const Eigen::Affine3f &pose) | ||
{ | ||
if (out_stream_.good ()) | ||
{ | ||
// convert 3x4 affine transformation to quaternion and write to file | ||
Eigen::Quaternionf q (pose.rotation ()); | ||
Eigen::Vector3f t (pose.translation ()); | ||
// write translation , quaternion in a row | ||
out_stream_ << t[0] << "," << t[1] << "," << t[2] | ||
<< "," << q.w () << "," << q.x () | ||
<< "," << q.y ()<< "," << q.z () << std::endl; | ||
} | ||
} | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
% Copyright (c) 2014-, Open Perception, Inc. | ||
% All rights reserved. | ||
% | ||
% Redistribution and use in source and binary forms, with or without | ||
% modification, are permitted provided that the following conditions | ||
% are met: | ||
% | ||
% * Redistributions of source code must retain the above copyright | ||
% notice, this list of conditions and the following disclaimer. | ||
% * Redistributions in binary form must reproduce the above | ||
% copyright notice, this list of conditions and the following | ||
% disclaimer in the documentation and/or other materials provided | ||
% with the distribution. | ||
% * Neither the name of the copyright holder(s) nor the names of its | ||
% contributors may be used to endorse or promote products derived | ||
% from this software without specific prior written permission. | ||
% | ||
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
% "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
% LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
% FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
% COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
% INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
% BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
% LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
% CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
% LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN | ||
% ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
% POSSIBILITY OF SUCH DAMAGE. | ||
% Author: Marco Paladini <marco.paladini@ocado.com> | ||
|
||
% sample octave script to load camera poses from file and plot them | ||
% example usage: run 'pcl_kinfu_app -save_pose camera.csv' to save | ||
% camera poses in a 'camera.csv' file | ||
% run octave and cd into the directory where this script resides | ||
% and call plot_camera_poses('<path-to-camera.csv-file>') | ||
|
||
function plot_camera_poses(filename) | ||
poses=load(filename); | ||
%% show data on a 2D graph | ||
h=figure(); | ||
plot(poses,'*-'); | ||
legend('x','y','z','qw','qx','qy','qz'); | ||
|
||
%% show data as 3D axis | ||
h=figure(); | ||
for n=1:size(poses,1) | ||
t=poses(n,1:3); | ||
q=poses(n,4:7); | ||
r=q2rot(q); | ||
coord(h,r,t); | ||
end | ||
octave_axis_equal(h); | ||
|
||
%% prevent Octave from quitting if called from the command line | ||
input('Press enter to continue'); | ||
end | ||
|
||
function coord(h,r,t) | ||
figure(h); | ||
hold on; | ||
c={'r','g','b'}; | ||
p=0.1*[1 0 0;0 1 0;0 0 1]; | ||
for n=1:3 | ||
a=r*p(n,:)'; | ||
plot3([t(1),t(1)+a(1)], [t(2),t(2)+a(2)], [t(3),t(3)+a(3)], 'color', c{n}); | ||
end | ||
|
||
function R=q2rot(q) | ||
% conversion code from http://en.wikipedia.org/wiki/Rotation_matrix%Quaternion | ||
Nq = q(1)^2 + q(2)^2 + q(3)^2 + q(4)^2; | ||
if Nq>0; s=2/Nq; else s=0; end | ||
X = q(2)*s; Y = q(3)*s; Z = q(4)*s; | ||
wX = q(1)*X; wY = q(1)*Y; wZ = q(1)*Z; | ||
xX = q(2)*X; xY = q(2)*Y; xZ = q(2)*Z; | ||
yY = q(3)*Y; yZ = q(3)*Z; zZ = q(4)*Z; | ||
R=[ 1.0-(yY+zZ) xY-wZ xZ+wY ; | ||
xY+wZ 1.0-(xX+zZ) yZ-wX ; | ||
xZ-wY yZ+wX 1.0-(xX+yY) ]; | ||
end | ||
|
||
function octave_axis_equal(h) | ||
% workaround for axis auto not working in 3d | ||
% tanks http://octave.1599824.n4.nabble.com/axis-equal-help-tp1636701p1636702.html | ||
figure(h); | ||
xl = get (gca, "xlim"); | ||
yl = get (gca, "ylim"); | ||
zl = get (gca, "zlim"); | ||
span = max ([diff(xl), diff(yl), diff(zl)]); | ||
xlim (mean (xl) + span*[-0.5, 0.5]) | ||
ylim (mean (yl) + span*[-0.5, 0.5]) | ||
zlim (mean (zl) + span*[-0.5, 0.5]) | ||
end | ||
|