summaryrefslogtreecommitdiff
path: root/2003/i/buzz/src/camera
diff options
context:
space:
mode:
Diffstat (limited to '2003/i/buzz/src/camera')
-rw-r--r--2003/i/buzz/src/camera/Makefile.defs4
-rw-r--r--2003/i/buzz/src/camera/camera.cc35
-rw-r--r--2003/i/buzz/src/camera/camera.h5
-rw-r--r--2003/i/buzz/src/camera/dumpimage.cc10
-rw-r--r--2003/i/buzz/src/camera/test_camera.cc4
5 files changed, 47 insertions, 11 deletions
diff --git a/2003/i/buzz/src/camera/Makefile.defs b/2003/i/buzz/src/camera/Makefile.defs
index e9457f6..6c85f1b 100644
--- a/2003/i/buzz/src/camera/Makefile.defs
+++ b/2003/i/buzz/src/camera/Makefile.defs
@@ -1,7 +1,7 @@
TARGETS += test_camera dumpimage
LIBS += camera.a
-test_camera_SOURCES = camera.cc test_camera.cc erreur.a config.a
-dumpimage_SOURCES = camera.cc dumpimage.cc erreur.a config.a
+test_camera_SOURCES = camera.cc test_camera.cc erreur.a config.a date.a
+dumpimage_SOURCES = camera.cc dumpimage.cc erreur.a config.a date.a
camera_a_SOURCES = camera.cc
dumpimage: $(dumpimage_SOURCES:%.cc=%.o)
diff --git a/2003/i/buzz/src/camera/camera.cc b/2003/i/buzz/src/camera/camera.cc
index 5bc6920..fb1fe2d 100644
--- a/2003/i/buzz/src/camera/camera.cc
+++ b/2003/i/buzz/src/camera/camera.cc
@@ -6,6 +6,7 @@
#include "erreur/erreur.h"
#include "kernel/pbus.h"
#include "config/config.h"
+#include "date/date.h"
#include <fcntl.h>
#include <unistd.h>
@@ -15,6 +16,8 @@
#define CAM_FILE "/dev/robotcam"
+#define CAMERA_DEBUG
+
// Constructeur.
Camera::Camera ()
{
@@ -36,25 +39,33 @@ Camera::Camera ()
{
rc.getId ();
m_w = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera width " << m_w << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("height"))
{
rc.getId ();
m_h = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera height " << m_h << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("depth"))
{
rc.getId ();
m_d = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera depth " << m_d << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("cut"))
{
rc.getId ();
m_cut = rc.getNum ();
+#ifdef CAMERA_DEBUG
cout << "camera cut " << m_cut << endl;
+#endif // CAMERA_DEBUG
}
else if (rc.isId ("setup"))
{
@@ -62,14 +73,17 @@ Camera::Camera ()
addr = rc.getNum ();
data = rc.getNum ();
param.addr = addr; param.data = data;
+#ifdef CAMERA_DEBUG
cout << "camera sccbwrite 0x" << hex << addr << " 0x" << data <<
endl;
+#endif // CAMERA_DEBUG
ioctl (m_fd, CAM_SCCBWRITE, &param);
}
else
rc.noId ();
}
// Affiche les paramètres.
+#ifdef CAMERA_DEBUG
cout << hex << "camera sccbdump";
for (addr = 0; addr < 0x50; ++addr)
{
@@ -81,6 +95,8 @@ Camera::Camera ()
}
cout << endl << dec;
+#endif // CAMERA_DEBUG
+ m_lastRead = 0;
// Paramètre la taille de frame.
int hcount = m_w * m_d;
ioctl (m_fd, CAM_SETHCOUNT, &hcount);
@@ -97,28 +113,42 @@ Camera::~Camera ()
// Lit une image.
int
-Camera::read (unsigned char *image) const
+Camera::read (unsigned char *image)
{
int r;
+ int t = Date::getInstance ().start ();
+ // Attention, pas trops vite.
+ if (m_lastRead + 100 > t)
+ return 0;
+ m_lastRead = t;
// Lit les données sur la camera.
if (m_cut)
r = ::read (m_fd, image, m_cut);
if (!m_cut || r)
r = ::read (m_fd, image, m_frameSize - m_cut);
+#ifdef CAMERA_DEBUG
cout << "camera read " << r << endl;
+#endif // CAMERA_DEBUG
return r;
}
// Lit une image en RGB.
int
-Camera::readRGB (unsigned char *rgb) const
+Camera::readRGB (unsigned char *rgb)
{
int ret;
+ int t = Date::getInstance ().start ();
+ // Attention, pas trops vite.
+ if (m_lastRead + 100 > t)
+ return 0;
+ m_lastRead = t;
// 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);
+#ifdef CAMERA_DEBUG
cout << "camera read " << ret << endl;
+#endif // CAMERA_DEBUG
if (!ret) return 0;
// Positions de débuts.
unsigned char *r, *g, *b;
@@ -135,6 +165,7 @@ Camera::readRGB (unsigned char *rgb) const
*rgb++ = *b;
b += 4;
}
+ delete image;
return ret - m_cut;
}
diff --git a/2003/i/buzz/src/camera/camera.h b/2003/i/buzz/src/camera/camera.h
index 2ab1479..b6c003e 100644
--- a/2003/i/buzz/src/camera/camera.h
+++ b/2003/i/buzz/src/camera/camera.h
@@ -10,15 +10,16 @@ class Camera
int m_w, m_h, m_d;
int m_cut;
int m_frameSize;
+ int m_lastRead;
public:
// Constructeur.
Camera ();
// Destructeur.
~Camera ();
// Lit une image.
- int read (unsigned char *image) const;
+ int read (unsigned char *image);
// Lit une image en RGB.
- int readRGB (unsigned char *rgb) const;
+ int readRGB (unsigned char *rgb);
// 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; }
diff --git a/2003/i/buzz/src/camera/dumpimage.cc b/2003/i/buzz/src/camera/dumpimage.cc
index e617c6a..90909af 100644
--- a/2003/i/buzz/src/camera/dumpimage.cc
+++ b/2003/i/buzz/src/camera/dumpimage.cc
@@ -3,6 +3,7 @@
// Copyright (C) 2003 Nicolas Schodet
//
#include "camera.h"
+#include "date/date.h"
#include <iomanip>
#include <unistd.h>
@@ -11,16 +12,17 @@ int
main (int argc, char **argv)
{
Camera cam;
- int w, h;
- cam.getSize (w, h);
- unsigned char *image = new unsigned char[w * h * 3];
+ Date date;
+ int w, h, d;
+ cam.getSize (w, h, d);
+ unsigned char *image = new unsigned char[w * h * d];
cout << hex;
int j = 0;
int pixel;
while (1)
{
cout << dec << "\n- " << j++ << hex << " ---------";
- while (cam.read (image) == 0) sleep (1);
+ while (cam.read (image) == 0);
for (int i = 0; i < 256; ++i)
{
if (!(i % 16))
diff --git a/2003/i/buzz/src/camera/test_camera.cc b/2003/i/buzz/src/camera/test_camera.cc
index 11dac93..701b050 100644
--- a/2003/i/buzz/src/camera/test_camera.cc
+++ b/2003/i/buzz/src/camera/test_camera.cc
@@ -4,6 +4,7 @@
//
#include "camera.h"
#include "erreur/erreur.h"
+#include "date/date.h"
#include <fstream>
#include <unistd.h>
@@ -15,6 +16,7 @@ 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];
@@ -42,7 +44,7 @@ main (int argc, char **argv)
}
for (int j = 0; j < w * h; ++j)
{
- int t = (int) image[j * 4 + 2] >> 2 - (int) image[j * 4 + 1] >> 2;
+ int t = ((int) image[j * 4 + 2] >> 1) - ((int) image[j * 4 + 1] >> 1);
t = t > 0 ? t : -t;
image2[j] = t;
}