Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv_contrib
Commits
d6320797
Commit
d6320797
authored
Nov 25, 2016
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
text: update detectRegions()
parent
590dc298
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
18 additions
and
23 deletions
+18
-23
textdetection.py
modules/text/samples/textdetection.py
+4
-6
erfilter.cpp
modules/text/src/erfilter.cpp
+14
-17
No files found.
modules/text/samples/textdetection.py
View file @
d6320797
...
...
@@ -5,7 +5,6 @@ import os
import
cv2
import
numpy
as
np
from
matplotlib
import
pyplot
as
plt
print
(
'
\n
textdetection.py'
)
print
(
' A demo script of the Extremal Region Filter algorithm described in:'
)
...
...
@@ -50,11 +49,10 @@ for channel in channels:
#Visualization
for
r
in
range
(
0
,
np
.
shape
(
rects
)[
0
]):
rect
=
rects
[
r
]
cv2
.
rectangle
(
vis
,
(
rect
[
0
],
rect
[
1
]),
(
rect
[
0
]
+
rect
[
2
],
rect
[
1
]
+
rect
[
3
]),
(
0
,
255
,
255
),
2
)
cv2
.
rectangle
(
vis
,
(
rect
[
0
],
rect
[
1
]),
(
rect
[
0
]
+
rect
[
2
],
rect
[
1
]
+
rect
[
3
]),
(
0
,
0
,
0
),
2
)
cv2
.
rectangle
(
vis
,
(
rect
[
0
],
rect
[
1
]),
(
rect
[
0
]
+
rect
[
2
],
rect
[
1
]
+
rect
[
3
]),
(
255
,
255
,
255
),
1
)
#Visualization
vis
=
vis
[:,:,::
-
1
]
#flip the colors dimension from BGR to RGB
plt
.
imshow
(
vis
)
plt
.
xticks
([]),
plt
.
yticks
([])
# to hide tick values on X and Y axis
plt
.
show
()
cv2
.
imshow
(
"Text detection result"
,
vis
)
cv2
.
waitKey
(
0
)
modules/text/src/erfilter.cpp
View file @
d6320797
...
...
@@ -4175,7 +4175,7 @@ void MSERsToERStats(InputArray image, vector<vector<Point> > &contours, vector<v
void
detectRegions
(
InputArray
image
,
const
Ptr
<
ERFilter
>&
er_filter1
,
const
Ptr
<
ERFilter
>&
er_filter2
,
CV_OUT
vector
<
vector
<
Point
>
>&
regions
)
{
// assert correct image type
CV_Assert
(
image
.
getMat
().
type
()
==
CV_8UC1
);
CV_Assert
(
image
.
type
()
==
CV_8UC1
);
// at least one ERFilter must be passed
CV_Assert
(
!
er_filter1
.
empty
()
);
...
...
@@ -4189,36 +4189,33 @@ void detectRegions(InputArray image, const Ptr<ERFilter>& er_filter1, const Ptr<
}
//Convert each ER to vector<Point> and push it to output regions
Mat
src
=
image
.
getMat
();
Mat
region_mask
=
Mat
::
zeros
(
src
.
rows
+
2
,
src
.
cols
+
2
,
CV_8UC1
);
const
Mat
src
=
image
.
getMat
();
for
(
size_t
i
=
1
;
i
<
ers
.
size
();
i
++
)
//start from 1 to deprecate root region
{
ERStat
*
stat
=
&
ers
[
i
];
//Fill the region and calculate 2nd stage features
Mat
region
=
region_mask
(
Rect
(
Point
(
stat
->
rect
.
x
,
stat
->
rect
.
y
),
Point
(
stat
->
rect
.
br
().
x
+
2
,
stat
->
rect
.
br
().
y
+
2
)));
region
=
Scalar
(
0
);
Mat
region_mask
(
Size
(
stat
->
rect
.
width
+
2
,
stat
->
rect
.
height
+
2
),
CV_8UC1
,
Scalar
(
0
));
Mat
region
=
region_mask
(
Rect
(
1
,
1
,
stat
->
rect
.
width
,
stat
->
rect
.
height
));
int
newMaskVal
=
255
;
int
flags
=
4
+
(
newMaskVal
<<
8
)
+
FLOODFILL_FIXED_RANGE
+
FLOODFILL_MASK_ONLY
;
Rect
rect
;
floodFill
(
src
(
Rect
(
Point
(
stat
->
rect
.
x
,
stat
->
rect
.
y
),
Point
(
stat
->
rect
.
br
().
x
,
stat
->
rect
.
br
().
y
))),
region
,
Point
(
stat
->
pixel
%
src
.
cols
-
stat
->
rect
.
x
,
stat
->
pixel
/
src
.
cols
-
stat
->
rect
.
y
),
Scalar
(
255
),
&
rect
,
Scalar
(
stat
->
level
),
Scalar
(
0
),
flags
);
rect
.
width
+=
2
;
rect
.
height
+=
2
;
region
=
region
(
rect
);
const
Point
seed_pt
(
stat
->
pixel
%
src
.
cols
,
stat
->
pixel
/
src
.
cols
);
uchar
seed_v
=
src
.
at
<
uchar
>
(
seed_pt
);
CV_Assert
((
int
)
seed_v
<=
stat
->
level
);
floodFill
(
src
(
stat
->
rect
),
region_mask
,
seed_pt
-
stat
->
rect
.
tl
(),
Scalar
(
255
),
NULL
,
Scalar
(
/*stat->level*/
255
),
Scalar
(
0
),
flags
);
vector
<
vector
<
Point
>
>
contours
;
vector
<
Vec4i
>
hierarchy
;
findContours
(
region
,
contours
,
hierarchy
,
RETR_TREE
,
CHAIN_APPROX_NONE
,
Point
(
0
,
0
)
);
for
(
size_t
j
=
0
;
j
<
contours
[
0
].
size
();
j
++
)
contours
[
0
][
j
]
+=
(
stat
->
rect
.
tl
()
-
Point
(
1
,
1
));
findContours
(
region
,
contours
,
hierarchy
,
RETR_TREE
,
CHAIN_APPROX_NONE
,
stat
->
rect
.
tl
()
);
regions
.
push_back
(
contours
[
0
]);
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment