From 4ad16e10bf38c10caf68aa1a1c4471646ba896b1 Mon Sep 17 00:00:00 2001 From: Antoine Villeret Date: Sat, 18 May 2013 10:12:46 +0000 Subject: add invert method to invert transformation matrix svn path=/trunk/externals/pix_opencv/; revision=17136 --- pix_opencv_warpperspective.cc | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) (limited to 'pix_opencv_warpperspective.cc') 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); +} + -- cgit v1.2.1