aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAntoine Villeret <avilleret@users.sourceforge.net>2013-05-18 10:12:46 +0000
committerAntoine Villeret <avilleret@users.sourceforge.net>2013-05-18 10:12:46 +0000
commit4ad16e10bf38c10caf68aa1a1c4471646ba896b1 (patch)
tree6e9c47c583facb4fe8e32b45ae43c4cae346935a
parent29cd98626deb592c816b6b27aff942c8ae038d9d (diff)
add invert method to invert transformation matrix
svn path=/trunk/externals/pix_opencv/; revision=17136
-rw-r--r--pix_opencv_warpperspective.cc36
-rw-r--r--pix_opencv_warpperspective.h12
2 files changed, 34 insertions, 14 deletions
diff --git a/pix_opencv_warpperspective.cc b/pix_opencv_warpperspective.cc
index 6d1f122..e53a1dc 100644
--- a/pix_opencv_warpperspective.cc
+++ b/pix_opencv_warpperspective.cc
@@ -15,8 +15,7 @@
//
/////////////////////////////////////////////////////////
//
-// pix_opencv_warpperspective by Antoine Villeret - 2011
-//
+// pix_opencv_warpperspective by Antoine Villeret - 2011/13
@@ -117,8 +116,7 @@ void pix_opencv_warpperspective :: processRGBAImage(imageStruct &image)
// no need to copy a lot of memory, just point to it...
rgb->imageData = (char*) image.data;
cvWarpPerspective(rgb, tmp, mapMatrix, flags, cvScalar(0));
- memcpy(image.data, tmp->imageData, image.xsize*image.ysize*image.csize);
-
+ memcpy(image.data, tmp->imageData, image.xsize*image.ysize*image.csize);
}
void pix_opencv_warpperspective :: processRGBImage(imageStruct &image)
@@ -165,7 +163,7 @@ void pix_opencv_warpperspective :: processGrayImage(imageStruct &image)
void pix_opencv_warpperspective :: mapMatrixMess (int argc, t_atom *argv)
{
post("set mapMatrix");
- int i,j;
+ int i;
if (argc != 9) {
error("map matrix should be 3x3");
return;
@@ -189,6 +187,7 @@ void pix_opencv_warpperspective :: mapMatrixMess (int argc, t_atom *argv)
CV_MAT_ELEM( *mapMatrix, float, 2, 2 ) = argv[8].a_w.w_float;
/*
+ int j;
printf("---mapMatrix---\n");
for ( j = 0 ; j < 3 ; j++ ){
for( i=0 ; i<3 ; i++){
@@ -201,8 +200,7 @@ void pix_opencv_warpperspective :: mapMatrixMess (int argc, t_atom *argv)
void pix_opencv_warpperspective :: srcMatrixMess (int argc, t_atom *argv)
{
- int i,j;
- float a;
+ int i;
if ( argc % 2 ) {
error("src is should be a list of couple x/y values");
return;
@@ -230,7 +228,7 @@ void pix_opencv_warpperspective :: srcMatrixMess (int argc, t_atom *argv)
void pix_opencv_warpperspective :: dstMatrixMess (int argc, t_atom *argv)
{
- int i,j;
+ int i;
if ( argc % 2 ){
error("dstMatrix is should be a list of x/y pairs");
return;
@@ -258,6 +256,21 @@ void pix_opencv_warpperspective :: dstMatrixMess (int argc, t_atom *argv)
findhomography();
}
+void pix_opencv_warpperspective :: invertMess( int argc, t_atom *argv ){
+ if ( argc == 0 ){
+ error("invert need one argument (0|1)");
+ } else if ( argv[0].a_type != A_FLOAT ){
+ error("invert need one float argument (0|1)");
+ } else {
+ int invert = argv[0].a_w.w_float;
+ if (invert > 0){
+ flags |= cv::WARP_INVERSE_MAP;
+ } else {
+ flags ^= cv::WARP_INVERSE_MAP;
+ }
+ }
+}
+
void pix_opencv_warpperspective :: findhomography( )
{
int i,j;
@@ -291,6 +304,8 @@ void pix_opencv_warpperspective :: obj_setupCallback(t_class *classPtr)
gensym("srcMatrix"), A_GIMME, A_NULL);
class_addmethod(classPtr, (t_method)&pix_opencv_warpperspective::dstMatrixMessCallback,
gensym("dstMatrix"), A_GIMME, A_NULL);
+ class_addmethod(classPtr, (t_method)&pix_opencv_warpperspective::invertMessCallback,
+ gensym("invert"), A_GIMME, A_NULL);
}
void pix_opencv_warpperspective :: mapMatrixMessCallback(void *data, t_symbol *s, int argc, t_atom *argv)
@@ -308,3 +323,8 @@ void pix_opencv_warpperspective :: dstMatrixMessCallback(void *data, t_symbol *s
GetMyClass(data)->dstMatrixMess(argc, argv);
}
+void pix_opencv_warpperspective :: invertMessCallback(void *data, t_symbol *s, int argc, t_atom *argv)
+{
+ GetMyClass(data)->invertMess(argc, argv);
+}
+
diff --git a/pix_opencv_warpperspective.h b/pix_opencv_warpperspective.h
index 27af960..22fca5f 100644
--- a/pix_opencv_warpperspective.h
+++ b/pix_opencv_warpperspective.h
@@ -2,7 +2,7 @@
LOG
GEM - Graphics Environment for Multimedia
- Contours Bounding Rectangle detection
+ Compute homography between 2 sets on points and apply transformation to input image
Copyright (c) 1997-1999 Mark Danks. mark@danks.org
Copyright (c) Günther Geiger. geiger@epy.co.at
@@ -12,19 +12,17 @@ LOG
WARRANTIES, see the file, "GEM.LICENSE.TERMS" in this distribution.
-----------------------------------------------------------------*/
-// pix_opencv_warpperspective integration by Antoine Villeret - 2011
+// pix_opencv_warpperspective by Antoine Villeret - 2011/13
#ifndef INCLUDE_PIX_OPENCV_WARPPERSPECTIVE_H_
#define INCLUDE_PIX_OPENCV_WARPPERSPECTIVE_H_
#ifndef _EiC
-#include "cv.h"
+#include "cv.hpp"
#endif
#include "Base/GemPixObj.h"
-#define MAX_MARKERS 500
-
/*-----------------------------------------------------------------
-------------------------------------------------------------------
CLASS
@@ -64,6 +62,7 @@ class GEM_EXTERN pix_opencv_warpperspective : public GemPixObj
void mapMatrixMess (int argc, t_atom *argv);
void srcMatrixMess (int argc, t_atom *argv);
void dstMatrixMess (int argc, t_atom *argv);
+ void invertMess (int argc, t_atom *argv);
void findhomography();
// to detect changes in the image size
@@ -85,7 +84,8 @@ class GEM_EXTERN pix_opencv_warpperspective : public GemPixObj
static void mapMatrixMessCallback(void *data, t_symbol *s, int argc, t_atom *argv);
static void srcMatrixMessCallback(void *data, t_symbol *s, int argc, t_atom *argv);
static void dstMatrixMessCallback(void *data, t_symbol *s, int argc, t_atom *argv);
-
+ static void invertMessCallback(void *data, t_symbol *s, int argc, t_atom *argv);
+
/////////
// IplImage needed
IplImage *rgb, *tmp, *gray;