[mousetrap/ng] Changed pthread for g_timeout_add



commit f40d8157bae48b080c7f36cd55e01c953047fb1e
Author: Flavio Percoco Premoli <flaper87 gmail com>
Date:   Sun Nov 1 11:10:10 2009 +0100

    Changed pthread for g_timeout_add

 src/mousetrap/ocvfw/.cproject          |    3 +-
 src/mousetrap/ocvfw/dev/Camera.cpp     |   75 --------------------------------
 src/mousetrap/ocvfw/dev/Camera.h       |   61 --------------------------
 src/mousetrap/ocvfw/dev/MtpCapture.cpp |   29 ++++--------
 src/mousetrap/ocvfw/dev/MtpCapture.h   |    7 +--
 5 files changed, 14 insertions(+), 161 deletions(-)
---
diff --git a/src/mousetrap/ocvfw/.cproject b/src/mousetrap/ocvfw/.cproject
index 59c91e7..f988401 100644
--- a/src/mousetrap/ocvfw/.cproject
+++ b/src/mousetrap/ocvfw/.cproject
@@ -33,6 +33,7 @@
 <listOptionValue builtIn="false" value="/usr/local/include"/>
 <listOptionValue builtIn="false" value="/usr/include/opencv"/>
 <listOptionValue builtIn="false" value="/usr/include/python2.6"/>
+<listOptionValue builtIn="false" value="/usr/include/glib-2.0"/>
 </option>
 <inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.430443262" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
 </tool>
@@ -48,7 +49,7 @@
 </tool>
 <tool id="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug.1438019628" name="GCC C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.exe.debug"/>
 <tool id="cdt.managedbuild.tool.gnu.assembler.exe.debug.749084407" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.exe.debug">
-<option id="gnu.both.asm.option.include.paths.1015623977" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths" valueType="includePath"/>
+<option id="gnu.both.asm.option.include.paths.1015623977" name="Include paths (-I)" superClass="gnu.both.asm.option.include.paths"/>
 <inputType id="cdt.managedbuild.tool.gnu.assembler.input.2139621460" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
 </tool>
 </toolChain>
diff --git a/src/mousetrap/ocvfw/dev/MtpCapture.cpp b/src/mousetrap/ocvfw/dev/MtpCapture.cpp
index fa5bd36..4a57102 100644
--- a/src/mousetrap/ocvfw/dev/MtpCapture.cpp
+++ b/src/mousetrap/ocvfw/dev/MtpCapture.cpp
@@ -24,12 +24,12 @@
 #include "highgui.h"
 #include "MtpCamera.h"
 
-#include "pthread.h"
+#include "glib.h"
 
 #include "MtpCapture.h"
 
+int fps = 0;
 bool async = false;
-pthread_t thread;
 
 MtpCapture::MtpCapture() {
 	webcam.startCamera();
@@ -40,28 +40,19 @@ void MtpCapture::init() {
    cvReleaseCapture( &capture );
 }
 
-int MtpCapture::set_async(bool val) {
-	int rc;
+void MtpCapture::set_async(int set_fps=100, bool set_async=false) {
+	fps = set_fps;
+	async = set_async;
 
-	if ( val == true) {
-		rc = pthread_create(&thread, NULL, sync());
-
-		if (rc){
-		 printf("ERROR; return code from pthread_create() is %d\n", rc);
-		 return 1;
-		}
-	} else {
-		pthread_exit(0);
-	}
-
-	return 0;
+	if ( set_async == true)
+		g_timeout_add(set_fps, sync, NULL);
 }
 
-int MtpCapture::sync() {
+bool MtpCapture::sync() {
 	image = webcam.queryFrame();
 
 	if (!image)
-		return 1;
+		return async;
 
-	return 0;
+	return async;
 }
diff --git a/src/mousetrap/ocvfw/dev/MtpCapture.h b/src/mousetrap/ocvfw/dev/MtpCapture.h
index 58195a8..9b35760 100644
--- a/src/mousetrap/ocvfw/dev/MtpCapture.h
+++ b/src/mousetrap/ocvfw/dev/MtpCapture.h
@@ -25,8 +25,6 @@
 #include "highgui.h"
 #include "MtpCamera.h"
 
-//#include "Camera.h"
-
 #ifndef _INCL_GUARD_WEBCAM
 #define _INCL_GUARD_WEBCAM
 
@@ -44,14 +42,13 @@ public:
 
     /**
      * Synchronize the capture quering a new frame.
-     * @result returns 1 for Sucess and 0 for Failure
      */
-    int sync();
+    bool sync();
 
     /**
      * Starts/Stops the asynchronous calls to the sync method.
      */
-    int set_async
+    void set_async(int set_fps, bool set_async);
 
 private:
     /**



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