Homepage | Demos | Overview | Downloads | Tutorials | Reference | Credits |
00001 /*========================================================================= 00002 CMPack'02 Source Code Release for OPEN-R SDK v1.0 00003 Copyright (C) 2002 Multirobot Lab [Project Head: Manuela Veloso] 00004 School of Computer Science, Carnegie Mellon University 00005 ------------------------------------------------------------------------- 00006 This software is distributed under the GNU General Public License, 00007 version 2. If you do not have a copy of this licence, visit 00008 www.gnu.org, or write: Free Software Foundation, 59 Temple Place, 00009 Suite 330 Boston, MA 02111-1307 USA. This program is distributed 00010 in the hope that it will be useful, but WITHOUT ANY WARRANTY, 00011 including MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00012 ------------------------------------------------------------------------- 00013 Additionally licensed to Sony Corporation under the following terms: 00014 00015 This software is provided by the copyright holders AS IS and any 00016 express or implied warranties, including, but not limited to, the 00017 implied warranties of merchantability and fitness for a particular 00018 purpose are disclaimed. In no event shall authors be liable for 00019 any direct, indirect, incidental, special, exemplary, or consequential 00020 damages (including, but not limited to, procurement of substitute 00021 goods or services; loss of use, data, or profits; or business 00022 interruption) however caused and on any theory of liability, whether 00023 in contract, strict liability, or tort (including negligence or 00024 otherwise) arising in any way out of the use of this software, even if 00025 advised of the possibility of such damage. 00026 ========================================================================= 00027 */ 00028 00029 #include "Vision.h" 00030 #include "VisionSerializer.h" 00031 #include "Wireless/Wireless.h" 00032 #include "Shared/Config.h" 00033 #include "Shared/get_time.h" 00034 00035 VisionSerializer::VisionSerializer() : visRaw(NULL), visRLE(NULL) { 00036 visRaw=wireless->socket(SocketNS::SOCK_STREAM, 1024, 88*72*3); 00037 visRLE=wireless->socket(SocketNS::SOCK_STREAM, 1024, 22*144*3*2); 00038 wireless->listen(visRaw, config->vision.raw_port); 00039 wireless->listen(visRLE, config->vision.rle_port); 00040 } 00041 00042 void 00043 VisionSerializer::serialize() { 00044 // static int time=get_time(); 00045 // static int frame=0; 00046 char *buf=(char*)visRaw->getWriteBuffer(22*144*3); 00047 if (buf) { 00048 encodeVisionRaw((char *)buf,vision->img,2); 00049 //visRaw->write(174*144*3); 00050 visRaw->write(88*72*3); 00051 /* if (get_time()-time>1000) { 00052 time=get_time(); 00053 cout << frame << "hz " << time << endl; 00054 frame=0; 00055 } else { 00056 frame++; 00057 }*/ 00058 } 00059 00060 buf=(char*)visRLE->getWriteBuffer(22*144*3*2); 00061 if (buf) { 00062 encodeVisionRLE((char *)buf, vision->num_runs, vision->rmap); 00063 visRLE->write(4+vision->num_runs*3); 00064 } 00065 00066 } 00067 00068 char * 00069 VisionSerializer::encodeVisionRun(char *buf, run *rn) { 00070 buf[0]=(uchar)rn->color; 00071 buf[1]=(uchar)rn->x; 00072 buf[2]=(uchar)rn->width; 00073 return buf+3; 00074 } 00075 00076 void 00077 VisionSerializer::encodeVisionRaw(char *buf, 00078 CMVision::image_yuv<const uchar> &img, 00079 int scale) { 00080 const uchar *row_y,*row_u,*row_v; 00081 int height, width; 00082 height = img.height; 00083 width = img.width; 00084 00085 for(int y=0; y<height; y+=scale) { 00086 row_y = img.buf_y + y*img.row_stride; 00087 row_u = img.buf_u + y*img.row_stride; 00088 row_v = img.buf_v + y*img.row_stride; 00089 for(int x=0; x<width; x+=scale) { 00090 *(buf )=row_y[x]; 00091 *(buf+1)=row_u[x]; 00092 *(buf+2)=row_v[x]; 00093 buf+=3; 00094 } 00095 } 00096 } 00097 00098 void 00099 VisionSerializer::encodeVisionRLE(char *buf,int num_runs,run *runs) { 00100 encode(&buf,num_runs); 00101 for (; num_runs>0; num_runs--, runs++) { 00102 buf=encodeVisionRun(buf,runs); 00103 } 00104 }; 00105 00106 /*! @file 00107 * @brief Implements VisionSerializer, which encodes and transmits camera images 00108 * @author CMU RoboSoccer 2001-2002 (Creator) 00109 * @author alokl (Ported) 00110 * 00111 * @verbinclude CMPack_license.txt 00112 * 00113 * $Author: ejt $ 00114 * $Name: tekkotsu-1_4_1 $ 00115 * $Revision: 1.5 $ 00116 * $State: Exp $ 00117 * $Date: 2003/06/12 23:41:41 $ 00118 */
Tekkotsu v1.4 |
Generated Sat Jul 19 00:06:32 2003 by Doxygen 1.3.2 |