[mousetrap/ng] Added color change method. Needs more work
- From: Flavio Percoco <flaper src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [mousetrap/ng] Added color change method. Needs more work
- Date: Fri, 13 Nov 2009 22:55:51 +0000 (UTC)
commit e8888c98f783250e0513c48cf3fff1ed7ec8382d
Author: Flavio Percoco Premoli <flaper87 gmail com>
Date: Sat Nov 14 01:10:59 2009 +0100
Added color change method. Needs more work
src/mousetrap/ocvfw/dev/MtpCapture.cpp | 20 ++++++++++++++++++--
src/mousetrap/ocvfw/dev/MtpCapture.h | 14 +++++++++++++-
src/mousetrap/ocvfw/dev/PyMtpCapture.cpp | 13 +++++++++++++
3 files changed, 44 insertions(+), 3 deletions(-)
---
diff --git a/src/mousetrap/ocvfw/dev/MtpCapture.cpp b/src/mousetrap/ocvfw/dev/MtpCapture.cpp
index 62b219c..edfe434 100644
--- a/src/mousetrap/ocvfw/dev/MtpCapture.cpp
+++ b/src/mousetrap/ocvfw/dev/MtpCapture.cpp
@@ -19,7 +19,8 @@
* along with Ocvfw. If not, see <http://www.gnu.org/licenses/>.
*/
-
+#include <iostream>
+#include <map>
#include <stdio.h>
#include <glibmm.h>
@@ -28,8 +29,9 @@
#include "MtpCamera.h"
#include "MtpCapture.h"
-MtpCapture::MtpCapture() {
+using namespace std;
+MtpCapture::MtpCapture() {
}
void MtpCapture::init(int set_fps, bool set_async, int idx) {
@@ -56,6 +58,7 @@ bool MtpCapture::sync() {
this->img = this->webcam.queryFrame();
if (!this->img)
+ printf("Not Image loaded\n");
return true;
return true;
@@ -79,6 +82,19 @@ IplImage *MtpCapture::rect(CvRect rect) {
return p_rect;
}
+IplImage *MtpCapture::color(int channel, int new_color, bool copy) {
+ IplImage *tmp;
+
+ tmp = cvCreateImage( cvGetSize(this->img), 8, channel);
+
+ cvCvtColor(this->img, tmp, new_color);
+
+ if (!copy)
+ this->img = tmp;
+
+ return tmp;
+}
+
IplImage *MtpCapture::resize(int width, int height, bool copy) {
IplImage *tmp;
diff --git a/src/mousetrap/ocvfw/dev/MtpCapture.h b/src/mousetrap/ocvfw/dev/MtpCapture.h
index 98ef39e..72e1695 100644
--- a/src/mousetrap/ocvfw/dev/MtpCapture.h
+++ b/src/mousetrap/ocvfw/dev/MtpCapture.h
@@ -21,6 +21,8 @@
/** @file */
+
+
#include <stdio.h>
#include <glibmm.h>
@@ -96,10 +98,20 @@ public:
* Gets and Returns the required rectangle of the image.
*
* @param rect A CvRect object with the new rectangle params.
- * @returns The pointer to the CvMat rectangle.
+ * @returns The pointer to the IplImage rectangle.
*/
IplImage *rect(CvRect rect);
+ /**
+ * Changes the color of the current image frame.
+ *
+ * @param new_color The new color to set. (Use CV globals).
+ * @param copy Whether to copy the image or not.
+ *
+ * @returns The pointer to the converted image.
+ */
+ IplImage *color(int channel, int new_color, bool copy=false);
+
private:
/**
*Opencv Capture Structure
diff --git a/src/mousetrap/ocvfw/dev/PyMtpCapture.cpp b/src/mousetrap/ocvfw/dev/PyMtpCapture.cpp
index de39b28..8ed32a8 100644
--- a/src/mousetrap/ocvfw/dev/PyMtpCapture.cpp
+++ b/src/mousetrap/ocvfw/dev/PyMtpCapture.cpp
@@ -76,6 +76,18 @@ Capture_rect(Capture *self, PyObject *args, PyObject *keywds) {
}
static PyObject *
+Capture_color(Capture *self, PyObject *args, PyObject *keywds) {
+ int new_color, channels, copy;
+
+ static char *kwlist[] = { "new_color", "channels", "copy", NULL };
+
+ PyArg_ParseTupleAndKeywords(args, keywds, "ii|i", kwlist, &channels, &new_color, ©);
+
+ return Ipl2PyDict(cap.color(channels, new_color, (copy == 0) ? false : true));
+
+}
+
+static PyObject *
Capture_resize(Capture *self, PyObject *args, PyObject *keywds) {
int width, height, copy = 0;
@@ -136,6 +148,7 @@ static PyMethodDef Capture_methods[] = {
{ "image", (PyCFunction) Capture_image, METH_NOARGS, PyDoc_STR("Returns the current IplDict object.") },
{ "resize", (PyCFunction) Capture_resize, METH_KEYWORDS, PyDoc_STR("Resizes the current image and returns it.") },
{ "rect", (PyCFunction) Capture_rect, METH_KEYWORDS, PyDoc_STR("Returns the required rectangle of the image.") },
+ { "color", (PyCFunction) Capture_color, METH_KEYWORDS, PyDoc_STR("Returns the pointer to the converted image.") },
{NULL } /* Sentinel */
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]