00001 00002 /* Most of capture.cpp and capture.h are copied from http://jsk-enshu.svn.sourceforge.net/viewvc/jsk-enshu/trunk/keisanki/2009/ */ 00003 #include <opencv/cv.h> 00004 #include <opencv/highgui.h> 00005 #include <linux/videodev2.h> 00006 #include <fcntl.h> 00007 #include <errno.h> 00008 #include <sys/ioctl.h> 00009 00010 /* v4l2 capture class */ 00011 class v4l_capture 00012 { 00013 typedef struct _buffer { 00014 void *start; 00015 size_t length; 00016 } buffer; 00017 cv::Mat frame; 00018 std::string dev_name; 00019 int fd, width, height; 00020 buffer *buffers; 00021 unsigned int n_buffers; 00022 bool open_device(); 00023 bool init_device(); 00024 bool init_mmap(); 00025 bool start_capturing(); 00026 bool stop_capturing(); 00027 void uninit_device(); 00028 bool uninit_mmap(); 00029 bool close_device(); 00030 bool read_frame(void); 00031 bool write_img(uchar * ret); 00032 bool init_all(size_t _width, size_t _height, unsigned int _devId); 00033 public: 00034 v4l_capture(); 00035 ~v4l_capture(); 00036 uchar *capture (); 00037 int getHeight (); 00038 int getWidth (); 00039 int init (size_t _width, size_t _height, unsigned int devId); 00040 };