// test_video4linux.cc // nono - programme du robot 2004. {{{ // // Copyright (C) 2004 Nicolas Schodet // // Robot APB Team/Efrei 2004. // Web: http://assos.efrei.fr/robot/ // Email: robot AT efrei DOT fr // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. // // }}} #include "video4linux.h" #include "utils/errno_exception.h" #include "date/date.h" #include #include #include #include #include #include #include int main (int argc, char **argv) { try { if (argc != 3) throw std::runtime_error ("Syntaxe : fichier " "{rgb|bgr|yuv|yuv422}"); std::string format (argv[2]); Video4Linux::ColorSpace cs; if (format == "rgb") cs = Video4Linux::rgb; else if (format == "bgr") cs = Video4Linux::bgr; else if (format == "yuv") cs = Video4Linux::yuv; else if (format == "yuv422") cs = Video4Linux::yuv422; else throw std::invalid_argument ("Syntaxe : fichier {rgb|yuv422}"); Video4Linux vid ("/dev/video", cs); vid.calibrate (); int w, h; vid.getSize (w, h); std::cout << w << ' ' << h << std::endl; int s; s = vid.getBufSize (); unsigned char *buf = new unsigned char[s]; for (int i = 0; i < 10; ++i) { s = vid.read (buf, s); std::ostringstream os; os << argv[1] << std::setw (3) << std::setfill ('0') << i << '.' << argv[2]; int fd = open (os.str ().c_str (), O_WRONLY | O_CREAT, 0666); if (fd == -1) throw errno_exception (argv[1], errno); write (fd, buf, s); close (fd); } delete[] buf; return 0; } catch (const std::exception &e) { std::cerr << e.what () << std::endl; return 1; } }