summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src
diff options
context:
space:
mode:
Diffstat (limited to '2003/i/buzz/src')
-rw-r--r--2003/i/buzz/src/camera/camera.cc45
-rw-r--r--2003/i/buzz/src/camera/camera.h5
-rw-r--r--2003/i/buzz/src/camera/test_camera.cc43
3 files changed, 63 insertions, 30 deletions
diff --git a/2003/i/buzz/src/camera/camera.cc b/2003/i/buzz/src/camera/camera.cc
index 27132f9..5bc6920 100644
--- a/2003/i/buzz/src/camera/camera.cc
+++ b/2003/i/buzz/src/camera/camera.cc
@@ -19,7 +19,7 @@
Camera::Camera ()
{
// Taille par défaut.
- m_w = 352; m_h = 288;
+ m_w = 352; m_h = 288; m_d = 1;
m_cut = 0;
// Ouvre le périphérique.
m_fd = open (CAM_FILE, O_RDONLY);
@@ -44,6 +44,12 @@ Camera::Camera ()
m_h = rc.getNum ();
cout << "camera height " << m_h << endl;
}
+ else if (rc.isId ("depth"))
+ {
+ rc.getId ();
+ m_d = rc.getNum ();
+ cout << "camera depth " << m_d << endl;
+ }
else if (rc.isId ("cut"))
{
rc.getId ();
@@ -60,6 +66,8 @@ Camera::Camera ()
endl;
ioctl (m_fd, CAM_SCCBWRITE, &param);
}
+ else
+ rc.noId ();
}
// Affiche les paramètres.
cout << hex << "camera sccbdump";
@@ -74,8 +82,9 @@ Camera::Camera ()
}
cout << endl << dec;
// Paramètre la taille de frame.
- ioctl (m_fd, CAM_SETHCOUNT, &m_w);
- m_frameSize = m_w * m_h + m_cut;
+ int hcount = m_w * m_d;
+ ioctl (m_fd, CAM_SETHCOUNT, &hcount);
+ m_frameSize = m_w * m_h * m_d + m_cut;
ioctl (m_fd, CAM_SETFRAMESIZE, &m_frameSize);
}
@@ -99,3 +108,33 @@ Camera::read (unsigned char *image) const
cout << "camera read " << r << endl;
return r;
}
+
+// Lit une image en RGB.
+int
+Camera::readRGB (unsigned char *rgb) const
+{
+ int ret;
+ // Alloue de la mémoire.
+ unsigned char *image = new unsigned char[m_frameSize];
+ // Lit les données sur la camera.
+ ret = ::read (m_fd, image, m_frameSize);
+ cout << "camera read " << ret << endl;
+ if (!ret) return 0;
+ // Positions de débuts.
+ unsigned char *r, *g, *b;
+ r = image + m_cut + 2;
+ g = image + m_cut + 1;
+ b = image + m_cut;
+ // Décode les couleurs.
+ for (int i = 0; i < m_w * m_h; ++i)
+ {
+ *rgb++ = *r;
+ r += 4;
+ *rgb++ = *g;
+ g += 4;
+ *rgb++ = *b;
+ b += 4;
+ }
+ return ret - m_cut;
+}
+
diff --git a/2003/i/buzz/src/camera/camera.h b/2003/i/buzz/src/camera/camera.h
index 2d056c4..2ab1479 100644
--- a/2003/i/buzz/src/camera/camera.h
+++ b/2003/i/buzz/src/camera/camera.h
@@ -7,7 +7,7 @@
class Camera
{
int m_fd;
- int m_w, m_h;
+ int m_w, m_h, m_d;
int m_cut;
int m_frameSize;
public:
@@ -17,8 +17,11 @@ class Camera
~Camera ();
// Lit une image.
int read (unsigned char *image) const;
+ // Lit une image en RGB.
+ int readRGB (unsigned char *rgb) const;
// Lit la taille.
void getSize (int &w, int &h) const { w = m_w; h = m_h; }
+ void getSize (int &w, int &h, int &d) const { w = m_w; h = m_h; d = m_d; }
};
#endif // camera_h
diff --git a/2003/i/buzz/src/camera/test_camera.cc b/2003/i/buzz/src/camera/test_camera.cc
index b81f1dc..11dac93 100644
--- a/2003/i/buzz/src/camera/test_camera.cc
+++ b/2003/i/buzz/src/camera/test_camera.cc
@@ -15,9 +15,9 @@ main (int argc, char **argv)
try
{
Camera cam;
- int w, h;
- cam.getSize (w, h);
- unsigned char *image = new unsigned char[w * h];
+ 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)
{
@@ -25,35 +25,26 @@ main (int argc, char **argv)
sprintf (s, "camera%d.gray", i);
ofstream o (s);
while (cam.read (image) == 0) sleep (1);
- o.write (image, w * h);
+ o.write (image, w * h * d);
o.close ();
- for (int j = 0; j < w * h; j += 4)
+ if (d == 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];
+ 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 ();
}
- 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)
+ for (int j = 0; j < w * h; ++j)
{
- int t = (int) image[j + 2] >> 2 - (int) image[j + 1] >> 2;
+ int t = (int) image[j * 4 + 2] >> 2 - (int) image[j * 4 + 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);