[mousetrap/ng] Added MtpCapture and changed camera name to MtpCamera



commit a60721c6fe32a585da6de5d75b93d583bf5d24e6
Author: Flavio Percoco Premoli <flaper87 gmail com>
Date:   Sat Oct 31 21:34:31 2009 +0100

    Added MtpCapture and changed camera name to MtpCamera

 src/mousetrap/ocvfw/dev/MtpCamera.cpp  |   80 ++++++++++++++++++++++++++++++++
 src/mousetrap/ocvfw/dev/MtpCamera.h    |   69 +++++++++++++++++++++++++++
 src/mousetrap/ocvfw/dev/MtpCapture.cpp |   67 ++++++++++++++++++++++++++
 src/mousetrap/ocvfw/dev/MtpCapture.h   |   68 +++++++++++++++++++++++++++
 4 files changed, 284 insertions(+), 0 deletions(-)
---
diff --git a/src/mousetrap/ocvfw/dev/MtpCamera.cpp b/src/mousetrap/ocvfw/dev/MtpCamera.cpp
new file mode 100644
index 0000000..c37e829
--- /dev/null
+++ b/src/mousetrap/ocvfw/dev/MtpCamera.cpp
@@ -0,0 +1,80 @@
+/**
+ * Ocvfw
+ *
+ * Copyright 2009 Flavio Percoco Premoli
+ * Copyright (C) 2009 Rohan Anil (rohan anil gmail com)
+ *
+ * This file is part of Ocvfw.
+ *
+ * Ocvfw is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2 as published
+ * by the Free Software Foundation.
+ *
+ * Ocvfw is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Ocvfw.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "cv.h"
+#include "highgui.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+#include <math.h>
+#include <float.h>
+#include <limits.h>
+#include <time.h>
+#include <ctype.h>
+
+static IplImage * orginalFrame=0;
+IplImage * frame=0;
+IplImage * frame_copy=0;
+
+MtpCamera::MtpCamera()
+{
+
+}
+
+void MtpCamera::stopCamera()
+{
+   if(capture!=0)
+   cvReleaseCapture( &capture );
+}
+int MtpCamera::startCamera(int idx)
+{
+    capture = cvCaptureFromCAM(idx);
+
+    if(capture==0)
+    	return 0;
+    else
+    	return 1;
+}
+
+IplImage *MtpCamera::queryFrame()
+{
+    orginalFrame = cvQueryFrame( capture );
+    if (orginalFrame==NULL)
+    	return 0;
+
+    frame = cvCreateImage( cvSize(IMAGE_WIDTH,IMAGE_HEIGHT),IPL_DEPTH_8U, orginalFrame->nChannels );
+    cvResize(orginalFrame,frame, CV_INTER_LINEAR);
+
+    if ( !frame )
+        return 0;
+
+    frame_copy = cvCreateImage( cvSize(frame->width,frame->height),IPL_DEPTH_8U, frame->nChannels );
+
+    if ( frame->origin == IPL_ORIGIN_TL )
+        cvCopy( frame, frame_copy, 0 );
+    else
+        cvFlip( frame, frame_copy, 0 );
+
+    cvReleaseImage(&frame);
+
+    return frame_copy;
+}
diff --git a/src/mousetrap/ocvfw/dev/MtpCamera.h b/src/mousetrap/ocvfw/dev/MtpCamera.h
new file mode 100644
index 0000000..19ce814
--- /dev/null
+++ b/src/mousetrap/ocvfw/dev/MtpCamera.h
@@ -0,0 +1,69 @@
+/**
+ * Ocvfw
+ *
+ * Copyright 2009 Flavio Percoco Premoli
+ * Copyright (C) 2009 Rohan Anil (rohan anil gmail com)
+ *
+ * This file is part of Ocvfw.
+ *
+ * Ocvfw is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2 as published
+ * by the Free Software Foundation.
+ *
+ * Ocvfw is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Ocvfw.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** @file */
+
+#include "cv.h"
+#include "highgui.h"
+#ifndef _INCL_GUARD_WEBCAM
+#define _INCL_GUARD_WEBCAM
+/**
+* OpenCV Webcam Class. This class wraps over the opencv Image Query Functions.
+*/
+class MtpCamera
+{
+public:
+    /**
+    *The Constructor
+    *Currently does nothing
+    */
+	MtpCamera(void);
+
+	/**
+     *Query Image From Webcam
+     * result Image From the Webcam
+     */
+    IplImage *queryFrame();
+
+    /**
+     *Initialize Webcam for Querying Image
+     * result returns 1 for Sucess and 0 for Failure
+     */
+    int startCamera(int idx);
+
+    /**
+     *Deinitialize Webcam Structures
+     */
+    void stopCamera();
+
+
+private:
+    /**
+    *Opencv Capture Structure
+    */
+    CvCapture* capture;
+
+    /**
+     * The camera index.
+     */
+    int idx;
+};
+#endif
diff --git a/src/mousetrap/ocvfw/dev/MtpCapture.cpp b/src/mousetrap/ocvfw/dev/MtpCapture.cpp
new file mode 100644
index 0000000..fa5bd36
--- /dev/null
+++ b/src/mousetrap/ocvfw/dev/MtpCapture.cpp
@@ -0,0 +1,67 @@
+/**
+ * Ocvfw
+ *
+ * Copyright 2009 Flavio Percoco Premoli
+ * Copyright (C) 2009 Rohan Anil (rohan anil gmail com)
+ *
+ * This file is part of Ocvfw.
+ *
+ * Ocvfw is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2 as published
+ * by the Free Software Foundation.
+ *
+ * Ocvfw is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Ocvfw.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "cv.h"
+#include "highgui.h"
+#include "MtpCamera.h"
+
+#include "pthread.h"
+
+#include "MtpCapture.h"
+
+bool async = false;
+pthread_t thread;
+
+MtpCapture::MtpCapture() {
+	webcam.startCamera();
+}
+
+void MtpCapture::init() {
+   if(capture!=0)
+   cvReleaseCapture( &capture );
+}
+
+int MtpCapture::set_async(bool val) {
+	int rc;
+
+	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;
+}
+
+int MtpCapture::sync() {
+	image = webcam.queryFrame();
+
+	if (!image)
+		return 1;
+
+	return 0;
+}
diff --git a/src/mousetrap/ocvfw/dev/MtpCapture.h b/src/mousetrap/ocvfw/dev/MtpCapture.h
new file mode 100644
index 0000000..58195a8
--- /dev/null
+++ b/src/mousetrap/ocvfw/dev/MtpCapture.h
@@ -0,0 +1,68 @@
+/**
+ * Ocvfw
+ *
+ * Copyright 2009 Flavio Percoco Premoli
+ * Copyright (C) 2009 Rohan Anil (rohan anil gmail com)
+ *
+ * This file is part of Ocvfw.
+ *
+ * Ocvfw is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2 as published
+ * by the Free Software Foundation.
+ *
+ * Ocvfw is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Ocvfw.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+/** @file */
+
+#include "cv.h"
+#include "highgui.h"
+#include "MtpCamera.h"
+
+//#include "Camera.h"
+
+#ifndef _INCL_GUARD_WEBCAM
+#define _INCL_GUARD_WEBCAM
+
+/**
+ * OpenCV Webcam Class. This class wraps over the opencv Image Query Functions.
+ */
+class MtpCapture
+{
+public:
+    /**
+     *The Constructor
+     *Currently does nothing
+     */
+	MtpCapture(void);
+
+    /**
+     * Synchronize the capture quering a new frame.
+     * @result returns 1 for Sucess and 0 for Failure
+     */
+    int sync();
+
+    /**
+     * Starts/Stops the asynchronous calls to the sync method.
+     */
+    int set_async
+
+private:
+    /**
+     *Opencv Capture Structure
+     */
+    IplImage* image;
+
+    /**
+     * Camera Object
+     */
+    MtpCamera webcam;
+};
+#endif
+



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