main.cpp
Go to the documentation of this file.
00001 #include <stdio.h>
00002 #include <stdlib.h>
00003 #include <string.h>
00004 #include <signal.h>
00005 
00006 #include <iostream>
00007 #include <string>
00008 
00009 #include <fovis/fovis.hpp>
00010 
00011 #include "data_capture.hpp"
00012 
00013 #define dbg(...) fprintf(stderr, __VA_ARGS__)
00014 
00015 sig_atomic_t shutdown_flag = 0;
00016 static void
00017 sig_action(int signal, siginfo_t *s, void *user)
00018 {
00019   fprintf(stderr,"Shutting Down!\n");
00020   shutdown_flag = 1;
00021 }
00022 
00023 std::string
00024 isometryToString(const Eigen::Isometry3d& m)
00025 {
00026   char result[80];
00027   memset(result, 0, sizeof(result));
00028   Eigen::Vector3d xyz = m.translation();
00029   Eigen::Vector3d rpy = m.rotation().eulerAngles(0, 1, 2);
00030   snprintf(result, 79, "%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f", 
00031       xyz(0), xyz(1), xyz(2), 
00032       rpy(0) * 180/M_PI, rpy(1) * 180/M_PI, rpy(2) * 180/M_PI);
00033   return std::string(result);
00034 }
00035 
00036 int main(int argc, char **argv)
00037 {
00038   // initialize the device
00039   fovis_example::DataCapture* cap = new fovis_example::DataCapture();
00040   if(!cap->initialize()) {
00041     fprintf(stderr, "Unable to initialize OpenNI sensor\n");
00042     return 1;
00043   }
00044   if(!cap->startDataCapture()) {
00045     fprintf(stderr, "Unable to start data capture\n");
00046     return 1;
00047   }
00048 
00049   // get the RGB camera parameters of our device
00050   fovis::Rectification rect(cap->getRgbParameters());
00051 
00052   fovis::VisualOdometryOptions options = 
00053       fovis::VisualOdometry::getDefaultOptions();
00054   // If we wanted to play around with the different VO parameters, we could set
00055   // them here in the "options" variable.
00056 
00057   // setup the visual odometry
00058   fovis::VisualOdometry* odom = new fovis::VisualOdometry(&rect, options);
00059 
00060   // exit cleanly on CTL-C
00061   struct sigaction new_action;
00062   new_action.sa_sigaction = sig_action;
00063   sigemptyset(&new_action.sa_mask);
00064   new_action.sa_flags = 0;
00065   sigaction(SIGINT, &new_action, NULL);
00066   sigaction(SIGTERM, &new_action, NULL);
00067   sigaction(SIGHUP, &new_action, NULL);
00068 
00069   while(!shutdown_flag) {
00070     if(!cap->captureOne()) {
00071       fprintf(stderr, "Capture failed\n");
00072       break;
00073     }
00074 
00075     odom->processFrame(cap->getGrayImage(), cap->getDepthImage());
00076 
00077     // get the integrated pose estimate.
00078     Eigen::Isometry3d cam_to_local = odom->getPose();
00079 
00080     // get the motion estimate for this frame to the previous frame.
00081     Eigen::Isometry3d motion_estimate = odom->getMotionEstimate();
00082 
00083     // display the motion estimate.  These values are all given in the RGB
00084     // camera frame, where +Z is forward, +X points right, +Y points down, and
00085     // the origin is located at the focal point of the RGB camera.
00086     std::cout << isometryToString(cam_to_local) << " " << 
00087       isometryToString(motion_estimate) << "\n";
00088   }
00089 
00090   printf("Shutting down\n");
00091   cap->stopDataCapture();
00092   delete odom;
00093   delete cap;
00094   return 0;
00095 }


libfovis
Author(s): Albert Huang, Maurice Fallon
autogenerated on Thu Jun 6 2019 20:16:12