aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN.N. <sevyves@users.sourceforge.net>2010-08-08 17:23:44 +0000
committerN.N. <sevyves@users.sourceforge.net>2010-08-08 17:23:44 +0000
commit84e702368750bba07f231178e1264c2ea4e3929c (patch)
tree22db45e6eb41305abd19756d917c2478583f49ec
parent15ec89b8acb5e2fb3f41b45cc37fd3c585bdb38b (diff)
compare contours and points to the closest object
svn path=/trunk/externals/pix_opencv/; revision=13775
-rw-r--r--pix_opencv_contours_boundingrect-help.pd148
-rw-r--r--pix_opencv_contours_boundingrect.cc166
-rw-r--r--pix_opencv_contours_boundingrect.h10
-rw-r--r--pix_opencv_lk-help.pd153
-rw-r--r--pix_opencv_lk.cc154
-rw-r--r--pix_opencv_surf-help.pd72
-rw-r--r--pix_opencv_surf.cc171
7 files changed, 513 insertions, 361 deletions
diff --git a/pix_opencv_contours_boundingrect-help.pd b/pix_opencv_contours_boundingrect-help.pd
index d2daeae..0aa1fff 100644
--- a/pix_opencv_contours_boundingrect-help.pd
+++ b/pix_opencv_contours_boundingrect-help.pd
@@ -1,11 +1,9 @@
-#N canvas 625 108 1040 775 10;
+#N canvas 277 66 1040 775 10;
#X obj 580 466 cnv 15 550 250 empty empty empty 20 12 0 14 -24198 -66577
0;
#X floatatom 717 652 5 0 0 0 - - -;
#X obj 600 684 pix_opencv_contours_boundingrect;
-#X text 752 648 min area in pixels (default 1);
#X floatatom 803 666 5 0 0 0 - - -;
-#X text 841 665 max area in pixels (default 76800);
#X floatatom 733 816 5 0 0 0 - - -;
#X floatatom 768 816 5 0 0 0 - - -;
#X floatatom 805 816 5 0 0 0 - - -;
@@ -27,8 +25,7 @@ silouets of the objects you want to track.;
#X floatatom 747 529 5 0 0 0 - - -;
#X floatatom 771 553 5 0 0 0 - - -;
#X msg 683 550 ftolerance \$1;
-#X text 790 528 maximum move of a countour ( default 10 );
-#X text 807 551 frame tolerance for identification ( default 5 );
+#X text 808 551 frame tolerance for identification ( default 5 );
#X text 30 138 pix_opencv_contours_boundingrect :: Calculates up-right
bounding rectangle of all contours of a binary image.;
#X text 29 211 This object considers a contour to be analyzed any group
@@ -90,7 +87,7 @@ to transform the contours of the shapes to be analyzed..;
#X connect 10 0 7 0;
#X connect 10 2 9 0;
#X restore 43 84 pd gemwin;
-#X msg 43 66 create;
+#X msg 43 66 destroy;
#X obj 444 838 pix_texture;
#X obj 444 866 square 2;
#X obj 596 371 separator;
@@ -103,7 +100,7 @@ to transform the contours of the shapes to be analyzed..;
#X msg 727 120 open \$1;
#X obj 715 229 pix_film;
#X msg 733 163 auto \$1;
-#X obj 733 145 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0
+#X obj 733 145 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1
1;
#X text 41 46 Create window and render;
#X msg 828 146 colorspace RGBA;
@@ -143,8 +140,8 @@ to transform the contours of the shapes to be analyzed..;
#X connect 11 0 8 0;
#X connect 11 1 9 0;
#X connect 11 1 6 0;
-#X restore 537 299 pd vswitch;
-#X obj 605 299 tgl 15 0 empty load empty 17 7 0 10 -262144 -1 -1 0
+#X restore 536 267 pd vswitch;
+#X obj 604 267 tgl 15 0 empty load empty 17 7 0 10 -262144 -1 -1 0
1;
#X obj 478 227 pix_video;
#X obj 478 39 gemhead;
@@ -159,69 +156,76 @@ to transform the contours of the shapes to be analyzed..;
#X obj 743 865 unpack 0 0 0 0 0;
#X text 883 816 ( First contour ) Xorigin Yorigin Width Height;
#X text 895 892 ( Second contour ) Xorigin Yorigin Width Height;
-#X obj 596 439 pix_opencv_bgsubstract;
+#X text 752 648 min area in pixels (default 10x10);
+#X text 840 664 max area in pixels (default 320x240);
+#X obj 536 296 pix_resize 320 240;
+#X text 790 528 maximum move of a countour ( default 20 );
+#X obj 596 439 pix_opencv_threshold;
+#X floatatom 731 441 5 0 0 0 - - -;
#X connect 1 0 2 1;
-#X connect 2 0 41 0;
-#X connect 2 1 11 0;
-#X connect 2 2 29 0;
-#X connect 4 0 2 2;
-#X connect 10 0 6 0;
-#X connect 10 1 7 0;
-#X connect 10 2 8 0;
-#X connect 10 3 9 0;
-#X connect 11 0 10 0;
-#X connect 11 1 79 0;
-#X connect 14 0 2 0;
-#X connect 15 0 14 0;
-#X connect 17 0 19 0;
-#X connect 19 0 2 0;
-#X connect 20 0 2 0;
-#X connect 21 0 20 0;
-#X connect 22 0 23 0;
-#X connect 23 0 2 0;
-#X connect 31 0 2 0;
-#X connect 32 0 31 0;
-#X connect 33 0 35 0;
-#X connect 34 0 37 0;
-#X connect 35 0 2 0;
-#X connect 37 0 2 0;
-#X connect 40 0 54 0;
+#X connect 2 0 38 0;
+#X connect 2 1 9 0;
+#X connect 2 2 26 0;
+#X connect 3 0 2 2;
+#X connect 8 0 4 0;
+#X connect 8 1 5 0;
+#X connect 8 2 6 0;
+#X connect 8 3 7 0;
+#X connect 9 0 8 0;
+#X connect 9 1 76 0;
+#X connect 12 0 2 0;
+#X connect 13 0 12 0;
+#X connect 15 0 17 0;
+#X connect 17 0 2 0;
+#X connect 18 0 2 0;
+#X connect 19 0 18 0;
+#X connect 20 0 21 0;
+#X connect 21 0 2 0;
+#X connect 28 0 2 0;
+#X connect 29 0 28 0;
+#X connect 30 0 32 0;
+#X connect 31 0 34 0;
+#X connect 32 0 2 0;
+#X connect 34 0 2 0;
+#X connect 37 0 51 0;
+#X connect 38 0 39 0;
#X connect 41 0 42 0;
-#X connect 44 0 45 0;
-#X connect 45 0 44 0;
-#X connect 46 0 47 0;
-#X connect 48 0 66 0;
-#X connect 49 0 52 0;
+#X connect 42 0 41 0;
+#X connect 43 0 44 0;
+#X connect 45 0 63 0;
+#X connect 46 0 49 0;
+#X connect 47 0 48 0;
+#X connect 48 0 51 1;
+#X connect 49 0 50 0;
#X connect 50 0 51 0;
-#X connect 51 0 54 1;
-#X connect 52 0 53 0;
-#X connect 53 0 54 0;
-#X connect 54 0 67 1;
-#X connect 54 2 50 0;
-#X connect 55 0 54 0;
-#X connect 56 0 55 0;
-#X connect 58 0 54 0;
-#X connect 58 0 69 0;
-#X connect 59 0 54 0;
-#X connect 60 0 54 0;
-#X connect 61 0 58 0;
-#X connect 61 0 56 0;
-#X connect 62 0 48 0;
-#X connect 63 0 65 0;
-#X connect 64 0 63 0;
-#X connect 65 0 46 0;
-#X connect 66 0 82 0;
-#X connect 67 0 62 0;
-#X connect 67 0 64 0;
-#X connect 68 0 67 2;
-#X connect 69 0 67 0;
-#X connect 70 0 69 0;
-#X connect 71 0 69 0;
-#X connect 72 0 69 0;
-#X connect 73 0 69 0;
-#X connect 74 0 69 0;
-#X connect 79 0 75 0;
-#X connect 79 1 76 0;
-#X connect 79 2 77 0;
-#X connect 79 3 78 0;
-#X connect 82 0 2 0;
+#X connect 51 0 64 1;
+#X connect 51 2 47 0;
+#X connect 52 0 51 0;
+#X connect 53 0 52 0;
+#X connect 55 0 51 0;
+#X connect 55 0 66 0;
+#X connect 56 0 51 0;
+#X connect 57 0 51 0;
+#X connect 58 0 55 0;
+#X connect 58 0 53 0;
+#X connect 59 0 45 0;
+#X connect 60 0 62 0;
+#X connect 61 0 60 0;
+#X connect 62 0 43 0;
+#X connect 63 0 83 0;
+#X connect 64 0 81 0;
+#X connect 65 0 64 2;
+#X connect 66 0 64 0;
+#X connect 67 0 66 0;
+#X connect 68 0 66 0;
+#X connect 69 0 66 0;
+#X connect 70 0 66 0;
+#X connect 71 0 66 0;
+#X connect 76 0 72 0;
+#X connect 76 1 73 0;
+#X connect 76 2 74 0;
+#X connect 76 3 75 0;
+#X connect 81 0 59 0;
+#X connect 81 0 61 0;
+#X connect 83 0 2 0;
+#X connect 84 0 83 2;
diff --git a/pix_opencv_contours_boundingrect.cc b/pix_opencv_contours_boundingrect.cc
index fa35c82..42b978c 100644
--- a/pix_opencv_contours_boundingrect.cc
+++ b/pix_opencv_contours_boundingrect.cc
@@ -34,16 +34,16 @@ pix_opencv_contours_boundingrect :: pix_opencv_contours_boundingrect()
inlet_new(this->x_obj, &this->x_obj->ob_pd, gensym("float"), gensym("maxarea"));
m_dataout = outlet_new(this->x_obj, 0);
m_countout = outlet_new(this->x_obj, 0);
- minarea = 1;
+ minarea = 10*10;
maxarea = 320*240;
- comp_xsize = 0;
- comp_ysize = 0;
+ comp_xsize = 320;
+ comp_ysize = 240;
orig = NULL;
gray = NULL;
cnt_img = NULL;
rgb = NULL;
x_ftolerance = 5;
- x_mmove = 10;
+ x_mmove = 20;
x_nightmode = 0;
x_show = 0;
x_draw = 1;
@@ -72,7 +72,7 @@ pix_opencv_contours_boundingrect :: ~pix_opencv_contours_boundingrect()
// Mark a contour
//
/////////////////////////////////////////////////////////
-int pix_opencv_contours_boundingrect :: mark(float fx, float fy )
+int pix_opencv_contours_boundingrect :: mark(float fx, float fy, float fw, float fh )
{
int i;
@@ -85,8 +85,10 @@ int pix_opencv_contours_boundingrect :: mark(float fx, float fy )
{
if ( x_xmark[i] == -1 )
{
- x_xmark[i] = (int)fx;
- x_ymark[i] = (int)fy;
+ x_xmark[i] = (float)(fx+(fw/2));
+ x_ymark[i] = (float)(fy+(fh/2));
+ x_wmark[i] = (int)fw;
+ x_hmark[i] = (int)fh;
x_found[i] = x_ftolerance;
return i;
}
@@ -104,10 +106,13 @@ void pix_opencv_contours_boundingrect :: processRGBAImage(imageStruct &image)
{
unsigned char *pixels = image.data;
char tindex[4];
- int im = 0; // Indicator of markers.
+ int im = 0, i, ic; // Indicator of markers.
+ int oi, found;
+ float dist, odist; // Distances
t_atom rlist[5];
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig))
+ {
this->comp_xsize = image.xsize;
this->comp_ysize = image.ysize;
@@ -155,43 +160,58 @@ void pix_opencv_contours_boundingrect :: processRGBAImage(imageStruct &image)
}
}
- int i = 0; // Indicator of cycles.
- int ic = 0; // Indicator of contours.
+ i = 0; // Indicator of cycles.
+ ic = 0; // Indicator of contours.
for( ; contours != 0; contours = contours->h_next )
{
int count = contours->total; // This is number point in contour
CvRect rect;
- int oi, found;
rect = cvContourBoundingRect( contours, 1);
- if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) ) {
+
+ if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) )
+ {
found = 0;
oi = -1;
+ dist=(comp_xsize>comp_ysize)?comp_xsize:comp_ysize;
+
for ( im=0; im<MAX_MARKERS; im++ )
{
- // check if the object is already known
- if ( ( abs( rect.x - x_xmark[im] ) < x_mmove ) && ( abs( rect.y - x_ymark[im] ) < x_mmove ) )
+
+ if ( x_xmark[im]==-1 ) continue; // no contours
+
+ odist=sqrt( pow( ((float)rect.x+rect.width/2)-x_xmark[im], 2 ) + pow( ((float)rect.y+rect.height/2)-x_ymark[im], 2 ) );
+
+ // search for the closest known contour
+ // that is likely to be this one
+ if ( odist < x_mmove )
{
- oi=im;
- found=1;
- x_found[im] = x_ftolerance;
- x_xmark[im] = rect.x;
- x_ymark[im] = rect.y;
- break;
+ if ( odist < dist )
+ {
+ found=1;
+ oi=im;
+ x_xmark[oi] = (float)(rect.x+rect.width/2);
+ x_ymark[oi] = (float)(rect.y+rect.height/2);
+ x_wmark[oi] = (int)rect.width;
+ x_hmark[oi] = (int)rect.height;
+ x_found[oi] = x_ftolerance;
+ dist=odist;
+ }
}
}
+
// new object detected
if ( !found )
{
- oi = this->mark(rect.x, rect.y );
+ oi = this->mark(rect.x, rect.y, rect.width, rect.height );
}
if ( x_draw )
{
cvRectangle( orig, cvPoint(rect.x,rect.y), cvPoint(rect.x+rect.width,rect.y+rect.height), CV_RGB(255,0,0), 2, 8 , 0 );
sprintf( tindex, "%d", oi );
- cvPutText( orig, tindex, cvPoint(rect.x,rect.y), &font, CV_RGB(255,255,255));
+ cvPutText( orig, tindex, cvPoint(x_xmark[oi],x_ymark[oi]), &font, CV_RGB(255,0,0));
}
if ( x_show )
@@ -210,6 +230,7 @@ void pix_opencv_contours_boundingrect :: processRGBAImage(imageStruct &image)
ic++;
}
}
+
outlet_float( m_countout, ic );
// delete lost objects
@@ -241,8 +262,11 @@ void pix_opencv_contours_boundingrect :: processRGBImage(imageStruct &image)
char tindex[4];
t_atom rlist[5];
int im = 0; // Indicator of markers.
+ int oi, found;
+ float dist, odist; // Distances
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!rgb)) {
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!rgb))
+ {
this->comp_xsize = image.xsize;
this->comp_ysize = image.ysize;
@@ -291,37 +315,51 @@ void pix_opencv_contours_boundingrect :: processRGBImage(imageStruct &image)
{
int count = contours->total; // This is number point in contour
CvRect rect;
- int oi, found;
rect = cvContourBoundingRect( contours, 1);
- if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) ) {
+ if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) )
+ {
found = 0;
oi = -1;
+ dist=(comp_xsize>comp_ysize)?comp_xsize:comp_ysize;
+
for ( im=0; im<MAX_MARKERS; im++ )
{
- // check if the object is already known
- if ( ( abs( rect.x - x_xmark[im] ) < x_mmove ) && ( abs( rect.y - x_ymark[im] ) < x_mmove ) )
+
+ if ( x_xmark[im]==-1 ) continue;
+
+ odist=sqrt( pow( ((float)rect.x+rect.width/2)-x_xmark[im], 2 ) + pow( ((float)rect.y+rect.height/2)-x_ymark[im], 2 ) );
+
+ // search for the closest known contour
+ // that is likely to be this one
+ if ( odist < x_mmove )
{
- oi=im;
- found=1;
- x_found[im] = x_ftolerance;
- x_xmark[im] = rect.x;
- x_ymark[im] = rect.y;
- break;
+ if ( odist < dist )
+ {
+ found=1;
+ oi=im;
+ x_xmark[oi] = (float)(rect.x+rect.width/2);
+ x_ymark[oi] = (float)(rect.y+rect.height/2);
+ x_wmark[oi] = (int)rect.width;
+ x_hmark[oi] = (int)rect.height;
+ x_found[oi] = x_ftolerance;
+ dist=odist;
+ }
}
}
+
// new object detected
if ( !found )
{
- oi = this->mark(rect.x, rect.y );
+ oi = this->mark(rect.x, rect.y, rect.width, rect.height );
}
if ( x_draw )
{
cvRectangle( rgb, cvPoint(rect.x,rect.y), cvPoint(rect.x+rect.width,rect.y+rect.height), CV_RGB(255,0,0), 2, 8 , 0 );
sprintf( tindex, "%d", oi );
- cvPutText( rgb, tindex, cvPoint(rect.x,rect.y), &font, CV_RGB(255,255,255));
+ cvPutText( rgb, tindex, cvPoint(x_xmark[oi],x_ymark[oi]), &font, CV_RGB(255,0,0));
}
if ( x_show )
@@ -374,8 +412,11 @@ void pix_opencv_contours_boundingrect :: processGrayImage(imageStruct &image)
char tindex[4];
t_atom rlist[5];
int im = 0; // Indicator of markers.
+ int oi, found;
+ float dist, odist; // Distances
- if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig)) {
+ if ((this->comp_xsize!=image.xsize)||(this->comp_ysize!=image.ysize)||(!orig))
+ {
this->comp_xsize = image.xsize;
this->comp_ysize = image.ysize;
@@ -427,37 +468,51 @@ void pix_opencv_contours_boundingrect :: processGrayImage(imageStruct &image)
{
int count = contours->total; // This is number point in contour
CvRect rect;
- int oi, found;
rect = cvContourBoundingRect( contours, 1);
- if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) ) {
+ if ( ( (rect.width*rect.height) > minarea ) && ( (rect.width*rect.height) < maxarea ) )
+ {
found = 0;
oi = -1;
+ dist=(comp_xsize>comp_ysize)?comp_xsize:comp_ysize;
+
for ( im=0; im<MAX_MARKERS; im++ )
{
- // check if the object is already known
- if ( ( abs( rect.x - x_xmark[im] ) < x_mmove ) && ( abs( rect.y - x_ymark[im] ) < x_mmove ) )
+
+ if ( x_xmark[im]==-1 ) continue;
+
+ odist=sqrt( pow( ((float)rect.x+rect.width/2)-x_xmark[im], 2 ) + pow( ((float)rect.y+rect.height/2)-x_ymark[im], 2 ) );
+
+ // search for the closest known contour
+ // that is likely to be this one
+ if ( odist < x_mmove )
{
- oi=im;
- found=1;
- x_found[im] = x_ftolerance;
- x_xmark[im] = rect.x;
- x_ymark[im] = rect.y;
- break;
+ if ( odist < dist )
+ {
+ found=1;
+ oi=im;
+ x_xmark[oi] = (float)(rect.x+rect.width/2);
+ x_ymark[oi] = (float)(rect.y+rect.height/2);
+ x_wmark[oi] = (int)rect.width;
+ x_hmark[oi] = (int)rect.height;
+ x_found[oi] = x_ftolerance;
+ dist=odist;
+ }
}
}
+
// new object detected
if ( !found )
{
- oi = this->mark(rect.x, rect.y );
+ oi = this->mark(rect.x, rect.y, rect.width, rect.height );
}
if ( x_draw )
{
cvRectangle( cnt_img, cvPoint(rect.x,rect.y), cvPoint(rect.x+rect.width,rect.y+rect.height), cvScalarAll(255), 2, 8 , 0 );
sprintf( tindex, "%d", oi );
- cvPutText( cnt_img, tindex, cvPoint(rect.x,rect.y), &font, cvScalarAll(255));
+ cvPutText( cnt_img, tindex, cvPoint(x_xmark[oi],x_ymark[oi]), &font, cvScalarAll(255));
}
if ( x_show )
@@ -476,7 +531,8 @@ void pix_opencv_contours_boundingrect :: processGrayImage(imageStruct &image)
ic++;
}
}
- outlet_float( m_countout, i );
+
+ outlet_float( m_countout, ic );
// delete lost objects
for ( im=0; im<MAX_MARKERS; im++ )
@@ -593,13 +649,15 @@ void pix_opencv_contours_boundingrect :: deleteMark(t_floatarg findex )
{
int i;
- if ( ( findex < 1.0 ) || ( findex > MAX_MARKERS ) )
+ if ( ( findex < 0.0 ) || ( findex >= MAX_MARKERS ) )
{
return;
}
- x_xmark[(int)findex-1] = -1;
- x_ymark[(int)findex-1] = -1;
+ x_xmark[(int)findex] = -1;
+ x_ymark[(int)findex] = -1;
+ x_wmark[(int)findex] = -1;
+ x_hmark[(int)findex] = -1;
}
@@ -611,6 +669,8 @@ void pix_opencv_contours_boundingrect :: floatClearMess (void)
{
x_xmark[i] = -1;
x_ymark[i] = -1;
+ x_wmark[i] = -1;
+ x_hmark[i] = -1;
x_found[i] = x_ftolerance;
}
}
diff --git a/pix_opencv_contours_boundingrect.h b/pix_opencv_contours_boundingrect.h
index 434a77c..e599f69 100644
--- a/pix_opencv_contours_boundingrect.h
+++ b/pix_opencv_contours_boundingrect.h
@@ -22,7 +22,7 @@ LOG
#include "Base/GemPixObj.h"
-#define MAX_MARKERS 100
+#define MAX_MARKERS 500
/*-----------------------------------------------------------------
-------------------------------------------------------------------
@@ -72,7 +72,7 @@ class GEM_EXTERN pix_opencv_contours_boundingrect : public GemPixObj
void floatNightmodeMess(float nightmode);
void floatShowMess(float show);
void floatDrawMess(float draw);
- int mark(float fx, float fy );
+ int mark(float fx, float fy, float fw, float fh );
void deleteMark(float findex);
// The new minimal/maximal area
int minarea;
@@ -80,8 +80,10 @@ class GEM_EXTERN pix_opencv_contours_boundingrect : public GemPixObj
// to detect changes in the image size
int comp_xsize;
int comp_ysize;
- int x_xmark[MAX_MARKERS];
- int x_ymark[MAX_MARKERS];
+ float x_xmark[MAX_MARKERS];
+ float x_ymark[MAX_MARKERS];
+ int x_wmark[MAX_MARKERS];
+ int x_hmark[MAX_MARKERS];
int x_found[MAX_MARKERS];
int x_ftolerance;
int x_mmove;
diff --git a/pix_opencv_lk-help.pd b/pix_opencv_lk-help.pd
index ae8fec2..804c923 100644
--- a/pix_opencv_lk-help.pd
+++ b/pix_opencv_lk-help.pd
@@ -1,5 +1,5 @@
-#N canvas 228 92 1192 685 10;
-#X obj 140 -12 cnv 15 600 450 empty empty empty 20 12 0 14 -24198 -66577
+#N canvas 236 140 1192 685 10;
+#X obj 141 -12 cnv 15 700 450 empty empty empty 20 12 0 14 -24198 -66577
0;
#X floatatom 288 328 5 0 0 0 - - -;
#X text 323 327 window size;
@@ -22,7 +22,6 @@
#X msg 316 177 clear;
#X text 364 178 delete all markers;
#X msg 322 197 maxmove \$1;
-#X text 436 197 max movement of a marker ( default 5 pisels );
#X floatatom 398 199 5 0 0 0 - - -;
#X text 563 42 set quality ( default 100 );
#X msg 471 41 100;
@@ -35,15 +34,15 @@
#X obj 284 357 route 1 2 3 4 5 6 7 8 9 10;
#X text 450 306 position of each marked point;
#X obj 178 346 pix_opencv_lk;
-#X obj 752 -69 gemmouse;
-#X obj 808 38 f;
-#X obj 778 37 f;
-#X obj 822 9 t b b;
-#X obj 775 82 pack f f;
+#X obj 664 -167 gemmouse;
+#X obj 678 -133 f;
+#X obj 648 -134 f;
+#X obj 734 -89 t b b;
+#X obj 645 -89 pack f f;
#X text 373 137 mark x y : mark a point to track ( max points : 10
);
-#X obj 798 -41 route 1;
-#X msg 819 -16 bang;
+#X obj 710 -139 route 1;
+#X msg 731 -114 bang;
#X msg 277 91 mark all;
#X msg 287 112 mark none;
#X text 340 92 mark all points;
@@ -65,8 +64,8 @@
;
#X obj 376 158 hradio 15 1 0 8 empty empty empty 0 -8 0 10 -262144
-1 -1 0;
-#X floatatom 769 59 5 0 0 0 - - -;
-#X floatatom 822 62 5 0 0 0 - - -;
+#X floatatom 639 -112 5 0 0 0 - - -;
+#X floatatom 692 -109 5 0 0 0 - - -;
#X msg 350 283 pdelaunay 1 500;
#X obj 341 -335 gemhead;
#X obj 353 -308 bng 25 250 50 0 load empty empty 0 -6 0 8 -262144 -1
@@ -163,77 +162,79 @@
#X connect 10 2 11 0;
#X connect 11 0 6 0;
#X restore -224 -379 pd gemwin;
-#X msg -223 -401 create;
+#X msg -223 -401 destroy;
#X text -223 -422 Create window and render;
#X obj 178 488 rectangle 5.3 4;
#X obj 178 -78 pix_resize 320 240;
-#X connect 1 0 33 1;
+#X text 642 -68 selection of a point;
+#X text 436 196 max movement of a marker ( default 20 pixels );
+#X connect 1 0 32 1;
#X connect 3 0 4 0;
-#X connect 4 0 33 0;
-#X connect 6 0 33 0;
+#X connect 4 0 32 0;
+#X connect 6 0 32 0;
#X connect 7 0 6 0;
#X connect 8 0 9 0;
-#X connect 9 0 33 0;
-#X connect 11 0 33 0;
+#X connect 9 0 32 0;
+#X connect 11 0 32 0;
#X connect 13 0 14 0;
#X connect 14 0 7 0;
-#X connect 15 0 33 0;
-#X connect 16 0 33 0;
-#X connect 18 0 33 0;
-#X connect 20 0 33 0;
-#X connect 22 0 20 0;
-#X connect 24 0 13 0;
-#X connect 25 0 24 0;
-#X connect 26 0 27 0;
-#X connect 26 1 28 0;
-#X connect 31 0 26 0;
-#X connect 33 0 81 0;
-#X connect 33 1 31 0;
-#X connect 34 0 36 1;
-#X connect 34 1 35 1;
-#X connect 34 2 40 0;
-#X connect 35 0 38 1;
-#X connect 35 0 58 0;
-#X connect 36 0 38 0;
-#X connect 36 0 57 0;
-#X connect 37 0 36 0;
-#X connect 37 1 35 0;
-#X connect 38 0 15 0;
-#X connect 40 0 41 0;
-#X connect 41 0 37 0;
-#X connect 42 0 33 0;
-#X connect 43 0 33 0;
-#X connect 47 0 33 0;
-#X connect 48 0 33 0;
-#X connect 50 0 33 0;
-#X connect 51 0 50 0;
-#X connect 56 0 16 0;
-#X connect 59 0 33 0;
-#X connect 60 0 66 0;
-#X connect 61 0 64 0;
-#X connect 62 0 63 0;
-#X connect 63 0 66 1;
+#X connect 15 0 32 0;
+#X connect 16 0 32 0;
+#X connect 18 0 32 0;
+#X connect 20 0 32 0;
+#X connect 21 0 20 0;
+#X connect 23 0 13 0;
+#X connect 24 0 23 0;
+#X connect 25 0 26 0;
+#X connect 25 1 27 0;
+#X connect 30 0 25 0;
+#X connect 32 0 80 0;
+#X connect 32 1 30 0;
+#X connect 33 0 35 1;
+#X connect 33 1 34 1;
+#X connect 33 2 39 0;
+#X connect 34 0 37 1;
+#X connect 34 0 57 0;
+#X connect 35 0 37 0;
+#X connect 35 0 56 0;
+#X connect 36 0 35 0;
+#X connect 36 1 34 0;
+#X connect 37 0 15 0;
+#X connect 39 0 40 0;
+#X connect 40 0 36 0;
+#X connect 41 0 32 0;
+#X connect 42 0 32 0;
+#X connect 46 0 32 0;
+#X connect 47 0 32 0;
+#X connect 49 0 32 0;
+#X connect 50 0 49 0;
+#X connect 55 0 16 0;
+#X connect 58 0 32 0;
+#X connect 59 0 65 0;
+#X connect 60 0 63 0;
+#X connect 61 0 62 0;
+#X connect 62 0 65 1;
+#X connect 63 0 64 0;
#X connect 64 0 65 0;
-#X connect 65 0 66 0;
-#X connect 66 0 73 1;
-#X connect 66 2 62 0;
+#X connect 65 0 72 1;
+#X connect 65 2 61 0;
+#X connect 66 0 65 0;
#X connect 67 0 66 0;
-#X connect 68 0 67 0;
-#X connect 69 0 66 0;
-#X connect 69 0 75 0;
-#X connect 70 0 66 0;
-#X connect 71 0 66 0;
-#X connect 72 0 69 0;
-#X connect 72 0 68 0;
-#X connect 73 0 87 0;
-#X connect 74 0 73 2;
-#X connect 75 0 73 0;
-#X connect 76 0 75 0;
-#X connect 77 0 75 0;
-#X connect 78 0 75 0;
-#X connect 79 0 75 0;
-#X connect 80 0 75 0;
-#X connect 81 0 86 0;
-#X connect 83 0 84 0;
-#X connect 84 0 83 0;
-#X connect 87 0 33 0;
+#X connect 68 0 65 0;
+#X connect 68 0 74 0;
+#X connect 69 0 65 0;
+#X connect 70 0 65 0;
+#X connect 71 0 68 0;
+#X connect 71 0 67 0;
+#X connect 72 0 86 0;
+#X connect 73 0 72 2;
+#X connect 74 0 72 0;
+#X connect 75 0 74 0;
+#X connect 76 0 74 0;
+#X connect 77 0 74 0;
+#X connect 78 0 74 0;
+#X connect 79 0 74 0;
+#X connect 80 0 85 0;
+#X connect 82 0 83 0;
+#X connect 83 0 82 0;
+#X connect 86 0 32 0;
diff --git a/pix_opencv_lk.cc b/pix_opencv_lk.cc
index dbab9b9..9e02ae3 100644
--- a/pix_opencv_lk.cc
+++ b/pix_opencv_lk.cc
@@ -51,7 +51,7 @@ pix_opencv_lk :: pix_opencv_lk()
add_remove_pt = 0;
quality = 0.1;
min_distance = 10;
- maxmove = 8;
+ maxmove = 20;
markall = 0;
ftolerance = 5;
delaunay = -1;
@@ -104,8 +104,9 @@ pix_opencv_lk :: ~pix_opencv_lk()
void pix_opencv_lk :: processRGBAImage(imageStruct &image)
{
int i, k;
- int im;
+ int im, oi;
int marked;
+ float dist, odist;
if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize))
{
@@ -250,29 +251,42 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image)
cvCircle( rgb, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
marked=0;
+ oi=-1;
+ dist=(comp_xsize>comp_ysize)?comp_xsize:comp_ysize;
+
for ( im=0; im<MAX_MARKERS; im++ )
{
- // first marking
- if ( x_xmark[im] != -1.0 )
+
+ if ( x_xmark[im] == -1 ) continue; // i don't see the point
+
+ odist=sqrt( pow( points[1][i].x - x_xmark[im], 2 ) + pow( points[1][i].y - x_ymark[im], 2 ) );
+
+ // search for the closest point
+ if ( odist <= maxmove )
{
- // post( "pix_opencv_lk : compare (%f,%f) to (%d,%d)", points[1][i].x, points[1][i].y, x_xmark[im], x_ymark[im] );
- if ( ( abs( (int)points[1][i].x - x_xmark[im] ) <= maxmove ) && ( abs( (int)points[1][i].y - x_ymark[im] ) <= maxmove ) )
- {
- char tindex[4];
- sprintf( tindex, "%d", im+1 );
- cvPutText( rgb, tindex, cvPointFrom32f(points[1][i]), &font, CV_RGB(255,255,255));
- x_xmark[im]=(int)points[1][i].x;
- x_ymark[im]=(int)points[1][i].y;
- x_found[im]=ftolerance;
- marked=1;
- SETFLOAT(&x_list[0], im+1);
- SETFLOAT(&x_list[1], x_xmark[im]);
- SETFLOAT(&x_list[2], x_ymark[im]);
- outlet_list( m_dataout, 0, 3, x_list );
- }
+ if ( odist < dist )
+ {
+ dist = odist;
+ marked=1;
+ oi=im;
+ }
}
}
+ if ( oi != -1 )
+ {
+ char tindex[4];
+ sprintf( tindex, "%d", oi );
+ cvPutText( rgb, tindex, cvPointFrom32f(points[1][i]), &font, CV_RGB(255,255,255));
+ x_xmark[oi]=(int)points[1][i].x;
+ x_ymark[oi]=(int)points[1][i].y;
+ x_found[oi]=ftolerance;
+ SETFLOAT(&x_list[0], oi);
+ SETFLOAT(&x_list[1], x_xmark[oi]);
+ SETFLOAT(&x_list[2], x_ymark[oi]);
+ outlet_list( m_dataout, 0, 3, x_list );
+ }
+
if ( markall && !marked )
{
for ( im=0; im<MAX_MARKERS; im++)
@@ -369,8 +383,9 @@ void pix_opencv_lk :: processRGBAImage(imageStruct &image)
void pix_opencv_lk :: processRGBImage(imageStruct &image)
{
int i, k;
- int im;
+ int im, oi;
int marked;
+ float dist, odist;
if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize))
{
@@ -514,28 +529,41 @@ void pix_opencv_lk :: processRGBImage(imageStruct &image)
cvCircle( rgb, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
marked=0;
+ oi=-1;
+ dist=(comp_xsize>comp_ysize)?comp_xsize:comp_ysize;
+
for ( im=0; im<MAX_MARKERS; im++ )
{
- // first marking
- if ( x_xmark[im] != -1.0 )
+ if ( x_xmark[im] == -1 ) continue; // i don't see the point
+
+ odist=sqrt( pow( points[1][i].x - x_xmark[im], 2 ) + pow( points[1][i].y - x_ymark[im], 2 ) );
+
+ // search for this point
+ if ( odist <= maxmove )
{
- if ( ( abs( points[1][i].x - x_xmark[im] ) <= maxmove ) && ( abs( points[1][i].y - x_ymark[im] ) <= maxmove ) )
- {
- char tindex[4];
- sprintf( tindex, "%d", im+1 );
- cvPutText( rgb, tindex, cvPointFrom32f(points[1][i]), &font, CV_RGB(255,255,255));
- x_xmark[im]=points[1][i].x;
- x_ymark[im]=points[1][i].y;
- x_found[im]=ftolerance;
- marked=1;
- SETFLOAT(&x_list[0], im+1);
- SETFLOAT(&x_list[1], x_xmark[im]);
- SETFLOAT(&x_list[2], x_ymark[im]);
- outlet_list( m_dataout, 0, 3, x_list );
- }
+ if ( odist < dist )
+ {
+ dist = odist;
+ marked=1;
+ oi=im;
+ }
}
}
+ if ( oi !=-1 )
+ {
+ char tindex[4];
+ sprintf( tindex, "%d", oi );
+ cvPutText( rgb, tindex, cvPointFrom32f(points[1][i]), &font, CV_RGB(255,255,255));
+ x_xmark[oi]=points[1][i].x;
+ x_ymark[oi]=points[1][i].y;
+ x_found[oi]=ftolerance;
+ SETFLOAT(&x_list[0], oi);
+ SETFLOAT(&x_list[1], x_xmark[oi]);
+ SETFLOAT(&x_list[2], x_ymark[oi]);
+ outlet_list( m_dataout, 0, 3, x_list );
+ }
+
if ( markall && !marked )
{
for ( im=0; im<MAX_MARKERS; im++)
@@ -636,8 +664,9 @@ void pix_opencv_lk :: processYUVImage(imageStruct &image)
void pix_opencv_lk :: processGrayImage(imageStruct &image)
{
int i, k;
- int im;
+ int im, oi;
int marked;
+ float dist, odist;
if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize))
{
@@ -774,26 +803,39 @@ void pix_opencv_lk :: processGrayImage(imageStruct &image)
cvCircle( gray, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
marked=0;
+ oi=-1;
+ dist=(comp_xsize>comp_ysize)?comp_xsize:comp_ysize;
+
for ( im=0; im<MAX_MARKERS; im++ )
{
- // first marking
- if ( x_xmark[im] != -1.0 )
- {
- if ( ( abs( points[1][i].x - x_xmark[im] ) <= maxmove ) && ( abs( points[1][i].y - x_ymark[im] ) <= maxmove ) )
- {
- char tindex[4];
- sprintf( tindex, "%d", im+1 );
+ if ( x_xmark[im] == -1 ) continue; // i don't see the point
+
+ odist=sqrt( pow( points[1][i].x - x_xmark[im], 2 ) + pow( points[1][i].y - x_ymark[im], 2 ) );
+
+ // search for the closest point
+ if ( odist <= maxmove )
+ {
+ if ( odist < dist )
+ {
+ dist = odist;
+ marked=1;
+ oi=im;
+ }
+ }
+ }
+
+ if ( oi !=-1 )
+ {
+ char tindex[4];
+ sprintf( tindex, "%d", oi );
cvPutText( gray, tindex, cvPointFrom32f(points[1][i]), &font, CV_RGB(255,255,255));
- x_xmark[im]=points[1][i].x;
- x_ymark[im]=points[1][i].y;
- x_found[im]=ftolerance;
- marked=1;
- SETFLOAT(&x_list[0], im+1);
- SETFLOAT(&x_list[1], x_xmark[im]);
- SETFLOAT(&x_list[2], x_ymark[im]);
+ x_xmark[oi]=points[1][i].x;
+ x_ymark[oi]=points[1][i].y;
+ x_found[oi]=ftolerance;
+ SETFLOAT(&x_list[0], oi);
+ SETFLOAT(&x_list[1], x_xmark[oi]);
+ SETFLOAT(&x_list[2], x_ymark[oi]);
outlet_list( m_dataout, 0, 3, x_list );
- }
- }
}
if ( markall && !marked )
@@ -1070,13 +1112,13 @@ void pix_opencv_lk :: deleteMess(float index)
{
int i;
- if ( ( index < 1.0 ) || ( index > MAX_MARKERS ) )
+ if ( ( index < 0.0 ) || ( index >= MAX_MARKERS ) )
{
return;
}
- x_xmark[(int)index-1] = -1;
- x_ymark[(int)index-1] = -1;
+ x_xmark[(int)index] = -1;
+ x_ymark[(int)index] = -1;
}
diff --git a/pix_opencv_surf-help.pd b/pix_opencv_surf-help.pd
index e60d1db..112d440 100644
--- a/pix_opencv_surf-help.pd
+++ b/pix_opencv_surf-help.pd
@@ -1,4 +1,4 @@
-#N canvas 122 88 1211 737 10;
+#N canvas 126 104 1211 737 10;
#X obj 361 637 pix_texture;
#X obj 32 -122 cnv 15 220 70 empty empty empty 20 12 0 14 -195568 -66577
0;
@@ -71,7 +71,6 @@
#X msg 446 362 clear;
#X text 494 363 delete all markers;
#X msg 461 392 maxmove \$1;
-#X text 575 392 max movement of a marker ( default 5 pisels );
#X floatatom 537 394 5 0 0 0 - - -;
#X text 502 316 mark %x %y : mark a point to track ( max points : 10
);
@@ -110,7 +109,7 @@
#X msg 527 -26 open \$1;
#X obj 515 83 pix_film;
#X msg 533 17 auto \$1;
-#X obj 533 -1 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 0 1
+#X obj 533 -1 tgl 15 0 empty empty empty 0 -6 0 8 -262144 -1 -1 1 1
;
#X msg 628 0 colorspace RGBA;
#X msg 733 0 colorspace RGB;
@@ -154,7 +153,8 @@
#X msg 365 -66 dialog;
#X msg 370 -36 device /dev/dv1394-0;
#X obj 357 151 pix_resize 320 240;
-#X connect 0 0 52 0;
+#X text 575 392 max movement of a marker ( default 20 pixels );
+#X connect 0 0 51 0;
#X connect 2 0 3 0;
#X connect 3 0 2 0;
#X connect 6 0 7 0;
@@ -180,39 +180,39 @@
#X connect 26 0 21 0;
#X connect 28 0 21 0;
#X connect 30 0 21 0;
-#X connect 32 0 30 0;
+#X connect 31 0 30 0;
+#X connect 34 0 21 0;
#X connect 35 0 21 0;
-#X connect 36 0 21 0;
-#X connect 38 0 26 0;
+#X connect 37 0 26 0;
+#X connect 38 0 21 0;
#X connect 39 0 21 0;
-#X connect 40 0 21 0;
-#X connect 41 0 40 0;
-#X connect 42 0 43 0;
-#X connect 43 0 21 0;
-#X connect 45 0 21 0;
-#X connect 47 0 21 0;
-#X connect 53 0 59 0;
-#X connect 54 0 57 0;
-#X connect 55 0 56 0;
-#X connect 56 0 59 1;
+#X connect 40 0 39 0;
+#X connect 41 0 42 0;
+#X connect 42 0 21 0;
+#X connect 44 0 21 0;
+#X connect 46 0 21 0;
+#X connect 52 0 58 0;
+#X connect 53 0 56 0;
+#X connect 54 0 55 0;
+#X connect 55 0 58 1;
+#X connect 56 0 57 0;
#X connect 57 0 58 0;
-#X connect 58 0 59 0;
-#X connect 59 0 66 1;
-#X connect 59 2 55 0;
+#X connect 58 0 65 1;
+#X connect 58 2 54 0;
+#X connect 59 0 58 0;
#X connect 60 0 59 0;
-#X connect 61 0 60 0;
-#X connect 62 0 59 0;
-#X connect 62 0 68 0;
-#X connect 63 0 59 0;
-#X connect 64 0 59 0;
-#X connect 65 0 62 0;
-#X connect 65 0 61 0;
-#X connect 66 0 74 0;
-#X connect 67 0 66 2;
-#X connect 68 0 66 0;
-#X connect 69 0 68 0;
-#X connect 70 0 68 0;
-#X connect 71 0 68 0;
-#X connect 72 0 68 0;
-#X connect 73 0 68 0;
-#X connect 74 0 21 0;
+#X connect 61 0 58 0;
+#X connect 61 0 67 0;
+#X connect 62 0 58 0;
+#X connect 63 0 58 0;
+#X connect 64 0 61 0;
+#X connect 64 0 60 0;
+#X connect 65 0 73 0;
+#X connect 66 0 65 2;
+#X connect 67 0 65 0;
+#X connect 68 0 67 0;
+#X connect 69 0 67 0;
+#X connect 70 0 67 0;
+#X connect 71 0 67 0;
+#X connect 72 0 67 0;
+#X connect 73 0 21 0;
diff --git a/pix_opencv_surf.cc b/pix_opencv_surf.cc
index adcd2b1..6fc1e59 100644
--- a/pix_opencv_surf.cc
+++ b/pix_opencv_surf.cc
@@ -40,7 +40,7 @@ pix_opencv_surf :: pix_opencv_surf()
m_dataout = outlet_new(this->x_obj, &s_anything);
night_mode = 0;
- x_maxmove = 8;
+ x_maxmove = 20;
x_delaunay = -1;
x_threshold = -1;
@@ -88,10 +88,11 @@ pix_opencv_surf :: ~pix_opencv_surf()
void pix_opencv_surf :: processRGBAImage(imageStruct &image)
{
int i, k;
- int im;
+ int im, oi;
int marked;
int descsize;
char tindex[4];
+ float dist, odist;
if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize))
{
@@ -202,15 +203,16 @@ void pix_opencv_surf :: processRGBAImage(imageStruct &image)
for ( im=0; im<MAX_MARKERS; im++ )
{
- if ( x_xmark[im] != -1.0 )
- {
- if ( ( abs( r1->pt.x - x_xmark[im] ) <= x_maxmove ) && ( abs( r1->pt.y - x_ymark[im] ) <= x_maxmove ) )
+ if ( x_xmark[im] == -1 ) continue; // no points
+
+ odist=sqrt( pow( r1->pt.x-x_xmark[im], 2 ) + pow( r1->pt.y-x_ymark[im], 2 ) );
+
+ if ( odist <= x_maxmove )
{
marked = 1;
// post( "pdp_opencv_surf : point already marked" );
break;
}
- }
}
if ( !marked )
{
@@ -234,6 +236,11 @@ void pix_opencv_surf :: processRGBAImage(imageStruct &image)
int neighbour = -1;
double d, dist1 = 1000000, dist2 = 1000000;
+ if ( x_xmark[im] == -1 ) continue; // no points
+
+ oi=-1;
+ dist=(comp_xsize>comp_ysize)?comp_xsize:comp_ysize;
+
for( i = 0; i < objectKeypoints->total; i++ )
{
CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem( objectKeypoints, i );
@@ -242,24 +249,31 @@ void pix_opencv_surf :: processRGBAImage(imageStruct &image)
// manually marked points
// recognized on position
- if ( x_xmark[im] != -1.0 )
+ odist=sqrt( pow( r1->pt.x-x_xmark[im], 2 ) + pow( r1->pt.y-x_ymark[im], 2 ) );
+
+ if ( odist <= x_maxmove )
{
- if ( ( abs( r1->pt.x - x_xmark[im] ) <= x_maxmove ) && ( abs( r1->pt.y - x_ymark[im] ) <= x_maxmove ) )
- {
- sprintf( tindex, "%d", im+1 );
- cvPutText( rgb, tindex, cvPointFrom32f(r1->pt), &font, CV_RGB(255,255,255));
- x_xmark[im]=r1->pt.x;
- x_ymark[im]=r1->pt.y;
- memcpy( (float * )x_rdesc[im], rdesc, descsize*sizeof(float));
- x_found[im]++;
- SETFLOAT(&x_list[0], im+1);
- SETFLOAT(&x_list[1], x_xmark[im]);
- SETFLOAT(&x_list[2], x_ymark[im]);
- outlet_list( m_dataout, 0, 3, x_list );
- break;
- }
+ if ( odist < dist )
+ {
+ oi=im;
+ x_xmark[oi]=r1->pt.x;
+ x_ymark[oi]=r1->pt.y;
+ memcpy( (float * )x_rdesc[oi], rdesc, descsize*sizeof(float));
+ dist = odist;
+ }
}
}
+
+ if ( oi !=-1 )
+ {
+ sprintf( tindex, "%d", oi );
+ cvPutText( rgb, tindex, cvPoint(x_xmark[oi],x_ymark[oi]), &font, CV_RGB(255,255,255));
+ x_found[oi] = x_ftolerance;
+ SETFLOAT(&x_list[0], oi);
+ SETFLOAT(&x_list[1], x_xmark[oi]);
+ SETFLOAT(&x_list[2], x_ymark[oi]);
+ outlet_list( m_dataout, 0, 3, x_list );
+ }
}
// draw the delaunay
@@ -330,10 +344,11 @@ void pix_opencv_surf :: processRGBAImage(imageStruct &image)
void pix_opencv_surf :: processRGBImage(imageStruct &image)
{
int i, k;
- int im;
+ int im, oi;
int marked;
int descsize;
char tindex[4];
+ float dist, odist;
if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize))
{
@@ -443,14 +458,15 @@ void pix_opencv_surf :: processRGBImage(imageStruct &image)
for ( im=0; im<MAX_MARKERS; im++ )
{
- if ( x_xmark[im] != -1.0 )
+ if ( x_xmark[im] == -1 ) continue; // no points
+
+ odist=sqrt( pow( r1->pt.x-x_xmark[im], 2 ) + pow( r1->pt.y-x_ymark[im], 2 ) );
+
+ if ( odist <= x_maxmove )
{
- if ( ( abs( r1->pt.x - x_xmark[im] ) <= x_maxmove ) && ( abs( r1->pt.y - x_ymark[im] ) <= x_maxmove ) )
- {
marked = 1;
// post( "pdp_opencv_surf : point already marked" );
break;
- }
}
}
if ( !marked )
@@ -475,6 +491,11 @@ void pix_opencv_surf :: processRGBImage(imageStruct &image)
int neighbour = -1;
double d, dist1 = 1000000, dist2 = 1000000;
+ if ( x_xmark[im] == -1 ) continue; // no points
+
+ oi=-1;
+ dist=(comp_xsize>comp_ysize)?comp_xsize:comp_ysize;
+
for( i = 0; i < objectKeypoints->total; i++ )
{
CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem( objectKeypoints, i );
@@ -483,24 +504,31 @@ void pix_opencv_surf :: processRGBImage(imageStruct &image)
// manually marked points
// recognized on position
- if ( x_xmark[im] != -1.0 )
+ odist=sqrt( pow( r1->pt.x-x_xmark[im], 2 ) + pow( r1->pt.y-x_ymark[im], 2 ) );
+
+ if ( odist <= x_maxmove )
{
- if ( ( abs( r1->pt.x - x_xmark[im] ) <= x_maxmove ) && ( abs( r1->pt.y - x_ymark[im] ) <= x_maxmove ) )
- {
- sprintf( tindex, "%d", im+1 );
- cvPutText( rgb, tindex, cvPointFrom32f(r1->pt), &font, CV_RGB(255,255,255));
- x_xmark[im]=r1->pt.x;
- x_ymark[im]=r1->pt.y;
- memcpy( (float * )x_rdesc[im], rdesc, descsize*sizeof(float));
- x_found[im]++;
- SETFLOAT(&x_list[0], im+1);
- SETFLOAT(&x_list[1], x_xmark[im]);
- SETFLOAT(&x_list[2], x_ymark[im]);
- outlet_list( m_dataout, 0, 3, x_list );
- break;
- }
+ if ( odist < dist )
+ {
+ oi=im;
+ x_xmark[oi]=r1->pt.x;
+ x_ymark[oi]=r1->pt.y;
+ memcpy( (float * )x_rdesc[oi], rdesc, descsize*sizeof(float));
+ dist = odist;
+ }
}
}
+
+ if ( oi !=-1 )
+ {
+ sprintf( tindex, "%d", oi );
+ cvPutText( rgb, tindex, cvPoint(x_xmark[oi],x_ymark[oi]), &font, CV_RGB(255,255,255));
+ x_found[oi] = x_ftolerance;
+ SETFLOAT(&x_list[0], oi);
+ SETFLOAT(&x_list[1], x_xmark[oi]);
+ SETFLOAT(&x_list[2], x_ymark[oi]);
+ outlet_list( m_dataout, 0, 3, x_list );
+ }
}
// draw the delaunay
@@ -574,10 +602,11 @@ void pix_opencv_surf :: processYUVImage(imageStruct &image)
void pix_opencv_surf :: processGrayImage(imageStruct &image)
{
int i, k;
- int im;
+ int im, oi;
int marked;
int descsize;
char tindex[4];
+ float dist, odist;
if ((this->comp_xsize!=image.xsize)&&(this->comp_ysize!=image.ysize))
{
@@ -679,16 +708,18 @@ void pix_opencv_surf :: processGrayImage(imageStruct &image)
for ( im=0; im<MAX_MARKERS; im++ )
{
- if ( x_xmark[im] != -1.0 )
+ if ( x_xmark[im] == -1 ) continue; // no points
+
+ odist=sqrt( pow( r1->pt.x-x_xmark[im], 2 ) + pow( r1->pt.y-x_ymark[im], 2 ) );
+
+ if ( odist <= x_maxmove )
{
- if ( ( abs( r1->pt.x - x_xmark[im] ) <= x_maxmove ) && ( abs( r1->pt.y - x_ymark[im] ) <= x_maxmove ) )
- {
- marked = 1;
- // post( "pdp_opencv_surf : point already marked" );
- break;
- }
+ marked = 1;
+ // post( "pdp_opencv_surf : point already marked" );
+ break;
}
}
+
if ( !marked )
{
for ( i=0; i<MAX_MARKERS; i++)
@@ -711,6 +742,11 @@ void pix_opencv_surf :: processGrayImage(imageStruct &image)
int neighbour = -1;
double d, dist1 = 1000000, dist2 = 1000000;
+ if ( x_xmark[im] == -1 ) continue; // no points
+
+ oi=-1;
+ dist=(comp_xsize>comp_ysize)?comp_xsize:comp_ysize;
+
for( i = 0; i < objectKeypoints->total; i++ )
{
CvSURFPoint* r1 = (CvSURFPoint*)cvGetSeqElem( objectKeypoints, i );
@@ -719,24 +755,31 @@ void pix_opencv_surf :: processGrayImage(imageStruct &image)
// manually marked points
// recognized on position
- if ( x_xmark[im] != -1.0 )
+ odist=sqrt( pow( r1->pt.x-x_xmark[im], 2 ) + pow( r1->pt.y-x_ymark[im], 2 ) );
+
+ if ( odist <= x_maxmove )
{
- if ( ( abs( r1->pt.x - x_xmark[im] ) <= x_maxmove ) && ( abs( r1->pt.y - x_ymark[im] ) <= x_maxmove ) )
- {
- sprintf( tindex, "%d", im+1 );
- cvPutText( gray, tindex, cvPointFrom32f(r1->pt), &font, CV_RGB(255,255,255));
- x_xmark[im]=r1->pt.x;
- x_ymark[im]=r1->pt.y;
- memcpy( (float * )x_rdesc[im], rdesc, descsize*sizeof(float));
- x_found[im]++;
- SETFLOAT(&x_list[0], im+1);
- SETFLOAT(&x_list[1], x_xmark[im]);
- SETFLOAT(&x_list[2], x_ymark[im]);
- outlet_list( m_dataout, 0, 3, x_list );
- break;
- }
+ if ( odist < dist )
+ {
+ oi=im;
+ x_xmark[oi]=r1->pt.x;
+ x_ymark[oi]=r1->pt.y;
+ memcpy( (float * )x_rdesc[oi], rdesc, descsize*sizeof(float));
+ dist = odist;
+ }
}
}
+
+ if ( oi !=-1 )
+ {
+ sprintf( tindex, "%d", oi );
+ cvPutText( gray, tindex, cvPoint(x_xmark[oi],x_ymark[oi]), &font, CV_RGB(255,255,255));
+ x_found[oi] = x_ftolerance;
+ SETFLOAT(&x_list[0], oi);
+ SETFLOAT(&x_list[1], x_xmark[oi]);
+ SETFLOAT(&x_list[2], x_ymark[oi]);
+ outlet_list( m_dataout, 0, 3, x_list );
+ }
}
// draw the delaunay