|
From: Yoda-JM <yo...@us...> - 2010-12-07 14:13:42
|
Module: performous
Branch: kinect
Commit: d8bb271077b7d4d40c5a6706cf627ff7ccb58930
Author: Vincent Le Ligeour <yo...@us...>
Date: Tue Dec 7 15:15:16 2010 +0100
Added kinect class header
---
game/CMakeLists.txt | 2 +-
game/kinect.cc | 102 +++++++++++++++++++++++++++++++++-----------------
game/kinect.hh | 27 +++++++++++++
game/main.cc | 9 ++++
4 files changed, 104 insertions(+), 36 deletions(-)
diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt
index e374d94..4955a62 100644
--- a/game/CMakeLists.txt
+++ b/game/CMakeLists.txt
@@ -122,7 +122,7 @@ if(NOT NO_KINECT)
if(OpenCV_FOUND AND Libfreenect_FOUND)
include_directories(${OpenCV_INCLUDE_DIRS} ${Libfreenect_INCLUDE_DIRS})
list(APPEND LIBS ${OpenCV_LIBRARIES} ${Libfreenect_LIBRARIES})
- add_definitions("-DUSE_KINEeCT")
+ add_definitions("-DUSE_KINECT")
message(STATUS "Kinect support: Enabled")
else()
message(STATUS "Kinect support: Disabled (libcv/libhighgui/libfreenect not found)")
diff --git a/game/kinect.cc b/game/kinect.cc
index a3ac786..15d5511 100644
--- a/game/kinect.cc
+++ b/game/kinect.cc
@@ -1,50 +1,84 @@
-#include "surface.hh"
-
-#include <iostream>
-#include <vector>
-#include <boost/thread/mutex.hpp>
+#include "kinect.hh"
#ifdef USE_KINECT
#include <libfreenect.hpp>
-#include <cv.h>
-#include <highgui.h>
class MyFreenectDevice : public Freenect::FreenectDevice {
public:
- MyFreenectDevice(freenect_context *_ctx, int _index) : Freenect::FreenectDevice(_ctx, _index), m_buffer_depth(FREENECT_FRAME_PIX), m_new_depth_frame(false) {
+ MyFreenectDevice(freenect_context *_ctx, int _index) : Freenect::FreenectDevice(_ctx, _index) {
}
- void RGBCallback(freenect_pixel *, uint32_t) {
+ void VideoCallback(void *, uint32_t) {
//std::cout << "RGB callback" << std::endl;
};
- void DepthCallback(void *_depth, uint32_t) {
+ void DepthCallback(void *, uint32_t) {
//std::cout << "Depth callback" << std::endl;
- boost::mutex::scoped_lock l(m_depth_mutex);
- freenect_depth *depth = static_cast<freenect_depth *>(_depth);
- std::copy(depth, depth+FREENECT_FRAME_PIX, m_buffer_depth.begin());
- m_new_depth_frame = true;
}
- bool getDepth(IplImage* depth_image) {
- boost::mutex::scoped_lock l(m_depth_mutex);
- if(m_new_depth_frame) {
- m_new_depth_frame = false;
- for(unsigned int i = 0 ; i < FREENECT_FRAME_PIX ; ++i) {
- if( m_buffer_depth[i] >= 0x07ff) {
- depth_image->imageData[i] = 0xff;
- } else {
- depth_image->imageData[i] = (2048 * 256) / (2048 - m_buffer_depth[i]);
- }
- }
- return true;
- } else {
- return false;
- }
+ private:
+};
+
+class Kinect::Impl {
+ public:
+ Impl() : m_freenect(), m_device(m_freenect.createDevice(0)) {};
+ ~Impl() {
+ stop();
+ }
+ void render() {};
+ void start() {
+ m_device.startDepth();
+ m_device.startVideo();
+ }
+ void stop() {
+ m_device.stopDepth();
+ m_device.stopVideo();
}
+ void process() {};
+ private:
+ Freenect::Freenect<MyFreenectDevice> m_freenect;
+ MyFreenectDevice& m_device;
+};
+
+#else // USE_KINECT
+
+class Kinect::Impl {
+ public:
+ Impl() {};
+ void render() {};
+ void start() {};
+ void stop() {};
+ void process() {};
private:
- std::vector<boost::uint16_t> m_buffer_depth;
- boost::mutex m_depth_mutex;
- bool m_new_depth_frame;
};
+#endif
+
+Kinect::Kinect(): self(new Impl) {}
+
+Kinect::~Kinect() {}
+
+void Kinect::render() {
+ self->render();
+}
+
+void Kinect::start() {
+ self->start();
+}
+
+void Kinect::stop() {
+ self->stop();
+}
+
+void Kinect::process() {
+ self->process();
+}
+
+/*
+#include <cv.h>
+#include <highgui.h>
+#include "surface.hh"
+
+#include <iostream>
+#include <vector>
+#include <boost/thread/mutex.hpp>
class BoundingBoxes {
public:
@@ -85,7 +119,6 @@ class BoundingBoxes {
static const int MIN_HEIGHT = 50;
};
-
class Kinect {
public:
Kinect() : m_freenect(), m_device(m_freenect.createDevice(0)), m_boxes(90, 130), m_new_image(false) {
@@ -144,5 +177,4 @@ class Kinect {
#endif
}
};
-
-#endif
+*/
diff --git a/game/kinect.hh b/game/kinect.hh
new file mode 100644
index 0000000..a2e9a4f
--- /dev/null
+++ b/game/kinect.hh
@@ -0,0 +1,27 @@
+#pragma once
+#include "config.hh"
+#include <boost/scoped_ptr.hpp>
+
+class Kinect {
+ public:
+ Kinect();
+ ~Kinect();
+
+ /// Display frame
+ void render();
+ void start();
+ void stop();
+ void process();
+ private:
+ struct Impl;
+ boost::scoped_ptr<Impl> self;
+
+ public:
+ static bool enabled() {
+ #ifdef USE_KINECT
+ return true;
+ #else
+ return false;
+ #endif
+ }
+};
diff --git a/game/main.cc b/game/main.cc
index f8de5de..de7b351 100644
--- a/game/main.cc
+++ b/game/main.cc
@@ -2,6 +2,7 @@
#include "fs.hh"
#include "screen.hh"
#include "joystick.hh"
+#include "kinect.hh"
#include "profiler.hh"
#include "songs.hh"
#include "backgrounds.hh"
@@ -127,9 +128,14 @@ void mainLoop(std::string const& songlist) {
Songs songs(database, songlist);
ScreenManager sm(window);
try {
+ // MidiDrums
boost::scoped_ptr<input::MidiDrums> midiDrums;
// TODO: Proper error handling...
try { midiDrums.reset(new input::MidiDrums); } catch (std::runtime_error&) {}
+ // Kinect
+ boost::scoped_ptr<Kinect> kinect;
+ // TODO: Proper error handling...
+ try { kinect.reset(new Kinect); } catch (std::runtime_error&) {}
// Load audio samples
sm.loading(_("Loading audio samples..."), 0.5);
audio.loadSample("drum bass", getPath("sounds/drum_bass.ogg"));
@@ -199,6 +205,7 @@ void mainLoop(std::string const& songlist) {
prof("fpsctrl");
// Process events for the next frame
if (midiDrums) midiDrums->process();
+ if (kinect) kinect->process();
checkEvents_SDL(sm);
prof("events");
} catch (std::runtime_error& e) {
@@ -382,6 +389,8 @@ void outputOptionalFeatureStatus() {
(Gettext::enabled() ? "Enabled" : "Disabled")
<< std::endl << " MIDI I/O: " <<
(input::MidiDrums::enabled() ? "Enabled" : "Disabled")
+ << std::endl << " Kinect: " <<
+ (Kinect::enabled() ? "Enabled" : "Disabled")
<< std::endl << " Webcam support: " <<
(Webcam::enabled() ? "Enabled" : "Disabled")
<< std::endl << std::endl;
|