rcxretriever.cpp

00001 
00002 /***************************************************************************
00003  *  rcxretriever.cpp - FireVision Retriever for RCSoftX
00004  *
00005  *  Created: Tue Jul 15 13:38:52 2008 (RoboCup 2008, Suzhou)
00006  *  Copyright  2006-2008  Tim Niemueller [www.niemueller.de]
00007  *
00008  ****************************************************************************/
00009 
00010 /*  This program is free software; you can redistribute it and/or modify
00011  *  it under the terms of the GNU General Public License as published by
00012  *  the Free Software Foundation; either version 2 of the License, or
00013  *  (at your option) any later version.
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL file in the doc directory.
00021  */
00022 
00023 #include <cams/factory.h>
00024 #include <fvutils/ipc/shm_image.h>
00025 
00026 #include <cstring>
00027 #include <signal.h>
00028 #include <cstdio>
00029 
00030 using namespace fawkes;
00031 using namespace firevision;
00032 
00033 Camera *cam;
00034 SharedMemoryImageBuffer *shm;
00035 bool quit = false;
00036 
00037 void
00038 handle_signal(int signum)
00039 {
00040   quit = true;
00041 }
00042 
00043 int
00044 main(int argc, char **argv)
00045 {
00046   signal(SIGINT, handle_signal);
00047 
00048   printf("Instantiating camera\n");
00049   cam = CameraFactory::instance("leutron:leutron");
00050   printf("Opening camera\n");
00051   cam->open();
00052   printf("Starting camera\n");
00053   cam->start();
00054 
00055   printf("Creating shm segment rcxretriever\n");
00056   shm = new SharedMemoryImageBuffer("rcxretriever", cam->colorspace(),
00057                                     cam->pixel_width(), cam->pixel_height());
00058 
00059   printf("Running capture loop\n");
00060   while (! quit) {
00061     cam->capture();
00062     memcpy(shm->buffer(), cam->buffer(), cam->buffer_size());
00063     cam->dispose_buffer();
00064   }
00065 
00066   printf("Cleaning up\n");
00067   cam->stop();
00068   cam->close();
00069 
00070   delete shm;
00071   delete cam;
00072 
00073 }
00074