From b3408a9b3a0d899ef52543c99e3d7a79fd34db3c Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 11 Sep 2012 13:56:25 +0400 Subject: [PATCH] fixed bug #2186 (thanks to Joao Soares for the patch) --- modules/imgproc/src/approx.cpp | 8 ++++++-- modules/imgproc/src/generalized_hough.cpp | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/imgproc/src/approx.cpp b/modules/imgproc/src/approx.cpp index bd0e3dabd3..773c9e74b2 100644 --- a/modules/imgproc/src/approx.cpp +++ b/modules/imgproc/src/approx.cpp @@ -642,13 +642,17 @@ icvApproxPolyDP( CvSeq* src_contour, int header_size, new_count = count = dst_contour->total; for( i = !is_closed; i < count - !is_closed && new_count > 2; i++ ) { - double dx, dy, dist; + double dx, dy, dist, successive_inner_product; CV_READ_SEQ_ELEM( end_pt, reader ); dx = end_pt.x - start_pt.x; dy = end_pt.y - start_pt.y; dist = fabs((pt.x - start_pt.x)*dy - (pt.y - start_pt.y)*dx); - if( dist * dist <= 0.5*eps*(dx*dx + dy*dy) && dx != 0 && dy != 0 ) + successive_inner_product = (pt.x - start_pt.x) * (end_pt.x - pt.x) + + (pt.y - start_pt.y) * (end_pt.y - pt.y); + + if( dist * dist <= 0.5*eps*(dx*dx + dy*dy) && dx != 0 && dy != 0 && + successive_inner_product >= 0 ) { new_count--; *((PT*)reader2.ptr) = start_pt = end_pt; diff --git a/modules/imgproc/src/generalized_hough.cpp b/modules/imgproc/src/generalized_hough.cpp index 4895b55e9d..e07a5f0b38 100644 --- a/modules/imgproc/src/generalized_hough.cpp +++ b/modules/imgproc/src/generalized_hough.cpp @@ -64,10 +64,10 @@ namespace { return fabs(v) > numeric_limits::epsilon(); } - bool notNull(double v) + /*bool notNull(double v) { return fabs(v) > numeric_limits::epsilon(); - } + }*/ class GHT_Pos : public GeneralizedHough {