Skip to content

Commit daa2448

Browse files
committed
text: filter CNN detection results
- instead of validation checks
1 parent 8fde8d7 commit daa2448

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

modules/text/src/text_detectorCNN.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,29 @@ class TextDetectorCNNImpl : public TextDetectorCNN
2929
{
3030
for(int k = 0; k < nbrTextBoxes; k++)
3131
{
32-
float x_min = buffer[k*nCol + 3]*inputShape.width;
33-
float y_min = buffer[k*nCol + 4]*inputShape.height;
32+
float confidence_ = buffer[k*nCol + 2];
33+
if (confidence_ <= FLT_EPSILON) continue;
3434

35-
float x_max = buffer[k*nCol + 5]*inputShape.width;
36-
float y_max = buffer[k*nCol + 6]*inputShape.height;
35+
float x_min_f = buffer[k*nCol + 3]*inputShape.width;
36+
float y_min_f = buffer[k*nCol + 4]*inputShape.height;
3737

38-
CV_CheckLT(x_min, x_max, "");
39-
CV_CheckLT(y_min, y_max, "");
38+
float x_max_f = buffer[k*nCol + 5]*inputShape.width;
39+
float y_max_f = buffer[k*nCol + 6]*inputShape.height;
4040

41-
x_min = std::max(0.f, x_min);
42-
y_min = std::max(0.f, y_min);
41+
int x_min = cvRound(std::max(0.f, x_min_f));
42+
int y_min = cvRound(std::max(0.f, y_min_f));
4343

44-
x_max = std::min(inputShape.width - 1.f, x_max);
45-
y_max = std::min(inputShape.height - 1.f, y_max);
44+
int x_max = std::min(inputShape.width - 1, cvRound(x_max_f));
45+
int y_max = std::min(inputShape.height - 1, cvRound(y_max_f));
4646

47-
int wd = cvRound(x_max - x_min);
48-
int ht = cvRound(y_max - y_min);
47+
if (x_min >= x_max) continue;
48+
if (y_min >= y_max) continue;
4949

50-
Bbox.push_back(Rect(cvRound(x_min), cvRound(y_min), wd, ht));
51-
confidence.push_back(buffer[k*nCol + 2]);
50+
int wd = x_max - x_min;
51+
int ht = y_max - y_min;
52+
53+
Bbox.push_back(Rect(x_min, y_min, wd, ht));
54+
confidence.push_back(confidence_);
5255
}
5356
}
5457

0 commit comments

Comments
 (0)