Skip to content

Commit 590dc29

Browse files
committed
text: fix valgrind errors, minor changes
1 parent afd8a83 commit 590dc29

File tree

2 files changed

+18
-25
lines changed

2 files changed

+18
-25
lines changed

modules/text/samples/detect_er_chars.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
import cv2
77
import numpy as np
8-
from matplotlib import pyplot as plt
98

109
print('\ndetect_er_chars.py')
1110
print(' A simple demo script using the Extremal Region Filter algorithm described in:')
@@ -32,8 +31,8 @@
3231
#Visualization
3332
rects = [cv2.boundingRect(p.reshape(-1, 1, 2)) for p in regions]
3433
for rect in rects:
35-
cv2.rectangle(img, rect[0:2], (rect[0]+rect[2],rect[1]+rect[3]), (0, 0, 255), 2)
36-
img = img[:,:,::-1] #flip the colors dimension from BGR to RGB
37-
plt.imshow(img)
38-
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
39-
plt.show()
34+
cv2.rectangle(img, rect[0:2], (rect[0]+rect[2],rect[1]+rect[3]), (0, 0, 0), 2)
35+
for rect in rects:
36+
cv2.rectangle(img, rect[0:2], (rect[0]+rect[2],rect[1]+rect[3]), (255, 255, 255), 1)
37+
cv2.imshow("Text detection result", img)
38+
cv2.waitKey(0)

modules/text/src/erfilter.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -275,24 +275,18 @@ void ERFilterNM::er_tree_extract( InputArray image )
275275
// the component stack
276276
vector<ERStat*> er_stack;
277277

278-
//the quads for euler number calculation
279-
unsigned char quads[3][4];
280-
quads[0][0] = 1 << 3;
281-
quads[0][1] = 1 << 2;
282-
quads[0][2] = 1 << 1;
283-
quads[0][3] = 1;
284-
quads[1][0] = (1<<2)|(1<<1)|(1);
285-
quads[1][1] = (1<<3)|(1<<1)|(1);
286-
quads[1][2] = (1<<3)|(1<<2)|(1);
287-
quads[1][3] = (1<<3)|(1<<2)|(1<<1);
288-
quads[2][0] = (1<<2)|(1<<1);
289-
quads[2][1] = (1<<3)|(1);
290-
// quads[2][2] and quads[2][3] are never used so no need to initialize them.
278+
// the quads for euler number calculation
279+
// quads[2][2] and quads[2][3] are never used.
291280
// The four lowest bits in each quads[i][j] correspond to the 2x2 binary patterns
292281
// Q_1, Q_2, Q_3 in the Neumann and Matas CVPR 2012 paper
293282
// (see in page 4 at the end of first column).
294283
// Q_1 and Q_2 have four patterns, while Q_3 has only two.
295-
284+
const int quads[3][4] =
285+
{
286+
{ 1<<3 , 1<<2 , 1<<1 , 1<<0 },
287+
{ (1<<2)|(1<<1)|(1), (1<<3)| (1<<1)|(1), (1<<3)|(1<<2)| (1), (1<<3)|(1<<2)|(1<<1) },
288+
{ (1<<2)|(1<<1) , (1<<3)| (1), /*unused*/-1, /*unused*/-1 }
289+
};
296290

297291
// masks to know if a pixel is accessible and if it has been already added to some region
298292
vector<bool> accessible_pixel_mask(width * height);
@@ -392,8 +386,8 @@ void ERFilterNM::er_tree_extract( InputArray image )
392386
int non_boundary_neighbours = 0;
393387
int non_boundary_neighbours_horiz = 0;
394388

395-
unsigned char quad_before[4] = {0,0,0,0};
396-
unsigned char quad_after[4] = {0,0,0,0};
389+
int quad_before[4] = {0,0,0,0};
390+
int quad_after[4] = {0,0,0,0};
397391
quad_after[0] = 1<<1;
398392
quad_after[1] = 1<<3;
399393
quad_after[2] = 1<<2;
@@ -542,9 +536,9 @@ void ERFilterNM::er_tree_extract( InputArray image )
542536
current_edge = boundary_edges[threshold_level].back();
543537
boundary_edges[threshold_level].erase(boundary_edges[threshold_level].end()-1);
544538

545-
while (boundary_pixes[threshold_level].empty() && (threshold_level < (255/thresholdDelta)+1))
546-
threshold_level++;
547-
539+
for (; threshold_level < (255/thresholdDelta)+1; threshold_level++)
540+
if (!boundary_pixes[threshold_level].empty())
541+
break;
548542

549543
int new_level = image_data[current_pixel];
550544

0 commit comments

Comments
 (0)