|
From: Tapio V. <aa...@us...> - 2010-05-12 02:11:45
|
Module: performous Branch: master Commit: 9552dbc7a104e7110cce99f4ff8757180fbe28f8 Author: Tapio Vierros <tap...@gm...> Date: Sun May 9 18:06:07 2010 +0300 Crude webcam background through OpenCV. * OpenCV CMake script is very much broken. * Colors are b0rked (probably wrong component order). * Webcam video framerate is very slow to keep overall fps playable. --- cmake/Modules/FindOpenCV.cmake | 28 ++++++++++++++++++++++++++++ game/CMakeLists.txt | 5 ++++- game/screen_sing.cc | 3 +++ game/screen_sing.hh | 5 +++-- game/webcam.hh | 39 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 77 insertions(+), 3 deletions(-) diff --git a/cmake/Modules/FindOpenCV.cmake b/cmake/Modules/FindOpenCV.cmake new file mode 100644 index 0000000..5f71597 --- /dev/null +++ b/cmake/Modules/FindOpenCV.cmake @@ -0,0 +1,28 @@ +# - Try to find OpenCV +# Once done, this will define +# +# OpenCV_FOUND - system has OpenCV +# OpenCV_INCLUDE_DIRS - the OpenCV include directories +# OpenCV_LIBRARIES - link these to use OpenCV +# +# See documentation on how to write CMake scripts at +# http://www.cmake.org/Wiki/CMake:How_To_Find_Libraries + +include(LibFindMacros) + + +find_path(OpenCV_INCLUDE_DIR + NAMES cv.h cv.hpp + PATHS ${OpenCV_INCLUDE_DIRS} + PATH_SUFFIXES opencv +) + +find_library(OpenCV_LIBRARY + NAMES cv highgui highgui4 libcv.a OpenCV opencv CV + PATHS ${OpenCV_PKGCONF_LIBRARY_DIRS} +) + +set(OpenCV_PROCESS_INCLUDES OpenCV_INCLUDE_DIR) +set(OpenCV_PROCESS_LIBS OpenCV_LIBRARY) +libfind_process(OpenCV) + diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index abb6532..ee87468 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -79,13 +79,16 @@ else() endif() # Find all the libs that don't require extra parameters -foreach(lib ${OUR_LIBS} SDL PangoCairo LibRSVG LibXML++ GLEW AVFormat SWScale OpenGL Z Jpeg Png) +foreach(lib ${OUR_LIBS} SDL PangoCairo LibRSVG LibXML++ GLEW AVFormat SWScale OpenGL Z Jpeg Png OpenCV) find_package(${lib} REQUIRED) include_directories(${${lib}_INCLUDE_DIRS}) list(APPEND LIBS ${${lib}_LIBRARIES}) add_definitions(${${lib}_DEFINITIONS}) endforeach(lib) + include_directories(${OpenCV_INCLUDE_DIR}) + list(APPEND LIBS ${OpenCV_cv_LIBRARY} ${OpenCV_cvcore_LIBRARY} ${OpenCV_highgui_LIBRARY}) + find_package(Gettext) if(Gettext_FOUND) include_directories(${Gettext_INCLUDE_DIRS}) diff --git a/game/screen_sing.cc b/game/screen_sing.cc index f74677a..8b0f914 100644 --- a/game/screen_sing.cc +++ b/game/screen_sing.cc @@ -307,6 +307,9 @@ void ScreenSing::draw() { theme->bg_top.draw(); } + // Webcam image + m_cam.render(time); + if( !m_dancers.empty() ) { danceLayout(time); //m_layout_singer->draw(time, LayoutSinger::LEFT); diff --git a/game/screen_sing.hh b/game/screen_sing.hh index 87cc33c..b7e4f68 100644 --- a/game/screen_sing.hh +++ b/game/screen_sing.hh @@ -15,7 +15,7 @@ #include "opengl_text.hh" #include "progressbar.hh" #include "guitargraph.hh" - +#include "webcam.hh" #include "screen_players.hh" class Players; @@ -50,7 +50,7 @@ class ScreenSing: public Screen { public: /// constructor ScreenSing(std::string const& name, Audio& audio, Capture& capture, Database& database, Backgrounds& bgs): - Screen(name), m_audio(audio), m_capture(capture), m_database(database), m_backgrounds(bgs), m_latencyAV(), m_only_singers_alive(true) + Screen(name), m_audio(audio), m_capture(capture), m_database(database), m_backgrounds(bgs), m_latencyAV(), m_only_singers_alive(true), m_cam() {} void enter(); void exit(); @@ -91,5 +91,6 @@ class ScreenSing: public Screen { boost::shared_ptr<ThemeSing> theme; AnimValue m_quitTimer; bool m_only_singers_alive; + Webcam m_cam; }; diff --git a/game/webcam.hh b/game/webcam.hh new file mode 100644 index 0000000..d90e31a --- /dev/null +++ b/game/webcam.hh @@ -0,0 +1,39 @@ + +#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() { 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(); + } + + Dimensions& dimensions() { return m_surface.dimensions; } + Dimensions const& dimensions() const { return m_surface.dimensions; } + + private: + CvCapture* m_capture; + Surface m_surface; + double m_timestamp; +}; |