aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN.N. <sevyves@users.sourceforge.net>2009-08-18 15:00:47 +0000
committerN.N. <sevyves@users.sourceforge.net>2009-08-18 15:00:47 +0000
commit571ab6c2132878c79a00227f81b42c4a48c1d91f (patch)
tree26182c6ea6e066d0608f97729235bdc0b0f6ee75
parent489edd286958ff852290836f65d302c47a611d64 (diff)
better following of objects
svn path=/trunk/externals/pidip/; revision=11943
-rw-r--r--modules/pdp_shape.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/modules/pdp_shape.c b/modules/pdp_shape.c
index 5786b81..c52b14f 100644
--- a/modules/pdp_shape.c
+++ b/modules/pdp_shape.c
@@ -50,6 +50,10 @@ typedef struct pdp_shape_struct
int x_cursX;
int x_cursY;
+ float x_meanX;
+ float x_meanY;
+ int x_nbpts;
+
int x_colorY; // YUV components of selected color
int x_colorU;
int x_colorV;
@@ -324,6 +328,9 @@ static void pdp_shape_do_detect(t_pdp_shape *x, t_floatarg X, t_floatarg Y)
*(pbbV+(nY>>1)*(x->x_vwidth>>1)+(nX>>1)) =
(yuv_RGBtoV( (x->x_blue << 16) + (x->x_green << 8) + x->x_red ))-128<<8;
}
+ x->x_meanX = ( x->x_nbpts*x->x_meanX + nX )/(x->x_nbpts+1);
+ x->x_meanY = ( x->x_nbpts*x->x_meanY + nY )/(x->x_nbpts+1);
+ x->x_nbpts++;
}
nX = (int) X+1;
@@ -470,8 +477,23 @@ static void pdp_shape_process_yv12(t_pdp_shape *x)
memset( x->x_bbdata, 0x0, (x->x_vsize+(x->x_vsize>>1))<<1 );
}
+ x->x_nbpts = 0;
+ x->x_meanX = 0;
+ x->x_meanY = 0;
if ( x->x_cursX != -1 ) pdp_shape_frame_detect( x, x->x_cursX, x->x_cursY );
+ // post( "pdp_shape : mean : %f,%f : nbpoints : %d", x->x_meanX, x->x_meanY, x->x_nbpts );
+ if ( x->x_nbpts > 0 )
+ {
+ if ( ( x->x_meanX >= 0 ) && ( x->x_meanX < x->x_vwidth )
+ && ( x->x_meanY >= 0 ) && ( x->x_meanY < x->x_vheight )
+ && pdp_shape_check_point(x, x->x_meanX, x->x_meanY) )
+ {
+ x->x_cursX = (int)x->x_meanX;
+ x->x_cursY = (int)x->x_meanY;
+ }
+ }
+
// paint cursor in red for debug purpose
if ( ( x->x_cursX != -1 ) && ( x->x_shape ) )
{
@@ -606,7 +628,6 @@ void pdp_shape_setup(void)
pdp_shape_class = class_new(gensym("pdp_shape"), (t_newmethod)pdp_shape_new,
(t_method)pdp_shape_free, sizeof(t_pdp_shape), 0, A_NULL);
-
class_addmethod(pdp_shape_class, (t_method)pdp_shape_input_0, gensym("pdp"), A_SYMBOL, A_DEFFLOAT, A_NULL);
class_addmethod(pdp_shape_class, (t_method)pdp_shape_pick, gensym("pick"), A_DEFFLOAT, A_DEFFLOAT, A_NULL);
class_addmethod(pdp_shape_class, (t_method)pdp_shape_detect, gensym("detect"), A_DEFFLOAT, A_DEFFLOAT, A_NULL);