summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/camera/test_camera.cc
blob: b81f1dcb2732e5e37f7a92909b61872bc82d0593 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 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 <fstream>
#include <unistd.h>
#include <stdio.h>

int
main (int argc, char **argv)
{
    try
      {
	Camera cam;
	int w, h;
	cam.getSize (w, h);
	unsigned char *image = new unsigned char[w * h];
	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);
	    o.close ();
	    for (int j = 0; j < w * h; j += 4)
	      {
		image2[j * 3] = image[j + 2];
		image2[j * 3 + 1] = image[j + 1];
		image2[j * 3 + 2] = image[j];
		image2[(j + 1) * 3] = image[j + 2];
		image2[(j + 1) * 3 + 1] = image[j + 1];
		image2[(j + 1) * 3 + 2] = image[j];
		image2[(j + 2) * 3] = image[j + 2];
		image2[(j + 2) * 3 + 1] = image[j + 1];
		image2[(j + 2) * 3 + 2] = image[j];
		image2[(j + 3) * 3] = image[j + 2];
		image2[(j + 3) * 3 + 1] = image[j + 1];
		image2[(j + 3) * 3 + 2] = image[j];
	      }
	    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 += 4)
	      {
		int t = (int) image[j + 2] >> 2 - (int) image[j + 1] >> 2;
		t = t > 0 ? t : -t;
		image2[j] = t;
		image2[j + 1] = t;
		image2[j + 2] = t;
		image2[j + 3] = 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;
      }
}