From 5dc1d97357e3519da6c595c21682aa00a58624ff Mon Sep 17 00:00:00 2001 From: "N.N." Date: Tue, 13 Jul 2010 20:39:43 +0000 Subject: fixed angle calculations svn path=/trunk/externals/pix_opencv/; revision=13712 --- pix_opencv_of_bm.cc | 108 +++++++++++++++++++++++++++++----------------------- 1 file changed, 60 insertions(+), 48 deletions(-) (limited to 'pix_opencv_of_bm.cc') 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 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 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 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 -- cgit v1.2.1