// test_video4linux.cc // robert - programme du robot 2005. {{{ // // Copyright (C) 2005 Nicolas Schodet // Modified by Olivier Gaillard // // Robot APB Team/Efrei 2005. // 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.hh" #include "utils/errno_exception.hh" #include #include #include #include #include #include #include int main (int argc, char **argv) { try { if ((argc != 3) && (argc != 4)) throw std::runtime_error ("Syntaxe : fichier " "{rgb|bgr|yuv|yuv422} [luminosité]"); std::string format (argv[2]); Image::PixelFormat pf; if (format == "rgb") pf = Image::rgb; else if (format == "bgr") pf = Image::bgr; else if (format == "yuv") pf = Image::yuv; else if (format == "yuv422") pf = Image::yuv422; else throw std::invalid_argument ("Syntaxe : fichier {rgb|yuv422}"); int lum = 58000; if (argc == 4) { std::istringstream isLum (argv[3]); isLum >> lum; } const unsigned width = 640; const unsigned height = 480; Video4Linux vid ("/dev/video", width, height, pf, lum); vid.calibrate (); int w, h; vid.getParam (w, h, pf); std::cout << w << ' ' << h << std::endl; // vid.setAdaptive (0); int s; s = Image::getBufSize (w, h, pf); uint8_t *buf = new uint8_t[s]; for (int i = 0; i < 10; ++i) { 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; } }