contrib/oul/oufgl/frame_grabber_v4l.h
Go to the documentation of this file.
00001 //:
00002 // \file
00003 //
00004 // \brief Classes for video input under linux making use of the video for linux stuff.
00005 // This has been tested using a webcam running under the Philips Web Cam driver.
00006 //
00007 // Copyright (c) 2002 Brendan McCane
00008 // University of Otago, Dunedin, New Zealand
00009 // Reproduction rights limited as described in the COPYRIGHT file.
00010 //----------------------------------------------------------------------
00011 
00012 #ifndef OTAGO_frame_grabber_v4l__h_INCLUDED
00013 #define OTAGO_frame_grabber_v4l__h_INCLUDED
00014 
00015 #include <vil1/vil1_memory_image.h>
00016 #include <vil1/vil1_memory_image_of.h>
00017 #include <vxl_config.h>
00018 #include "asyncio.h"
00019 #include "frame_grabber.h"
00020 #include <sys/mman.h>
00021 #include <sys/ioctl.h>
00022 #include <sys/types.h>
00023 #include <linux/videodev.h>
00024 #include <vcl_iostream.h>
00025 
00026 //----------------------------------------------------------------------
00027 //: The FrameGrabberV4lGrey class
00028 //
00029 // This class provides an interface with a v4l camera on a
00030 // linux system. I have not attempted at all to provide
00031 // cross-compatibility with linux and windows and indeed some
00032 // difficult questions are raised when hardware issues become
00033 // involved.
00034 //
00035 // \todo   under development
00036 // \author Brendan McCane
00037 //----------------------------------------------------------------------
00038 
00039 
00040 class FrameGrabberV4lGrey : public FrameGrabber
00041 {
00042  public:
00043   typedef vxl_byte ImageContents;
00044   typedef vil1_memory_image_of< ImageContents > ImageGrey;
00045 
00046   FrameGrabberV4lGrey(int width_=384, int height_=288, bool debug=false,
00047                       char *devname="/dev/video0");
00048   virtual ~FrameGrabberV4lGrey();
00049   // returns the current acquired frame
00050   inline vil1_memory_image *get_current_frame()
00051   {
00052     if (debug)
00053     {
00054       vcl_cout << "get_current_frame called\n"
00055                << "current = " << current
00056                << " im = " << im[current] << vcl_endl;
00057     }
00058     return im[current];
00059   }
00060   // acquire a new frame synchronously (ie don't return until completed)
00061   void acquire_frame_synch();
00062   // acquire a new frame asynchronously (ie start acquiring and
00063   // return immediately )
00064   void acquire_frame_asynch();
00065   // return the current frame and start acquiring the next one. This
00066   // function is only useful if asynchronous acquires are going to
00067   // be used.
00068   vil1_memory_image *get_current_and_acquire();
00069  private:
00070   ImageContents *contents[2];
00071   ImageGrey *im[2];
00072   int current;
00073   AsyncIO *aio;
00074   int width, height;
00075   int fd;
00076   void flip_current();
00077   bool debug;
00078 };
00079 
00080 #endif