00001 /*!@file SalGlasses/spyGlasses.C a test program run the SalGlasses */ 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: Lior Elazary <lelazary@yahoo.com> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/SalGlasses/spyGlasses.C $ 00035 // $Id: spyGlasses.C 10794 2009-02-08 06:21:09Z itti $ 00036 // 00037 00038 #include <stdio.h> 00039 #include "Component/ModelManager.H" 00040 #include "Image/Image.H" 00041 #include "Image/ImageSet.H" 00042 #include "Image/ShapeOps.H" 00043 #include "Image/DrawOps.H" 00044 #include "Image/ColorOps.H" 00045 #include "Image/MathOps.H" 00046 #include "Image/Layout.H" 00047 #include "GUI/XWinManaged.H" 00048 #include "Corba/ImageOrbUtil.H" 00049 #include "Corba/CorbaUtil.H" 00050 #include "Corba/Objects/SalGlassesSK.hh" 00051 #include "Neuro/EnvVisualCortex.H" 00052 00053 #include <signal.h> 00054 #include <stdio.h> 00055 #include <sys/types.h> 00056 #include <unistd.h> 00057 #include <sys/socket.h> 00058 #include <netinet/in.h> 00059 #include <unistd.h> 00060 #include <netdb.h> 00061 #include <fcntl.h> 00062 #include <arpa/inet.h> 00063 #include <stdlib.h> 00064 #include <ctype.h> 00065 00066 00067 #define UP 98 00068 #define DOWN 104 00069 #define LEFT 100 00070 #define RIGHT 102 00071 00072 #define UDPPORT 9938 00073 00074 00075 ////////////////////////////////////////////////////////////////////// 00076 int main(int argc, char** argv) 00077 { 00078 00079 00080 MYLOGVERB = LOG_INFO; 00081 ModelManager *mgr = new ModelManager("Test ObjRec"); 00082 00083 00084 nub::ref<EnvVisualCortex> evc(new EnvVisualCortex(*mgr)); 00085 mgr->addSubComponent(evc); 00086 mgr->exportOptions(MC_RECURSE); 00087 00088 if (mgr->parseCommandLine( 00089 (const int)argc, (const char**)argv, "", 0, 0) == false) 00090 return 1; 00091 00092 mgr->start(); 00093 00094 //setup network comm 00095 int sock = socket(AF_INET, SOCK_DGRAM, 0); 00096 if (sock == -1) 00097 { 00098 printf("Cannot create server socket\n"); 00099 exit(0); 00100 } 00101 00102 struct sockaddr_in addr; 00103 addr.sin_family = AF_INET; 00104 addr.sin_addr.s_addr = htonl(INADDR_ANY); // accept from any host 00105 addr.sin_port = htons(UDPPORT); 00106 if (bind(sock, (struct sockaddr*)(&addr), sizeof(addr)) == -1) 00107 { 00108 printf("Cannot bind server socket\n"); 00109 close(sock); 00110 exit(0); 00111 } 00112 00113 printf("Lisening on port %i\n", UDPPORT); 00114 00115 00116 XWinManaged* xwin = new XWinManaged(Dims(320*2,240), -1, -1, "Saliency Glasses"); 00117 Image<PixRGB<byte> > img; 00118 00119 int width = 320, height = 240; 00120 char rvcBuf[1024+4]; 00121 00122 Image<PixRGB<byte> > img(width, height, NO_INIT); 00123 00124 while(true) 00125 { 00126 00127 struct sockaddr_in fromaddr; unsigned int fromlen = sizeof(fromaddr); 00128 int ret = recvfrom(sock, rvcBuf, , 0, 00129 (struct sockaddr *)(&fromaddr), &fromlen); 00130 printf("Received message %d bytes from %s:%d\n", ret, 00131 inet_ntoa(fromaddr.sin_addr), ntohs(fromaddr.sin_port)); 00132 00133 if (ret != 1024+4) 00134 printf("Invalid packet\n"); 00135 int pos = * 00136 00137 00138 memcpy(img.getArrayPtr(), imgBuff, width*height*3); 00139 00140 00141 evc->input(img); 00142 00143 Image<float> vcxMap = evc->getVCXmap(); 00144 00145 Point2D<int> maxPos; float maxVal; 00146 00147 vcxMap = rescale(vcxMap, img.getDims()); 00148 findMax(vcxMap, maxPos, maxVal); 00149 inplaceNormalize(vcxMap, 0.0F, 255.0F); 00150 00151 drawCircle(img, maxPos, 20, PixRGB<byte>(255,0,0)); 00152 00153 Layout<PixRGB<byte> > outDisp; 00154 outDisp = vcat(outDisp, hcat(img, toRGB((Image<byte>)vcxMap))); 00155 xwin->drawRgbLayout(outDisp); 00156 00157 00158 int key = xwin->getLastKeyPress(); 00159 00160 switch (key) 00161 { 00162 case UP: 00163 break; 00164 case DOWN: 00165 break; 00166 case LEFT: 00167 break; 00168 case RIGHT: 00169 break; 00170 case 65: // space 00171 break; 00172 case 33: // p 00173 break; 00174 case 40: //d 00175 break; 00176 case 27: //r 00177 break; 00178 default: 00179 if (key != -1) 00180 printf("Unknown Key %i\n", key); 00181 break; 00182 } 00183 } 00184 return 0; 00185 }