app-calibrate-VCC4.C

Go to the documentation of this file.
00001 /*!@file AppDevices/app-calibrate-VCC4.C Calibration for the VCC4 pan/tilt camera unit
00002  */
00003 
00004 // //////////////////////////////////////////////////////////////////// //
00005 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003   //
00006 // by the University of Southern California (USC) and the iLab at USC.  //
00007 // See http://iLab.usc.edu for information about this project.          //
00008 // //////////////////////////////////////////////////////////////////// //
00009 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00010 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00011 // in Visual Environments, and Applications'' by Christof Koch and      //
00012 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00013 // pending; application number 09/912,225 filed July 23, 2001; see      //
00014 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00015 // //////////////////////////////////////////////////////////////////// //
00016 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00017 //                                                                      //
00018 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00019 // redistribute it and/or modify it under the terms of the GNU General  //
00020 // Public License as published by the Free Software Foundation; either  //
00021 // version 2 of the License, or (at your option) any later version.     //
00022 //                                                                      //
00023 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00024 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00025 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00026 // PURPOSE.  See the GNU General Public License for more details.       //
00027 //                                                                      //
00028 // You should have received a copy of the GNU General Public License    //
00029 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00030 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00031 // Boston, MA 02111-1307 USA.                                           //
00032 // //////////////////////////////////////////////////////////////////// //
00033 //
00034 // Primary maintainer for this file: Dirk Walther <walther@caltech.edu>
00035 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppDevices/app-calibrate-VCC4.C $
00036 // $Id: app-calibrate-VCC4.C 6454 2006-04-11 00:47:40Z rjpeters $
00037 //
00038 
00039 #include "Component/ModelManager.H"
00040 #include "Devices/DeviceOpts.H"
00041 #include "Devices/FrameGrabberConfigurator.H"
00042 #include "Devices/VCC4.H"
00043 #include "GUI/XWinManaged.H"
00044 #include "Image/ColorOps.H"
00045 #include "Image/Image.H"
00046 #include "Image/Pixels.H"
00047 #include "Image/calibrateFunctions.H"
00048 #include "Transport/FrameIstream.H"
00049 #include "Util/log.H"
00050 #include <iostream>
00051 #include <stdio.h>
00052 
00053 int main (const int argc, const char **argv)
00054 {
00055   LOG_FLAGS &= (~LOG_FULLTRACE);
00056 
00057   // instantiate a model manager:
00058   ModelManager manager("Camera Calibrator");
00059 
00060   // Instantiate our various ModelComponents:
00061   nub::soft_ref<FrameGrabberConfigurator>
00062     gbc(new FrameGrabberConfigurator(manager));
00063   manager.addSubComponent(gbc);
00064 
00065   nub::soft_ref<VCC4> pantilt(new VCC4(manager));
00066   manager.addSubComponent(pantilt);
00067 
00068   // choose a V4Lgrabber by default, and a few custom grabbing
00069   // defaults, for backward compatibility with an older version of
00070   // this program:
00071   manager.setOptionValString(&OPT_FrameGrabberType, "V4L");
00072   manager.setOptionValString(&OPT_FrameGrabberDims, "640x480");
00073 
00074   // Parse command-line:
00075   if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1);
00076 
00077   // do post-command-line configs:
00078   nub::soft_ref<FrameIstream> gb = gbc->getFrameGrabber();
00079   if (gb.isInvalid())
00080     LFATAL("You need to select a frame grabber type via the "
00081            "--fg-type=XX command-line option for this program "
00082            "to be useful");
00083 
00084   // let's get all our ModelComponent instances started:
00085   manager.start();
00086 
00087   int maxtilt = 30;  //, mintilt = -30;
00088   int maxpan = 100;  //, minpan = -100;
00089   const Dims dims = gb->peekDims();
00090 
00091   Image< PixRGB<byte> > cimg(dims,NO_INIT);
00092   Image<byte> bimg1(dims,NO_INIT), bimg2(dims,NO_INIT);
00093 
00094   pantilt->CameraInitialize(true);
00095   pantilt->gotoPosition(0,0,true);
00096 
00097   cimg = gb->readRGB();
00098   cimg = gb->readRGB();
00099   cimg = gb->readRGB();
00100 
00101   bimg1 = luminance(cimg);
00102 
00103   XWinManaged win1(dims,-1,-1,"Center"), win2(dims,-1,-1,"Periphery");
00104   win1.drawImage(bimg1);
00105 
00106   int dist = 0, angle = 0;
00107   int lbound = -10, ubound = 10;
00108   int est_pan = 100;
00109   int est_tilt = 80;
00110   float bounds = 0.1;
00111   int est;
00112 
00113   std::cout << "Tilt:\n";
00114   while ((dist < 0.9 * dims.h()) && (angle <= maxtilt))
00115     {
00116       cimg = gb->readRGB();
00117       angle++;
00118       pantilt->gotoPosition(0,angle,true);usleep(50000);
00119 
00120       bimg2 = luminance(cimg);
00121       win2.drawImage(bimg2);
00122 
00123       dist = findAlign(bimg1,bimg2,ALIGN_Y,lbound,ubound);
00124 
00125       est = dims.h() / est_tilt * angle;
00126       lbound = (int)(est * (1.0 - bounds));
00127       //lbound = dist;
00128       ubound = (int)(est * (1.0 + bounds));
00129 
00130       //lbound = dist;
00131       //ubound = dist * (angle + 2) / angle;
00132       if ((ubound - lbound) < 10)
00133         {
00134           ubound += 5;
00135           lbound -= 5;
00136         }
00137       if (ubound >= dims.h()) ubound = dims.h() - 1;
00138 
00139       std::cout << angle-1 << "\t" << dist << "\n";
00140       //std::cout << dist << " ";
00141     }
00142   pantilt->gotoPosition(0,0,true);
00143 
00144   std::cout << "\n";
00145 
00146   dist = 0; angle = 0;
00147   lbound = -10; ubound = 10;
00148 
00149   std::cout << "Pan:\n";
00150   while ((dist < 0.9 * dims.w()) && (angle <= maxpan))
00151     {
00152       cimg = gb->readRGB();
00153       angle++;
00154       pantilt->gotoPosition(angle,0,true);usleep(50000);
00155 
00156       bimg2 = luminance(cimg);
00157       win2.drawImage(bimg2);
00158 
00159       dist = findAlign(bimg1,bimg2,ALIGN_X,lbound,ubound);
00160 
00161       est = dims.w() / est_pan * angle;
00162       lbound = (int)(est * (1.0 - bounds));
00163       //lbound = dist;
00164       ubound = (int)(est * (1.0 + bounds));
00165 
00166       //lbound = dist;
00167       //ubound = dist * (angle + 2) / angle;
00168       if ((ubound - lbound) < 10)
00169         {
00170           ubound += 5;
00171           lbound -= 5;
00172         }
00173       if (ubound >= dims.w()) ubound = dims.w() - 1;
00174 
00175 
00176       std::cout << angle-1 << "\t" << dist << "\n";
00177       //std::cout << dist << " ";
00178     }
00179 
00180   std::cout << "\n";
00181 
00182   pantilt->gotoPosition(0,0,false);
00183 
00184   //while (!(win1.pressedCloseButton() || win2.pressedCloseButton())) sleep(1);
00185 
00186   // stop all our ModelComponents
00187   manager.stop();
00188 
00189   // all done!
00190   return 0;
00191 }
00192 
00193 // ######################################################################
00194 /* So things look consistent in everyone's emacs... */
00195 /* Local Variables: */
00196 /* indent-tabs-mode: nil */
00197 /* End: */
Generated on Sun May 8 08:04:10 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3