run_simulated2d.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 * Software License Agreement (BSD License)
00003 *
00004 *  Copyright (c) 2009, Willow Garage, Inc.
00005 *  All rights reserved.
00006 *
00007 *  Redistribution and use in source and binary forms, with or without
00008 *  modification, are permitted provided that the following conditions
00009 *  are met:
00010 *
00011 *   * Redistributions of source code must retain the above copyright
00012 *     notice, this list of conditions and the following disclaimer.
00013 *   * Redistributions in binary form must reproduce the above
00014 *     copyright notice, this list of conditions and the following
00015 *     disclaimer in the documentation and/or other materials provided
00016 *     with the distribution.
00017 *   * Neither the name of the Willow Garage nor the names of its
00018 *     contributors may be used to endorse or promote products derived
00019 *     from this software without specific prior written permission.
00020 *
00021 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032 *  POSSIBILITY OF SUCH DAMAGE.
00033 *********************************************************************/
00034 
00035 #include <opencv2/core/core.hpp>
00036 #include <posest/test/simulated.h>
00037 #include <posest/planarSFM.h>
00038 #include <iostream>
00039 #include <stdio.h>
00040 
00041 using namespace pe;
00042 using namespace cv;
00043 
00044 int main(int argc, char** argv)
00045 {
00046     Mat intrinsics, R0, T0;
00047     vector<Point3f> points;
00048     vector<KeyPoint> points1, points2;
00049     vector<int> indices;
00050     generateData(intrinsics, R0, T0, points1, points2, indices, points);
00051 
00052     Mat R, T, H;
00053     double error = SFM(intrinsics, points1, points2, indices, R, T);
00054     printf("SFM completed with reprojection error %f\n", error);
00055     T = T*10.0;
00056     dumpFltMat("SFM returned R", R);
00057     dumpFltMat("SFM return T", T);
00058 
00059     vector<Point2f> _points1, _points2;
00060     matchesFromIndices(points1, points2, indices, _points1, _points2);
00061 
00062     Mat essential = calcEssentialMatrix(intrinsics.inv(), R, T);
00063     vector<bool> inliers;
00064     computeEpipolarInliers(essential, _points1, _points2, inliers, 5.0);
00065     filterVector(_points1, inliers);
00066     filterVector(_points2, inliers);
00067     filterVector(points, inliers);
00068 
00069     vector<Point3f> cloud;
00070     vector<bool> valid;
00071     reprojectPoints(intrinsics, R, T, _points1, _points2, cloud, valid);
00072 
00073     printf("%d points before filtering\n", (int)points.size());
00074     filterVector(_points1, valid);
00075     filterVector(_points2, valid);
00076     filterVector(points, valid);
00077     filterVector(cloud, valid);
00078 
00079     printf("%d points left after filtering\n", (int)points.size());
00080     float error0 = calcScaledPointCloudDistance(cloud, points);
00081 
00082     Mat rvec;
00083     Rodrigues(R, rvec);
00084 
00085     sba(intrinsics, rvec, T, cloud, _points1, _points2);
00086     findNaNPoints(cloud, valid);
00087     filterVector(_points1, valid);
00088     filterVector(_points2, valid);
00089     filterVector(cloud, valid);
00090     filterVector(points, valid);
00091 
00092     float error1 = calcScaledPointCloudDistance(cloud, points);
00093 
00094     dumpFltMat("rvec", rvec);
00095     dumpFltMat("tvec", T);
00096 
00097     printf("%d points left after sba\n3D error after SFM: %f\n 3D error after sba: %f\n",
00098         points.size(), error0, error1);
00099 
00100     FileStorage fs("extrinsics.yml", FileStorage::WRITE);
00101     fs << "rvec" << rvec << "T" << T;
00102 }


posest
Author(s): Kurt Konolige
autogenerated on Thu Jan 2 2014 12:12:17