// test_camera.cc // buzz - Programme du robot Efrei Robotique I1-I2 2003 // Copyright (C) 2003 Nicolas Schodet // #include "camera.h" #include "erreur/erreur.h" #include "date/date.h" #include #include #include int main (int argc, char **argv) { try { Camera cam; Date date; int w, h, d; cam.getSize (w, h, d); unsigned char *image = new unsigned char[w * h * d]; unsigned char *image2 = new unsigned char[w * h * 3]; for (int i = 0; i < 10; ++i) { char s[256]; sprintf (s, "camera%d.gray", i); ofstream o (s); while (cam.read (image) == 0) sleep (1); o.write (image, w * h * d); o.close (); if (d == 4) { for (int j = 0; j < w * h; ++j) { image2[j * 3] = image[j * 4 + 2]; image2[j * 3 + 1] = image[j * 4 + 1]; image2[j * 3 + 2] = image[j * 4]; } sprintf (s, "camera%d.rgb", i); o.open (s); o.write (image2, w * h * 3); o.close (); } for (int j = 0; j < w * h; ++j) { int t = ((int) image[j * 4 + 2] >> 1) - ((int) image[j * 4 + 1] >> 1); t = t > 0 ? t : -t; image2[j] = t; } sprintf (s, "camera%d.diff.gray", i); o.open (s); o.write (image2, w * h); o.close (); } return 0; } catch (Erreur &e) { cout << e.what (); return 1; } }