00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 #include <posest/pe3d.h>
00037 #include <opencv/highgui.h>
00038 #include <boost/shared_ptr.hpp>
00039 #include <cstdio>
00040 #include <fstream>
00041 
00042 
00043 using namespace frame_common;
00044 using namespace std;
00045 
00046 
00047 #include <sys/time.h>
00048 static double mstime()
00049 {
00050   timeval tv;
00051   gettimeofday(&tv,NULL);
00052   long long ts = tv.tv_sec;
00053   ts *= 1000000;
00054   ts += tv.tv_usec;
00055   return (double)ts*.001;
00056 }
00057 
00058 
00059 int main(int argc, char** argv)
00060 {
00061   if (argc < 6)
00062     {
00063       printf("Args are: <params> <left0> <left1> <right0> <right1>\n");
00064       exit(0);
00065     }
00066 
00067   
00068   fstream fstr;
00069   fstr.open(argv[1],fstream::in);
00070   if (!fstr.is_open())
00071     {
00072       printf("Can't open camera file %s\n",argv[1]);
00073       exit(0);
00074     }
00075   CamParams camp;
00076   fstr >> camp.fx;
00077   fstr >> camp.fy;
00078   fstr >> camp.cx;
00079   fstr >> camp.cy;
00080   fstr >> camp.tx;
00081 
00082   cout << "Cam params: " << camp.fx << " " << camp.fy << " " << camp.cx
00083        << " " << camp.cy << " " << camp.tx << endl;
00084 
00085   
00086   cv::Mat image1 = cv::imread(argv[2], 0);
00087   cv::Mat image2 = cv::imread(argv[3], 0);
00088   cv::Mat image1r = cv::imread(argv[4], 0);
00089   cv::Mat image2r = cv::imread(argv[5], 0);
00090   printf("Image size: %d x %d\n", image1.cols, image1.rows);
00091   printf("Image size: %d x %d\n", image1r.cols, image1r.rows);
00092   printf("Image size: %d x %d\n", image2.cols, image2.rows);
00093   printf("Image size: %d x %d\n", image2r.cols, image2r.rows);
00094 
00095   if (image1.rows == 0 || image1r.rows == 0 || image2.rows == 0 || image2r.rows == 0)
00096     exit(0);
00097 
00098   cout << "Setting up frame processing..." << flush;
00099   FrameProc fp(30);
00100   cout << "done" << endl;
00101   
00102   Frame f0, f1;
00103   f0.setCamParams(camp);        
00104   f1.setCamParams(camp);
00105 
00106   double t0 = mstime();
00107   fp.setStereoFrame(f0,image1,image1r);
00108   fp.setStereoFrame(f1,image2,image2r);
00109 
00110   printf("%d keypoints from %s\n", (int)f0.kpts.size(), argv[2]);
00111   printf("%d keypoints from %s\n", (int)f1.kpts.size(), argv[3]);
00112 
00113   
00114   
00115   
00116 
00117   srand(mstime());              
00118 
00119   int n0=0, n1=0;
00120   for (int i=0; i<(int)f0.goodPts.size(); i++)
00121     if (f0.goodPts[i]) n0++;
00122   for (int i=0; i<(int)f1.goodPts.size(); i++)
00123     if (f1.goodPts[i]) n1++;
00124   printf("%d/%d, %d/%d good stereo points\n", n0, (int)f0.goodPts.size(), 
00125          n1, (int)f1.goodPts.size());
00126 
00127   for (int i=0; i<100; i++)
00128     {
00129       
00130       pe::PoseEstimator3d pe(500,true,10.0,4.0,4.0);
00131       double t0 = mstime();
00132       int inl = pe.estimate(f0,f1);
00133       double t1 = mstime();
00134       printf("\n");
00135       printf("%d matches\n", (int)pe.matches.size());
00136       printf("Number of inliers: %d; time is %0.2f ms\n", inl, t1-t0);
00137 
00138       cout << pe.trans.transpose() << endl << endl;
00139       cout << pe.rot << endl << "==========================" << endl;
00140 
00141 
00142       
00143       cv::Mat display;
00144       drawMatches(image1, f0.kpts, image2, f1.kpts, pe.inliers, display);
00145       
00146       const std::string window_name = "matches";
00147       cv::namedWindow(window_name,0);
00148       cv::imshow(window_name, display);
00149       cv::waitKey(2000);
00150     }
00151   return 0;
00152 }