|
From: Tapio V. <aa...@us...> - 2010-05-16 16:31:02
|
Module: performous
Branch: instrumentgraph
Commit: e1a820aafc163ffebd132e6b0e0d2aee48ea6870
Author: Tapio Vierros <tap...@gm...>
Date: Sun May 9 20:53:37 2010 +0300
Refactor webcam class.
---
game/webcam.cc | 24 ++++++++++++++++++++++++
game/webcam.hh | 24 +++++-------------------
2 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/game/webcam.cc b/game/webcam.cc
new file mode 100644
index 0000000..51cbb00
--- /dev/null
+++ b/game/webcam.cc
@@ -0,0 +1,24 @@
+#include <iostream>
+
+#include "webcam.hh"
+
+Webcam::Webcam(int cam_id): m_capture(NULL), m_timestamp(0) {
+ m_capture = cvCaptureFromCAM(cam_id);
+ if (!m_capture) {
+ std::cout << "Could not initialize webcam capturing!" << std::endl;
+ return;
+ }
+}
+
+
+void Webcam::render(double time) {
+ if (!m_capture) return;
+ IplImage* frame = 0;
+ if (time > m_timestamp + 0.333) {
+ frame = cvQueryFrame(m_capture);
+ if (!frame) return;
+ m_surface.load(frame->width, frame->height, pix::RGB, (const unsigned char*)frame->imageData);
+ m_timestamp = time;
+ }
+ m_surface.draw();
+}
diff --git a/game/webcam.hh b/game/webcam.hh
index d90e31a..33caad1 100644
--- a/game/webcam.hh
+++ b/game/webcam.hh
@@ -2,32 +2,18 @@
#include <cv.h>
#include <highgui.h>
-#include "glutil.hh"
#include "surface.hh"
class Webcam {
public:
- Webcam(int cam_id = -1): m_capture(NULL), m_timestamp(0) {
- m_capture = cvCaptureFromCAM(cam_id);
- if (!m_capture) {
- std::cout << "Could not initialize capturing!" << std::endl;
- return;
- }
- }
+ Webcam(int cam_id = -1);
~Webcam() { cvReleaseCapture(&m_capture); }
- void render(double time) {
- if (!m_capture) return;
- IplImage* frame = 0;
- if (time > m_timestamp + 0.5) {
- frame = cvQueryFrame(m_capture);
- if (!frame) return;
- m_surface.load(frame->width, frame->height, pix::RGB, (const unsigned char*)frame->imageData);
- m_timestamp = time;
- }
- m_surface.draw();
- }
+ /// Is good?
+ bool operator()() { return m_capture != 0; }
+
+ void render(double time);
Dimensions& dimensions() { return m_surface.dimensions; }
Dimensions const& dimensions() const { return m_surface.dimensions; }
|