[mousetrap/ng] BugFix: Removed g_timeout_add



commit 7c1f6ffe314fcc6b5fe47d3ef07a10e678875a09
Author: Flavio Percoco Premoli <flaper87 gmail com>
Date:   Thu Nov 5 00:19:58 2009 +0100

    BugFix: Removed g_timeout_add

 src/mousetrap/ocvfw/dev/MtpCapture.cpp |   27 ++++++++++++++++-----------
 src/mousetrap/ocvfw/dev/MtpCapture.h   |   15 ++++++++++++++-
 src/mousetrap/ocvfw/dev/setup.py       |   16 +++++++++-------
 3 files changed, 39 insertions(+), 19 deletions(-)
---
diff --git a/src/mousetrap/ocvfw/dev/MtpCapture.cpp b/src/mousetrap/ocvfw/dev/MtpCapture.cpp
index bd849f4..7f6de47 100644
--- a/src/mousetrap/ocvfw/dev/MtpCapture.cpp
+++ b/src/mousetrap/ocvfw/dev/MtpCapture.cpp
@@ -37,34 +37,39 @@ MtpCapture::MtpCapture() {
 void MtpCapture::init(int set_fps, bool set_async, int idx) {
 	fps = set_fps;
 	async = set_async;
-	webcam.startCamera(idx);
+
+	this->syncSlot = sigc::mem_fun(*this, &MtpCapture::sync);
+	this->webcam.startCamera(idx);
 }
 
 void MtpCapture::set_async(int set_fps, bool set_async) {
 	fps = set_fps;
 	async = set_async;
 
-	if ( set_async == true)
-		g_timeout_add(set_fps, sync, NULL);
+	if ( set_async == true) {
+		this->timer = Glib::signal_timeout().connect(this->syncSlot, fps);
+	} else {
+		this->timer.disconnect();
+	}
 }
 
-gboolean MtpCapture::sync(gpointer p) {
-	image = webcam.queryFrame();
+bool MtpCapture::sync() {
+	this->image = this->webcam.queryFrame();
 
-	if (!image)
-		return TRUE;
+	if (!this->image)
+		return true;
 
-	return TRUE;
+	return true;
 }
 
 IplImage *MtpCapture::resize(int width, int height, bool copy) {
 	IplImage *tmp;
 
-	tmp = cvCreateImage(cvSize(width, height), 8, image->nChannels);
-	cvResize(image, tmp, CV_INTER_AREA);
+	tmp = cvCreateImage(cvSize(width, height), 8, this->image->nChannels);
+	cvResize(this->image, tmp, CV_INTER_AREA);
 
 	if (!copy)
-		image = tmp;
+		this->image = tmp;
 
 	return tmp;
 }
diff --git a/src/mousetrap/ocvfw/dev/MtpCapture.h b/src/mousetrap/ocvfw/dev/MtpCapture.h
index eadb380..cff893a 100644
--- a/src/mousetrap/ocvfw/dev/MtpCapture.h
+++ b/src/mousetrap/ocvfw/dev/MtpCapture.h
@@ -24,6 +24,7 @@
 #include "cv.h"
 #include "highgui.h"
 
+#include <stdio.h>
 #include <glibmm.h>
 
 #include "MtpCamera.h"
@@ -64,7 +65,7 @@ public:
 	/**
 	 * Synchronize the capture quering a new frame.
 	 */
-	gboolean sync(gpointer p);
+	bool sync();
 
 	/**
 	 * Starts/Stops the asynchronous calls to the sync method.
@@ -81,5 +82,17 @@ private:
 	 * Camera Object
 	 */
 	MtpCamera webcam;
+
+
+	/**
+	 * Timer Slot
+	 */
+	sigc::slot<bool> syncSlot;
+
+	/**
+	 * The timer
+	 */
+	sigc::connection timer;
+
 };
 
diff --git a/src/mousetrap/ocvfw/dev/setup.py b/src/mousetrap/ocvfw/dev/setup.py
index d246713..cc36202 100644
--- a/src/mousetrap/ocvfw/dev/setup.py
+++ b/src/mousetrap/ocvfw/dev/setup.py
@@ -2,12 +2,14 @@ import os
 from distutils.core import setup                                                 
 from distutils.core import Extension
 
-os.environ['CC'] = 'g++' 
-os.environ['CXX'] = 'g++'
-os.environ['CPP'] = 'g++'
-os.environ['LDSHARED'] = 'g++'
+os.environ['CC'] = 'g++ -shared -fpic' 
+os.environ['CXX'] = 'g++ -shared -fpic'
+os.environ['CPP'] = 'g++ -shared -fpic'
+os.environ['LDSHARED'] = 'g++ -shared -fpic'
 
-module2 = Extension('capture',
+extra_options = {'build': ['-shared', '-fpic']}
+
+module = Extension('capture',
                     libraries = ['cv', 'highgui', 'cxcore', 'cvaux', 'ml', 'gobject-2.0', 'gmodule-2.0', 'gthread-2.0', 'rt', 'xml2', 'glib-2.0', 'glibmm-2.4', 'sigc-2.0'],
                     include_dirs=['/usr/include/opencv', 
                                   '/usr/include/glib-2.0/', 
@@ -18,8 +20,8 @@ module2 = Extension('capture',
                                   '/usr/include/sigc++-2.0/',
                                   '/usr/include/sigc++-2.0/sigc++/',
                                   '/usr/lib/sigc++-2.0/include'],
-                    sources = ['MtpCamera.cpp', 'MtpCapture.cpp', 'PyMtpCapture.cpp'])
+                    sources = ['MtpCamera.cpp', 'MtpCapture.cpp', 'PyMtpCapture.cpp'],)
 
 setup(name = 'capture',
       version = '0.1',
-      ext_modules = [module2])
\ No newline at end of file
+      ext_modules = [module])
\ No newline at end of file



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]