Merge pull request #1403 from lluisgomez:scene_text_detection_NM_fix

This commit is contained in:
Roman Donchenko 2013-09-09 12:05:56 +04:00 committed by OpenCV Buildbot
commit 74578f56a9
4 changed files with 6599 additions and 6588 deletions

View File

@ -172,8 +172,8 @@ public:
\param minProbability The minimum probability difference between local maxima and local minima ERs
*/
CV_EXPORTS Ptr<ERFilter> createERFilterNM1(const Ptr<ERFilter::Callback>& cb = Ptr<ERFilter::Callback>(),
int thresholdDelta = 1, float minArea = 0.000025,
float maxArea = 0.13, float minProbability = 0.2,
int thresholdDelta = 1, float minArea = 0.00025,
float maxArea = 0.13, float minProbability = 0.4,
bool nonMaxSuppression = true,
float minProbabilityDiff = 0.1);
@ -191,7 +191,7 @@ CV_EXPORTS Ptr<ERFilter> createERFilterNM1(const Ptr<ERFilter::Callback>& cb = P
\param minProbability The minimum probability P(er|character) allowed for retreived ER's
*/
CV_EXPORTS Ptr<ERFilter> createERFilterNM2(const Ptr<ERFilter::Callback>& cb = Ptr<ERFilter::Callback>(),
float minProbability = 0.85);
float minProbability = 0.3);
}
#endif // _OPENCV_ERFILTER_HPP_

View File

@ -631,9 +631,10 @@ void ERFilterNM::er_merge(ERStat *parent, ERStat *child)
child->probability = classifier->eval(*child);
}
if ( ((classifier!=NULL)?(child->probability >= minProbability):true) &&
if ( (((classifier!=NULL)?(child->probability >= minProbability):true)||(nonMaxSuppression)) &&
((child->area >= (minArea*region_mask.rows*region_mask.cols)) &&
(child->area <= (maxArea*region_mask.rows*region_mask.cols))) )
(child->area <= (maxArea*region_mask.rows*region_mask.cols)) &&
(child->rect.width > 2) && (child->rect.height > 2)) )
{
num_accepted_regions++;
@ -699,18 +700,24 @@ ERStat* ERFilterNM::er_save( ERStat *er, ERStat *parent, ERStat *prev )
regions->back().parent = parent;
if (prev != NULL)
{
prev->next = &(regions->back());
}
else if (parent != NULL)
parent->child = &(regions->back());
ERStat *old_prev = NULL;
ERStat *this_er = &regions->back();
if (this_er->parent == NULL)
{
this_er->probability = 0;
}
if (nonMaxSuppression)
{
if (this_er->parent == NULL)
{
this_er->probability = 0; //TODO this makes sense in order to select at least one region in short tree's but is it really necessary?
this_er->max_probability_ancestor = this_er;
this_er->min_probability_ancestor = this_er;
}
@ -722,15 +729,22 @@ ERStat* ERFilterNM::er_save( ERStat *er, ERStat *parent, ERStat *prev )
if ( (this_er->max_probability_ancestor->probability > minProbability) && (this_er->max_probability_ancestor->probability - this_er->min_probability_ancestor->probability > minProbabilityDiff))
{
this_er->max_probability_ancestor->local_maxima = true;
//TODO check here if the last local_maxima can be also suppressed, is the following correct?
//if (this_er->min_probability_ancestor->local_maxima)
// this_er->min_probability_ancestor->local_maxima = false;
this_er->max_probability_ancestor = this_er;
this_er->min_probability_ancestor = this_er;
this_er->max_probability_ancestor->local_maxima = true;
if ((this_er->max_probability_ancestor == this_er) && (this_er->parent->local_maxima))
{
this_er->parent->local_maxima = false;
}
}
else if (this_er->probability < this_er->parent->probability)
{
this_er->min_probability_ancestor = this_er;
}
else if (this_er->probability > this_er->parent->probability)
{
this_er->max_probability_ancestor = this_er;
}
}
}
@ -769,8 +783,7 @@ ERStat* ERFilterNM::er_tree_filter ( InputArray image, ERStat * stat, ERStat *pa
findContours( region, contours, hierarchy, RETR_TREE, CHAIN_APPROX_NONE, Point(0, 0) );
//TODO check epsilon parameter of approxPolyDP (set empirically) : we want more precission
// if the region is very small because otherwise we'll loose all the convexities
approxPolyDP( Mat(contours[0]), contour_poly, max(rect.width,rect.height)/25, true );
approxPolyDP( Mat(contours[0]), contour_poly, (float)min(rect.width,rect.height)/17, true );
bool was_convex = false;
int num_inflexion_points = 0;
@ -1120,7 +1133,6 @@ Ptr<ERFilter> createERFilterNM2(const Ptr<ERFilter::Callback>& cb, float minProb
Ptr<ERFilterNM> filter = makePtr<ERFilterNM>();
if (cb == NULL)
filter->setCallback(makePtr<ERClassifierNM2>());
else
@ -1129,5 +1141,4 @@ Ptr<ERFilter> createERFilterNM2(const Ptr<ERFilter::Callback>& cb, float minProb
filter->setMinProbability(minProbability);
return (Ptr<ERFilter>)filter;
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff