aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorN.N. <sevyves@users.sourceforge.net>2010-07-13 20:39:43 +0000
committerN.N. <sevyves@users.sourceforge.net>2010-07-13 20:39:43 +0000
commit5dc1d97357e3519da6c595c21682aa00a58624ff (patch)
tree2450acc4adf167e751fa8a1971015900720b6f89
parent07c9c742b5a7af4994cdccb39750eaf1edd886c2 (diff)
fixed angle calculations
svn path=/trunk/externals/pix_opencv/; revision=13712
-rw-r--r--Makefile2
-rwxr-xr-xpix_opencv_of_bm.cc108
-rwxr-xr-xpix_opencv_of_hs.cc108
-rwxr-xr-xpix_opencv_of_lk-help.pd52
-rwxr-xr-xpix_opencv_of_lk.cc119
5 files changed, 217 insertions, 172 deletions
diff --git a/Makefile b/Makefile
index 807f9fe..daf788e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
PD_DIR = /Software/pd-svn/trunk/pd
-GEM_DIR = /usr/src/gem-0.91-3
+GEM_DIR = /usr/src/gem-0.92-3
GEM_OPENCV_VERSION = 0.2
diff --git a/pix_opencv_of_bm.cc b/pix_opencv_of_bm.cc
index 00eb8fb..97bc9bf 100755
--- a/pix_opencv_of_bm.cc
+++ b/pix_opencv_of_bm.cc
@@ -86,7 +86,7 @@ pix_opencv_of_bm :: ~pix_opencv_of_bm()
void pix_opencv_of_bm :: processRGBAImage(imageStruct &image)
{
int px,py;
- double meanangle=0.0, meanx=0.0, meany=0.0, maxamp=0.0, maxangle=0.0;
+ double globangle=0.0, globx=0.0, globy=0.0, maxamp=0.0, maxangle=0.0;
int nbblocks=0;
CvPoint orig, dest;
double angle=0.0;
@@ -132,6 +132,9 @@ void pix_opencv_of_bm :: processRGBAImage(imageStruct &image)
x_velx, x_vely );
nbblocks = 0;
+ globangle = 0;
+ globx = 0;
+ globy = 0;
for( py=0; py<x_velsize.height; py++ )
{
for( px=0; px<x_velsize.width; px++ )
@@ -140,8 +143,8 @@ void pix_opencv_of_bm :: processRGBAImage(imageStruct &image)
orig.y = (py*comp_ysize)/x_velsize.height;
dest.x = (int)(orig.x + cvGet2D(x_velx, py, px).val[0]);
dest.y = (int)(orig.y + cvGet2D(x_vely, py, px).val[0]);
- angle = -atan2( (double) cvGet2D(x_vely, py, px).val[0], (double) cvGet2D(x_velx, py, px).val[0] );
- hypotenuse = sqrt( pow(orig.y - dest.y, 2) + pow(orig.x - dest.x, 2) );
+ angle = -atan2( (double) (dest.y-orig.y), (double) (dest.x-orig.x) );
+ hypotenuse = sqrt( pow(dest.y-orig.y, 2) + pow(dest.x-orig.x, 2) );
/* Now draw the tips of the arrow. I do some scaling so that the
* tips look proportional to the main line of the arrow.
@@ -156,8 +159,9 @@ void pix_opencv_of_bm :: processRGBAImage(imageStruct &image)
orig.x = (int) (dest.x - (x_shiftsize.width/4) * cos(angle - M_PI / 4));
orig.y = (int) (dest.y + (x_shiftsize.height/4) * sin(angle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(0,0,255), (int)hypotenuse/10, CV_AA, 0 );
- meanx = (meanx*nbblocks+cvGet2D(x_velx, py, px).val[0])/(nbblocks+1);
- meany = (meanx*nbblocks+cvGet2D(x_vely, py, px).val[0])/(nbblocks+1);
+
+ globx = globx+cvGet2D(x_velx, py, px).val[0];
+ globy = globy+cvGet2D(x_vely, py, px).val[0];
if ( hypotenuse > maxamp )
{
maxamp = hypotenuse;
@@ -170,26 +174,26 @@ void pix_opencv_of_bm :: processRGBAImage(imageStruct &image)
}
}
- meanangle=-atan2( meany, meanx );
- // post( "pdp_opencv_of_bm : meanangle : %f", (meanangle*180)/M_PI );
-
if ( nbblocks >= x_minblocks )
{
+ globangle=-atan2( globy, globx );
+ // post( "pdp_opencv_of_bm : globangle : %f", (globangle*180)/M_PI );
+
orig.x = (int) (comp_xsize/2);
orig.y = (int) (comp_ysize/2);
- dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(meanangle));
- dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(meanangle));
+ dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(globangle));
+ dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(globangle));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(meanangle + M_PI / 4));
- orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(meanangle + M_PI / 4));
+ orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(globangle + M_PI / 4));
+ orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(globangle + M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(meanangle - M_PI / 4));
- orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(meanangle - M_PI / 4));
+ orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(globangle - M_PI / 4));
+ orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(globangle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
// outputs the average angle of movement
- meanangle = (meanangle*180)/M_PI;
- SETFLOAT(&x_list[0], meanangle);
+ globangle = (globangle*180)/M_PI;
+ SETFLOAT(&x_list[0], globangle);
outlet_list( m_meanout, 0, 1, x_list );
// outputs the amplitude and angle of the maximum movement
@@ -208,7 +212,7 @@ void pix_opencv_of_bm :: processRGBAImage(imageStruct &image)
void pix_opencv_of_bm :: processRGBImage(imageStruct &image)
{
int px,py;
- double meanangle=0.0, meanx=0.0, meany=0.0, maxamp=0.0, maxangle=0.0;
+ double globangle=0.0, globx=0.0, globy=0.0, maxamp=0.0, maxangle=0.0;
int nbblocks=0;
CvPoint orig, dest;
double angle=0.0;
@@ -254,6 +258,9 @@ void pix_opencv_of_bm :: processRGBImage(imageStruct &image)
x_velx, x_vely );
nbblocks = 0;
+ globangle = 0;
+ globx = 0;
+ globy = 0;
for( py=0; py<x_velsize.height; py++ )
{
for( px=0; px<x_velsize.width; px++ )
@@ -263,8 +270,8 @@ void pix_opencv_of_bm :: processRGBImage(imageStruct &image)
orig.y = (py*comp_ysize)/x_velsize.height;
dest.x = (int)(orig.x + cvGet2D(x_velx, py, px).val[0]);
dest.y = (int)(orig.y + cvGet2D(x_vely, py, px).val[0]);
- angle = -atan2( (double) cvGet2D(x_vely, py, px).val[0], (double) cvGet2D(x_velx, py, px).val[0] );
- hypotenuse = sqrt( pow(orig.y - dest.y, 2) + pow(orig.x - dest.x, 2) );
+ angle = -atan2( (double) (dest.y-orig.y), (double) (dest.x-orig.x) );
+ hypotenuse = sqrt( pow(dest.y-orig.y, 2) + pow(dest.x-orig.x, 2) );
/* Now draw the tips of the arrow. I do some scaling so that the
* tips look proportional to the main line of the arrow.
@@ -279,8 +286,9 @@ void pix_opencv_of_bm :: processRGBImage(imageStruct &image)
orig.x = (int) (dest.x - (x_shiftsize.width/4) * cos(angle - M_PI / 4));
orig.y = (int) (dest.y + (x_shiftsize.height/4) * sin(angle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(0,0,255), (int)hypotenuse/10, CV_AA, 0 );
- meanx = (meanx*nbblocks+cvGet2D(x_velx, py, px).val[0])/(nbblocks+1);
- meany = (meanx*nbblocks+cvGet2D(x_vely, py, px).val[0])/(nbblocks+1);
+
+ globx = globx+cvGet2D(x_velx, py, px).val[0];
+ globy = globy+cvGet2D(x_vely, py, px).val[0];
if ( hypotenuse > maxamp )
{
maxamp = hypotenuse;
@@ -293,26 +301,26 @@ void pix_opencv_of_bm :: processRGBImage(imageStruct &image)
}
}
- meanangle=-atan2( meany, meanx );
- // post( "pdp_opencv_of_bm : meanangle : %f", (meanangle*180)/M_PI );
-
if ( nbblocks >= x_minblocks )
{
+ globangle=-atan2( globy, globx );
+ // post( "pdp_opencv_of_bm : globangle : %f", (globangle*180)/M_PI );
+
orig.x = (int) (comp_xsize/2);
orig.y = (int) (comp_ysize/2);
- dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(meanangle));
- dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(meanangle));
+ dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(globangle));
+ dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(globangle));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(meanangle + M_PI / 4));
- orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(meanangle + M_PI / 4));
+ orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(globangle + M_PI / 4));
+ orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(globangle + M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(meanangle - M_PI / 4));
- orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(meanangle - M_PI / 4));
+ orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(globangle - M_PI / 4));
+ orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(globangle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
// outputs the average angle of movement
- meanangle = (meanangle*180)/M_PI;
- SETFLOAT(&x_list[0], meanangle);
+ globangle = (globangle*180)/M_PI;
+ SETFLOAT(&x_list[0], globangle);
outlet_list( m_meanout, 0, 1, x_list );
// outputs the amplitude and angle of the maximum movement
@@ -335,7 +343,7 @@ void pix_opencv_of_bm :: processYUVImage(imageStruct &image)
void pix_opencv_of_bm :: processGrayImage(imageStruct &image)
{
int px,py;
- double meanangle=0.0, meanx=0.0, meany=0.0, maxamp=0.0, maxangle=0.0;
+ double globangle=0.0, globx=0.0, globy=0.0, maxamp=0.0, maxangle=0.0;
int nbblocks=0;
CvPoint orig, dest;
double angle=0.0;
@@ -377,6 +385,9 @@ void pix_opencv_of_bm :: processGrayImage(imageStruct &image)
x_velx, x_vely );
nbblocks = 0;
+ globangle = 0;
+ globx = 0;
+ globy = 0;
for( py=0; py<x_velsize.height; py++ )
{
for( px=0; px<x_velsize.width; px++ )
@@ -386,8 +397,8 @@ void pix_opencv_of_bm :: processGrayImage(imageStruct &image)
orig.y = (py*comp_ysize)/x_velsize.height;
dest.x = (int)(orig.x + cvGet2D(x_velx, py, px).val[0]);
dest.y = (int)(orig.y + cvGet2D(x_vely, py, px).val[0]);
- angle = -atan2( (double) cvGet2D(x_vely, py, px).val[0], (double) cvGet2D(x_velx, py, px).val[0] );
- hypotenuse = sqrt( pow(orig.y - dest.y, 2) + pow(orig.x - dest.x, 2) );
+ angle = -atan2( (double) (dest.y-orig.y), (double) (dest.x-orig.x) );
+ hypotenuse = sqrt( pow(dest.y-orig.y, 2) + pow(dest.x-orig.x, 2) );
/* Now draw the tips of the arrow. I do some scaling so that the
* tips look proportional to the main line of the arrow.
@@ -402,8 +413,9 @@ void pix_opencv_of_bm :: processGrayImage(imageStruct &image)
orig.x = (int) (dest.x - (x_shiftsize.width/4) * cos(angle - M_PI / 4));
orig.y = (int) (dest.y + (x_shiftsize.height/4) * sin(angle - M_PI / 4));
cvLine( grey, orig, dest, CV_RGB(0,0,255), (int)hypotenuse/10, CV_AA, 0 );
- meanx = (meanx*nbblocks+cvGet2D(x_velx, py, px).val[0])/(nbblocks+1);
- meany = (meanx*nbblocks+cvGet2D(x_vely, py, px).val[0])/(nbblocks+1);
+
+ globx = globx+cvGet2D(x_velx, py, px).val[0];
+ globy = globy+cvGet2D(x_vely, py, px).val[0];
if ( hypotenuse > maxamp )
{
maxamp = hypotenuse;
@@ -416,26 +428,26 @@ void pix_opencv_of_bm :: processGrayImage(imageStruct &image)
}
}
- meanangle=-atan2( meany, meanx );
- // post( "pdp_opencv_of_bm : meanangle : %f", (meanangle*180)/M_PI );
-
if ( nbblocks >= x_minblocks )
{
+ globangle=-atan2( globy, globx );
+ // post( "pdp_opencv_of_bm : globangle : %f", (globangle*180)/M_PI );
+
orig.x = (int) (comp_xsize/2);
orig.y = (int) (comp_ysize/2);
- dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(meanangle));
- dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(meanangle));
+ dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(globangle));
+ dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(globangle));
cvLine( grey, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(meanangle + M_PI / 4));
- orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(meanangle + M_PI / 4));
+ orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(globangle + M_PI / 4));
+ orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(globangle + M_PI / 4));
cvLine( grey, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(meanangle - M_PI / 4));
- orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(meanangle - M_PI / 4));
+ orig.x = (int) (dest.x - (x_shiftsize.width/2) * cos(globangle - M_PI / 4));
+ orig.y = (int) (dest.y + (x_shiftsize.height/2) * sin(globangle - M_PI / 4));
cvLine( grey, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
// outputs the average angle of movement
- meanangle = (meanangle*180)/M_PI;
- SETFLOAT(&x_list[0], meanangle);
+ globangle = (globangle*180)/M_PI;
+ SETFLOAT(&x_list[0], globangle);
outlet_list( m_meanout, 0, 1, x_list );
// outputs the amplitude and angle of the maximum movement
diff --git a/pix_opencv_of_hs.cc b/pix_opencv_of_hs.cc
index fca8c75..c18bb14 100755
--- a/pix_opencv_of_hs.cc
+++ b/pix_opencv_of_hs.cc
@@ -81,7 +81,7 @@ pix_opencv_of_hs :: ~pix_opencv_of_hs()
void pix_opencv_of_hs :: processRGBAImage(imageStruct &image)
{
int px,py;
- double meanangle=0.0, meanx=0.0, meany=0.0, maxamp=0.0, maxangle=0.0;
+ double globangle=0.0, globx=0.0, globy=0.0, maxamp=0.0, maxangle=0.0;
int nbblocks=0;
CvPoint orig, dest;
double angle=0.0;
@@ -128,6 +128,9 @@ void pix_opencv_of_hs :: processRGBAImage(imageStruct &image)
cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03) );
nbblocks = 0;
+ globangle = 0;
+ globx = 0;
+ globy = 0;
for( py=0; py<x_velsize.height; py++ )
{
for( px=0; px<x_velsize.width; px++ )
@@ -136,8 +139,8 @@ void pix_opencv_of_hs :: processRGBAImage(imageStruct &image)
orig.y = (py*comp_ysize)/x_velsize.height;
dest.x = (int)(orig.x + cvGet2D(x_velx, py, px).val[0]);
dest.y = (int)(orig.y + cvGet2D(x_vely, py, px).val[0]);
- angle = -atan2( (double) cvGet2D(x_vely, py, px).val[0], (double) cvGet2D(x_velx, py, px).val[0] );
- hypotenuse = sqrt( pow(orig.y - dest.y, 2) + pow(orig.x - dest.x, 2) );
+ angle = -atan2( (double) (dest.y-orig.y), (double) (dest.x-orig.x) );
+ hypotenuse = sqrt( pow(dest.y-orig.y, 2) + pow(dest.x-orig.x, 2) );
/* Now draw the tips of the arrow. I do some scaling so that the
* tips look proportional to the main line of the arrow.
@@ -152,8 +155,9 @@ void pix_opencv_of_hs :: processRGBAImage(imageStruct &image)
orig.x = (int) (dest.x - (6) * cos(angle - M_PI / 4));
orig.y = (int) (dest.y + (6) * sin(angle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(0,0,255), 1, CV_AA, 0 );
- meanx = (meanx*nbblocks+cvGet2D(x_velx, py, px).val[0])/(nbblocks+1);
- meany = (meanx*nbblocks+cvGet2D(x_vely, py, px).val[0])/(nbblocks+1);
+
+ globx = globx+cvGet2D(x_velx, py, px).val[0];
+ globy = globy+cvGet2D(x_vely, py, px).val[0];
if ( hypotenuse > maxamp )
{
maxamp = hypotenuse;
@@ -166,26 +170,26 @@ void pix_opencv_of_hs :: processRGBAImage(imageStruct &image)
}
}
- meanangle=-atan2( meany, meanx );
- // post( "pdp_opencv_of_bm : meanangle : %f", (meanangle*180)/M_PI );
-
if ( nbblocks >= x_minblocks )
{
+ globangle=-atan2( globy, globx );
+ // post( "pdp_opencv_of_bm : globangle : %f", (globangle*180)/M_PI );
+
orig.x = (int) (comp_xsize/2);
orig.y = (int) (comp_ysize/2);
- dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(meanangle));
- dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(meanangle));
+ dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(globangle));
+ dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(globangle));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle + M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle + M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle + M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle + M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle - M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle - M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle - M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
// outputs the average angle of movement
- meanangle = (meanangle*180)/M_PI;
- SETFLOAT(&x_list[0], meanangle);
+ globangle = (globangle*180)/M_PI;
+ SETFLOAT(&x_list[0], globangle);
outlet_list( m_meanout, 0, 1, x_list );
// outputs the amplitude and angle of the maximum movement
@@ -204,7 +208,7 @@ void pix_opencv_of_hs :: processRGBAImage(imageStruct &image)
void pix_opencv_of_hs :: processRGBImage(imageStruct &image)
{
int px,py;
- double meanangle=0.0, meanx=0.0, meany=0.0, maxamp=0.0, maxangle=0.0;
+ double globangle=0.0, globx=0.0, globy=0.0, maxamp=0.0, maxangle=0.0;
int nbblocks=0;
CvPoint orig, dest;
double angle=0.0;
@@ -251,6 +255,9 @@ void pix_opencv_of_hs :: processRGBImage(imageStruct &image)
cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03) );
nbblocks = 0;
+ globangle = 0;
+ globx = 0;
+ globy = 0;
for( py=0; py<x_velsize.height; py++ )
{
for( px=0; px<x_velsize.width; px++ )
@@ -260,8 +267,8 @@ void pix_opencv_of_hs :: processRGBImage(imageStruct &image)
orig.y = (py*comp_ysize)/x_velsize.height;
dest.x = (int)(orig.x + cvGet2D(x_velx, py, px).val[0]);
dest.y = (int)(orig.y + cvGet2D(x_vely, py, px).val[0]);
- angle = -atan2( (double) cvGet2D(x_vely, py, px).val[0], (double) cvGet2D(x_velx, py, px).val[0] );
- hypotenuse = sqrt( pow(orig.y - dest.y, 2) + pow(orig.x - dest.x, 2) );
+ angle = -atan2( (double) (dest.y-orig.y), (double) (dest.x-orig.x) );
+ hypotenuse = sqrt( pow(dest.y-orig.y, 2) + pow(dest.x-orig.x, 2) );
/* Now draw the tips of the arrow. I do some scaling so that the
* tips look proportional to the main line of the arrow.
@@ -276,8 +283,9 @@ void pix_opencv_of_hs :: processRGBImage(imageStruct &image)
orig.x = (int) (dest.x - (6) * cos(angle - M_PI / 4));
orig.y = (int) (dest.y + (6) * sin(angle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(0,0,255), 1, CV_AA, 0 );
- meanx = (meanx*nbblocks+cvGet2D(x_velx, py, px).val[0])/(nbblocks+1);
- meany = (meanx*nbblocks+cvGet2D(x_vely, py, px).val[0])/(nbblocks+1);
+
+ globx = globx+cvGet2D(x_velx, py, px).val[0];
+ globy = globy+cvGet2D(x_vely, py, px).val[0];
if ( hypotenuse > maxamp )
{
maxamp = hypotenuse;
@@ -290,26 +298,26 @@ void pix_opencv_of_hs :: processRGBImage(imageStruct &image)
}
}
- meanangle=-atan2( meany, meanx );
- // post( "pdp_opencv_of_bm : meanangle : %f", (meanangle*180)/M_PI );
-
if ( nbblocks >= x_minblocks )
{
+ globangle=-atan2( globy, globx );
+ // post( "pdp_opencv_of_bm : globangle : %f", (globangle*180)/M_PI );
+
orig.x = (int) (comp_xsize/2);
orig.y = (int) (comp_ysize/2);
- dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(meanangle));
- dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(meanangle));
+ dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(globangle));
+ dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(globangle));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle + M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle + M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle + M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle + M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle - M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle - M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle - M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
// outputs the average angle of movement
- meanangle = (meanangle*180)/M_PI;
- SETFLOAT(&x_list[0], meanangle);
+ globangle = (globangle*180)/M_PI;
+ SETFLOAT(&x_list[0], globangle);
outlet_list( m_meanout, 0, 1, x_list );
// outputs the amplitude and angle of the maximum movement
@@ -332,7 +340,7 @@ void pix_opencv_of_hs :: processYUVImage(imageStruct &image)
void pix_opencv_of_hs :: processGrayImage(imageStruct &image)
{
int px,py;
- double meanangle=0.0, meanx=0.0, meany=0.0, maxamp=0.0, maxangle=0.0;
+ double globangle=0.0, globx=0.0, globy=0.0, maxamp=0.0, maxangle=0.0;
int nbblocks=0;
CvPoint orig, dest;
double angle=0.0;
@@ -375,6 +383,9 @@ void pix_opencv_of_hs :: processGrayImage(imageStruct &image)
cvTermCriteria(CV_TERMCRIT_ITER|CV_TERMCRIT_EPS,20,0.03) );
nbblocks = 0;
+ globangle = 0;
+ globx = 0;
+ globy = 0;
for( py=0; py<x_velsize.height; py++ )
{
for( px=0; px<x_velsize.width; px++ )
@@ -384,8 +395,8 @@ void pix_opencv_of_hs :: processGrayImage(imageStruct &image)
orig.y = (py*comp_ysize)/x_velsize.height;
dest.x = (int)(orig.x + cvGet2D(x_velx, py, px).val[0]);
dest.y = (int)(orig.y + cvGet2D(x_vely, py, px).val[0]);
- angle = -atan2( (double) cvGet2D(x_vely, py, px).val[0], (double) cvGet2D(x_velx, py, px).val[0] );
- hypotenuse = sqrt( pow(orig.y - dest.y, 2) + pow(orig.x - dest.x, 2) );
+ angle = -atan2( (double) (dest.y-orig.y), (double) (dest.x-orig.x) );
+ hypotenuse = sqrt( pow(dest.y-orig.y, 2) + pow(dest.x-orig.x, 2) );
/* Now draw the tips of the arrow. I do some scaling so that the
* tips look proportional to the main line of the arrow.
@@ -400,8 +411,9 @@ void pix_opencv_of_hs :: processGrayImage(imageStruct &image)
orig.x = (int) (dest.x - (6) * cos(angle - M_PI / 4));
orig.y = (int) (dest.y + (6) * sin(angle - M_PI / 4));
cvLine( grey, orig, dest, CV_RGB(0,0,255), 1, CV_AA, 0 );
- meanx = (meanx*nbblocks+cvGet2D(x_velx, py, px).val[0])/(nbblocks+1);
- meany = (meanx*nbblocks+cvGet2D(x_vely, py, px).val[0])/(nbblocks+1);
+
+ globx = globx+cvGet2D(x_velx, py, px).val[0];
+ globy = globx+cvGet2D(x_vely, py, px).val[0];
if ( hypotenuse > maxamp )
{
maxamp = hypotenuse;
@@ -414,26 +426,26 @@ void pix_opencv_of_hs :: processGrayImage(imageStruct &image)
}
}
- meanangle=-atan2( meany, meanx );
- // post( "pdp_opencv_of_bm : meanangle : %f", (meanangle*180)/M_PI );
-
if ( nbblocks >= x_minblocks )
{
+ globangle=-atan2( globy, globx );
+ // post( "pdp_opencv_of_bm : globangle : %f", (globangle*180)/M_PI );
+
orig.x = (int) (comp_xsize/2);
orig.y = (int) (comp_ysize/2);
- dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(meanangle));
- dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(meanangle));
+ dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(globangle));
+ dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(globangle));
cvLine( grey, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle + M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle + M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle + M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle + M_PI / 4));
cvLine( grey, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle - M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle - M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle - M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle - M_PI / 4));
cvLine( grey, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
// outputs the average angle of movement
- meanangle = (meanangle*180)/M_PI;
- SETFLOAT(&x_list[0], meanangle);
+ globangle = (globangle*180)/M_PI;
+ SETFLOAT(&x_list[0], globangle);
outlet_list( m_meanout, 0, 1, x_list );
// outputs the amplitude and angle of the maximum movement
diff --git a/pix_opencv_of_lk-help.pd b/pix_opencv_of_lk-help.pd
index e059d03..8d501d4 100755
--- a/pix_opencv_of_lk-help.pd
+++ b/pix_opencv_of_lk-help.pd
@@ -1,4 +1,4 @@
-#N canvas 1 49 1424 780 10;
+#N canvas 12 61 1424 780 10;
#X obj 977 55 cnv 15 220 70 empty empty empty 20 12 0 14 -195568 -66577
0;
#N canvas 189 149 454 304 gemwin 0;
@@ -128,23 +128,25 @@ average direction and the intensity of the movement in a video stream.
#X text 977 205 comments to ydegoyon@gmail.com;
#X text 976 129 pix_opencv_of_lk : Lucas Kanade optical flow algorithm.
;
-#X obj 600 405 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
+#X obj 599 419 tgl 15 0 empty empty empty 17 7 0 10 -262144 -1 -1 0
1;
-#X msg 515 403 nightmode \$1;
-#X floatatom 585 325 5 0 0 0 - - -;
-#X floatatom 589 350 5 0 0 0 - - -;
-#X msg 502 348 threshold \$1;
-#X msg 505 377 minblocks \$1;
-#X floatatom 592 378 5 0 0 0 - - -;
-#X text 619 406 set nightmode;
-#X text 636 372 minimum nuber of blocks to detect the movement;
-#X text 633 385 ( default 10 );
-#X msg 491 323 winsize \$1 \$2;
-#X text 628 322 set window size ( width height ) [ default : 10x10
-];
-#X text 630 346 threshold value for the detection of movement ( default
-100 );
+#X msg 514 417 nightmode \$1;
+#X floatatom 585 311 5 0 0 0 - - -;
+#X floatatom 588 364 5 0 0 0 - - -;
+#X msg 501 362 threshold \$1;
+#X msg 504 391 minblocks \$1;
+#X floatatom 591 392 5 0 0 0 - - -;
+#X text 621 418 set nightmode;
+#X text 629 386 minimum nuber of blocks to detect the movement;
+#X text 626 399 ( default 10 );
+#X msg 491 309 winsize \$1 \$2;
#X obj 454 444 pix_opencv_of_lk;
+#X text 628 312 set window size ( width height ) [ default : 9x9 ]
+;
+#X text 630 328 window width and height must be oneof (1 \, 3 \, 5
+\, 7 \, 9 \, 11 \, 13 \, 15);
+#X text 627 363 threshold value for the detection of movement (default
+100);
#X connect 1 0 2 0;
#X connect 2 0 1 0;
#X connect 5 0 6 0;
@@ -163,7 +165,9 @@ average direction and the intensity of the movement in a video stream.
#X connect 25 0 22 0;
#X connect 25 0 34 0;
#X connect 26 0 22 0;
+#X connect 26 0 34 0;
#X connect 27 0 22 0;
+#X connect 27 0 34 0;
#X connect 28 0 25 0;
#X connect 28 0 24 0;
#X connect 29 0 30 0;
@@ -180,17 +184,17 @@ average direction and the intensity of the movement in a video stream.
#X connect 39 0 34 0;
#X connect 40 0 41 0;
#X connect 42 0 45 0;
-#X connect 43 0 65 0;
+#X connect 43 0 63 0;
#X connect 46 0 29 0;
#X connect 47 0 16 0;
#X connect 52 0 53 0;
-#X connect 53 0 65 0;
+#X connect 53 0 63 0;
#X connect 54 0 62 0;
#X connect 55 0 56 0;
-#X connect 56 0 65 0;
-#X connect 57 0 65 0;
+#X connect 56 0 63 0;
+#X connect 57 0 63 0;
#X connect 58 0 57 0;
-#X connect 62 0 65 0;
-#X connect 65 0 42 0;
-#X connect 65 1 11 0;
-#X connect 65 2 5 0;
+#X connect 62 0 63 0;
+#X connect 63 0 42 0;
+#X connect 63 1 11 0;
+#X connect 63 2 5 0;
diff --git a/pix_opencv_of_lk.cc b/pix_opencv_of_lk.cc
index d3c5460..fb64a4e 100755
--- a/pix_opencv_of_lk.cc
+++ b/pix_opencv_of_lk.cc
@@ -39,8 +39,8 @@ pix_opencv_of_lk :: pix_opencv_of_lk()
x_nightmode=0;
x_threshold=100;
- x_winsize.width = 10;
- x_winsize.height = 10;
+ x_winsize.width = 9;
+ x_winsize.height = 9;
x_minblocks = 10;
x_velsize.width = comp_xsize;
x_velsize.height = comp_ysize;
@@ -81,7 +81,7 @@ pix_opencv_of_lk :: ~pix_opencv_of_lk()
void pix_opencv_of_lk :: processRGBAImage(imageStruct &image)
{
int px,py;
- double meanangle=0.0, meanx=0.0, meany=0.0, maxamp=0.0, maxangle=0.0;
+ double globangle=0.0, globx=0.0, globy=0.0, maxamp=0.0, maxangle=0.0;
int nbblocks=0;
CvPoint orig, dest;
double angle=0.0;
@@ -125,6 +125,9 @@ void pix_opencv_of_lk :: processRGBAImage(imageStruct &image)
x_winsize, x_velx, x_vely );
nbblocks = 0;
+ globangle = 0;
+ globx = 0;
+ globy = 0;
for( py=0; py<x_velsize.height; py++ )
{
for( px=0; px<x_velsize.width; px++ )
@@ -133,8 +136,8 @@ void pix_opencv_of_lk :: processRGBAImage(imageStruct &image)
orig.y = (py*comp_ysize)/x_velsize.height;
dest.x = (int)(orig.x + cvGet2D(x_velx, py, px).val[0]);
dest.y = (int)(orig.y + cvGet2D(x_vely, py, px).val[0]);
- angle = -atan2( (double) cvGet2D(x_vely, py, px).val[0], (double) cvGet2D(x_velx, py, px).val[0] );
- hypotenuse = sqrt( pow(orig.y - dest.y, 2) + pow(orig.x - dest.x, 2) );
+ angle = -atan2( (double) (dest.y-orig.y), (double) (dest.x-orig.x) );
+ hypotenuse = sqrt( pow(dest.y-orig.y, 2) + pow(dest.x-orig.x, 2) );
/* Now draw the tips of the arrow. I do some scaling so that the
* tips look proportional to the main line of the arrow.
@@ -149,8 +152,9 @@ void pix_opencv_of_lk :: processRGBAImage(imageStruct &image)
orig.x = (int) (dest.x - (6) * cos(angle - M_PI / 4));
orig.y = (int) (dest.y + (6) * sin(angle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(0,0,255), 1, CV_AA, 0 );
- meanx = (meanx*nbblocks+cvGet2D(x_velx, py, px).val[0])/(nbblocks+1);
- meany = (meanx*nbblocks+cvGet2D(x_vely, py, px).val[0])/(nbblocks+1);
+
+ globx = globx+cvGet2D(x_velx, py, px).val[0];
+ globy = globy+cvGet2D(x_vely, py, px).val[0];
if ( hypotenuse > maxamp )
{
maxamp = hypotenuse;
@@ -163,26 +167,27 @@ void pix_opencv_of_lk :: processRGBAImage(imageStruct &image)
}
}
- meanangle=-atan2( meany, meanx );
- // post( "pdp_opencv_of_bm : meanangle : %f", (meanangle*180)/M_PI );
-
if ( nbblocks >= x_minblocks )
{
+ globangle=-atan2( globy, globx );
+ // post( "pdp_opencv_of_bm : globangle : %f", (globangle*180)/M_PI );
+
orig.x = (int) (comp_xsize/2);
orig.y = (int) (comp_ysize/2);
- dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(meanangle));
- dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(meanangle));
+ dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(globangle));
+ dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(globangle));
+
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle + M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle + M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle + M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle + M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle - M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle - M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle - M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
// outputs the average angle of movement
- meanangle = (meanangle*180)/M_PI;
- SETFLOAT(&x_list[0], meanangle);
+ globangle = (globangle*180)/M_PI;
+ SETFLOAT(&x_list[0], globangle);
outlet_list( m_meanout, 0, 1, x_list );
// outputs the amplitude and angle of the maximum movement
@@ -201,7 +206,7 @@ void pix_opencv_of_lk :: processRGBAImage(imageStruct &image)
void pix_opencv_of_lk :: processRGBImage(imageStruct &image)
{
int px,py;
- double meanangle=0.0, meanx=0.0, meany=0.0, maxamp=0.0, maxangle=0.0;
+ double globangle=0.0, globx=0.0, globy=0.0, maxamp=0.0, maxangle=0.0;
int nbblocks=0;
CvPoint orig, dest;
double angle=0.0;
@@ -245,6 +250,9 @@ void pix_opencv_of_lk :: processRGBImage(imageStruct &image)
x_winsize, x_velx, x_vely );
nbblocks = 0;
+ globangle = 0;
+ globx = 0;
+ globy = 0;
for( py=0; py<x_velsize.height; py++ )
{
for( px=0; px<x_velsize.width; px++ )
@@ -254,8 +262,8 @@ void pix_opencv_of_lk :: processRGBImage(imageStruct &image)
orig.y = (py*comp_ysize)/x_velsize.height;
dest.x = (int)(orig.x + cvGet2D(x_velx, py, px).val[0]);
dest.y = (int)(orig.y + cvGet2D(x_vely, py, px).val[0]);
- angle = -atan2( (double) cvGet2D(x_vely, py, px).val[0], (double) cvGet2D(x_velx, py, px).val[0] );
- hypotenuse = sqrt( pow(orig.y - dest.y, 2) + pow(orig.x - dest.x, 2) );
+ angle = -atan2( (double) (dest.y-orig.y), (double) (dest.x-orig.x) );
+ hypotenuse = sqrt( pow(dest.y-orig.y, 2) + pow(dest.x-orig.x, 2) );
/* Now draw the tips of the arrow. I do some scaling so that the
* tips look proportional to the main line of the arrow.
@@ -270,8 +278,9 @@ void pix_opencv_of_lk :: processRGBImage(imageStruct &image)
orig.x = (int) (dest.x - (6) * cos(angle - M_PI / 4));
orig.y = (int) (dest.y + (6) * sin(angle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(0,0,255), 1, CV_AA, 0 );
- meanx = (meanx*nbblocks+cvGet2D(x_velx, py, px).val[0])/(nbblocks+1);
- meany = (meanx*nbblocks+cvGet2D(x_vely, py, px).val[0])/(nbblocks+1);
+
+ globx = globx+cvGet2D(x_velx, py, px).val[0];
+ globy = globy+cvGet2D(x_vely, py, px).val[0];
if ( hypotenuse > maxamp )
{
maxamp = hypotenuse;
@@ -284,26 +293,27 @@ void pix_opencv_of_lk :: processRGBImage(imageStruct &image)
}
}
- meanangle=-atan2( meany, meanx );
- // post( "pdp_opencv_of_bm : meanangle : %f", (meanangle*180)/M_PI );
-
if ( nbblocks >= x_minblocks )
{
+ globangle=-atan2( globy, globx );
+ // post( "pdp_opencv_of_bm : globangle : %f", (globangle*180)/M_PI );
+
orig.x = (int) (comp_xsize/2);
orig.y = (int) (comp_ysize/2);
- dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(meanangle));
- dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(meanangle));
+ dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(globangle));
+ dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(globangle));
+
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle + M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle + M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle + M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle + M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle - M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle - M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle - M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle - M_PI / 4));
cvLine( rgb, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
// outputs the average angle of movement
- meanangle = (meanangle*180)/M_PI;
- SETFLOAT(&x_list[0], meanangle);
+ globangle = (globangle*180)/M_PI;
+ SETFLOAT(&x_list[0], globangle);
outlet_list( m_meanout, 0, 1, x_list );
// outputs the amplitude and angle of the maximum movement
@@ -326,7 +336,7 @@ void pix_opencv_of_lk :: processYUVImage(imageStruct &image)
void pix_opencv_of_lk :: processGrayImage(imageStruct &image)
{
int px,py;
- double meanangle=0.0, meanx=0.0, meany=0.0, maxamp=0.0, maxangle=0.0;
+ double globangle=0.0, globx=0.0, globy=0.0, maxamp=0.0, maxangle=0.0;
int nbblocks=0;
CvPoint orig, dest;
double angle=0.0;
@@ -366,6 +376,9 @@ void pix_opencv_of_lk :: processGrayImage(imageStruct &image)
x_winsize, x_velx, x_vely );
nbblocks = 0;
+ globangle = 0;
+ globx = 0;
+ globy = 0;
for( py=0; py<x_velsize.height; py++ )
{
for( px=0; px<x_velsize.width; px++ )
@@ -375,8 +388,8 @@ void pix_opencv_of_lk :: processGrayImage(imageStruct &image)
orig.y = (py*comp_ysize)/x_velsize.height;
dest.x = (int)(orig.x + cvGet2D(x_velx, py, px).val[0]);
dest.y = (int)(orig.y + cvGet2D(x_vely, py, px).val[0]);
- angle = -atan2( (double) cvGet2D(x_vely, py, px).val[0], (double) cvGet2D(x_velx, py, px).val[0] );
- hypotenuse = sqrt( pow(orig.y - dest.y, 2) + pow(orig.x - dest.x, 2) );
+ angle = -atan2( (double) (dest.y-orig.y), (double) (dest.x-orig.x) );
+ hypotenuse = sqrt( pow(dest.y-orig.y, 2) + pow(dest.x-orig.x, 2) );
/* Now draw the tips of the arrow. I do some scaling so that the
* tips look proportional to the main line of the arrow.
@@ -391,8 +404,9 @@ void pix_opencv_of_lk :: processGrayImage(imageStruct &image)
orig.x = (int) (dest.x - (6) * cos(angle - M_PI / 4));
orig.y = (int) (dest.y + (6) * sin(angle - M_PI / 4));
cvLine( grey, orig, dest, CV_RGB(0,0,255), 1, CV_AA, 0 );
- meanx = (meanx*nbblocks+cvGet2D(x_velx, py, px).val[0])/(nbblocks+1);
- meany = (meanx*nbblocks+cvGet2D(x_vely, py, px).val[0])/(nbblocks+1);
+
+ globx = globx+cvGet2D(x_velx, py, px).val[0];
+ globy = globy+cvGet2D(x_vely, py, px).val[0];
if ( hypotenuse > maxamp )
{
maxamp = hypotenuse;
@@ -405,26 +419,27 @@ void pix_opencv_of_lk :: processGrayImage(imageStruct &image)
}
}
- meanangle=-atan2( meany, meanx );
- // post( "pdp_opencv_of_bm : meanangle : %f", (meanangle*180)/M_PI );
+ globangle=-atan2( globy, globx );
+ // post( "pdp_opencv_of_bm : globangle : %f", (globangle*180)/M_PI );
if ( nbblocks >= x_minblocks )
{
orig.x = (int) (comp_xsize/2);
orig.y = (int) (comp_ysize/2);
- dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(meanangle));
- dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(meanangle));
+ dest.x = (int) (orig.x+((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*cos(globangle));
+ dest.y = (int) (orig.y-((comp_xsize>comp_ysize)?comp_ysize/2:comp_xsize/2)*sin(globangle));
+
cvLine( grey, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle + M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle + M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle + M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle + M_PI / 4));
cvLine( grey, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
- orig.x = (int) (dest.x - (6) * cos(meanangle - M_PI / 4));
- orig.y = (int) (dest.y + (6) * sin(meanangle - M_PI / 4));
+ orig.x = (int) (dest.x - (6) * cos(globangle - M_PI / 4));
+ orig.y = (int) (dest.y + (6) * sin(globangle - M_PI / 4));
cvLine( grey, orig, dest, CV_RGB(255,255,255), 3, CV_AA, 0 );
// outputs the average angle of movement
- meanangle = (meanangle*180)/M_PI;
- SETFLOAT(&x_list[0], meanangle);
+ globangle = (globangle*180)/M_PI;
+ SETFLOAT(&x_list[0], globangle);
outlet_list( m_meanout, 0, 1, x_list );
// outputs the amplitude and angle of the maximum movement
@@ -488,8 +503,10 @@ void pix_opencv_of_lk :: tresholdMess(float threshold)
void pix_opencv_of_lk :: winsizeMess(float fwidth, float fheight)
{
- if (fwidth>=5.0) x_winsize.width = (int)fwidth;
- if (fheight>=5.0) x_winsize.height = (int)fheight;
+ if (fwidth==1.0 || fwidth==3.0 || fwidth==5.0 || fwidth==7.0 || fwidth==9.0 || fwidth==11.0 || fwidth==13.0 || fwidth==15.0 ) x_winsize.width = (int)fwidth;
+ else post( "pdp_opencv_of_lk : wrong winsize width : must be one of (1,3,5,7,9,11,13,15)" );
+ if (fheight==1.0 || fheight==3.0 || fheight==5.0 || fheight==7.0 || fheight==9.0 || fheight==11.0 || fheight==13.0 || fheight==15.0 ) x_winsize.height = (int)fheight;
+ else post( "pdp_opencv_of_lk : wrong winsize height : must be one of (1,3,5,7,9,11,13,15)" );
}
void pix_opencv_of_lk :: minBlocksMess(float minblocks)