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
00032 Camera *cam;
00033 SharedMemoryImageBuffer *shm;
00034 bool quit = false;
00035
00036 void
00037 handle_signal(int signum)
00038 {
00039   quit = true;
00040 }
00041
00042 int
00043 main(int argc, char **argv)
00044 {
00045   signal(SIGINT, handle_signal);
00046
00047   printf("Instantiating camera\n");
00048   cam = CameraFactory::instance("leutron:leutron");
00049   printf("Opening camera\n");
00050   cam->open();
00051   printf("Starting camera\n");
00052   cam->start();
00053
00054   printf("Creating shm segment rcxretriever\n");
00055   shm = new SharedMemoryImageBuffer("rcxretriever", cam->colorspace(),
00056                                     cam->pixel_width(), cam->pixel_height());
00057
00058   printf("Running capture loop\n");
00059   while (! quit) {
00060     cam->capture();
00061     memcpy(shm->buffer(), cam->buffer(), cam->buffer_size());
00062     cam->dispose_buffer();
00063   }
00064
00065   printf("Cleaning up\n");
00066   cam->stop();
00067   cam->close();
00068
00069   delete shm;
00070   delete cam;
00071
00072 }
00073