00001 /*!@file AppDevices/test-VCC4.C Use a pan-tilt camera for executing saccades */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the // 00005 // University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Dirk Walther <walther@caltech.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/AppDevices/test-VCC4.C $ 00035 // $Id: test-VCC4.C 4751 2005-07-01 16:50:30Z rjpeters $ 00036 // 00037 00038 #include "Component/ModelManager.H" 00039 #include "Devices/VCC4.H" 00040 #include <cmath> 00041 #include <iostream> 00042 00043 00044 #define CAM_WIDTH 320 00045 #define CAM_HEIGHT 240 00046 #define CAM_DISPLAY NULL 00047 #define CAM_WINDOW_NAME "Saliency Calculated" 00048 #define CAM_PREV_NAME "Captured Image" 00049 #define CAM_VIDEO_DEVICE "/dev/video0" 00050 #define CAM_VIDEO_CHANNEL 2 00051 #define CAM_SERIAL_DEVICE "/dev/ttyS0" 00052 #define VCC4_HDEG 50 00053 #define VCC4_WDEG 67 00054 #define MAXPAN ((float)100.0) 00055 #define MINPAN ((float)-100.0) 00056 #define MAXTILT ((float)30.0) 00057 #define MINTILT ((float)-30.0) 00058 00059 // make random saccade if the salmap evolves for more than TOO_MUCH_TIME s 00060 #define TOO_MUCH_TIME 0.7 00061 00062 00063 float sqr (float x); 00064 float randang(); 00065 00066 // give back a random angle increment/decrement 00067 inline float randang () 00068 { 00069 const float max_randang = 30.0; 00070 return ((float)(2.0 * rand() / RAND_MAX) - 1.0) * max_randang; 00071 } 00072 00073 // sqr(x) = x*x; 00074 inline float sqr (float x) 00075 { 00076 return (x * x); 00077 } 00078 00079 // ###################################################################### 00080 // ##### Main Program: 00081 // ###################################################################### 00082 /*! This program takes input from a camera, calculates 00083 the most salient spot(s) and moves the camera there 00084 according to the following rules:<p> 00085 1) take image from camera 00086 2) calculate next most salient spot 00087 3) If (spot is already in list) goto 2 00088 4) store spot in list 00089 5) move to the spot 00090 6) goto 1<p> 00091 The list is finite (small) sized and "forgets" the oldest entries. 00092 When the search for the next most salient spot in a given image 00093 takes too much time, the camera is moved by a random amount.*/ 00094 int main(const int argc, const char **argv) 00095 { 00096 MYLOGVERB = LOG_INFO; 00097 00098 /* 00099 int min_dist = min(VCC4_HDEG, VCC4_WDEG) / 12; 00100 const int num_mem = 10; 00101 float mem_pan[num_mem], mem_tilt[num_mem]; 00102 int mem_ptr = 0; 00103 bool mem_filled = false; 00104 bool is_in_mem; 00105 int mem_top; 00106 */ 00107 00108 std::cout << "Mark 1 \n"; 00109 00110 // instantiate a model manager: 00111 ModelManager manager("Test VCC4"); 00112 00113 // Instantiate our various ModelComponents: 00114 nub::soft_ref<VCC4> pantilt(new VCC4(manager)); 00115 manager.addSubComponent(pantilt); 00116 00117 // Parse command-line: 00118 if (manager.parseCommandLine(argc, argv, "", 0, 0) == false) return(1); 00119 00120 // let's get all our ModelComponent instances started: 00121 manager.start(); 00122 00123 std::cout << "Mark 2 \n"; 00124 00125 pantilt->CameraInitialize(true); 00126 std::cout << "Mark 3 \n"; 00127 00128 pantilt->PlainCommand(VCC4_SetZoomingWIDE); 00129 std::cout << "Mark 4 \n"; 00130 00131 pantilt->PlainCommand(VCC4_GoHome); 00132 00133 00134 manager.stop(); 00135 return 0; 00136 } 00137 00138 00139 00140 // ###################################################################### 00141 /* So things look consistent in everyone's emacs... */ 00142 /* Local Variables: */ 00143 /* indent-tabs-mode: nil */ 00144 /* End: */