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
1bc908bd
Commit
1bc908bd
authored
Jul 19, 2017
by
sghoshcvc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added python sample script
parent
be395e59
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
0 deletions
+60
-0
deeptextdetection.py
modules/text/samples/deeptextdetection.py
+60
-0
No files found.
modules/text/samples/deeptextdetection.py
0 → 100644
View file @
1bc908bd
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 19 17:54:00 2017
@author: sgnosh
"""
#!/usr/bin/python
import
sys
import
os
import
cv2
import
numpy
as
np
print
(
'
\n
Deeptextdetection.py'
)
print
(
' A demo script of text box alogorithm of the paper:'
)
print
(
' * Minghui Liao et al.: TextBoxes: A Fast Text Detector with a Single Deep Neural Network https://arxiv.org/abs/1611.06779
\n
'
)
if
(
len
(
sys
.
argv
)
<
2
):
print
(
' (ERROR) You must call this script with an argument (path_to_image_to_be_processed)
\n
'
)
quit
()
#if not cv2.text.cnn_config.caffe_backend.getCaffeAvailable():
# print"The text module was compiled without Caffe which is the only available DeepCNN backend.\nAborting!\n"
#
# quit()
# check model and architecture file existance
if
not
os
.
path
.
isfile
(
'textbox.caffemodel'
)
or
not
os
.
path
.
isfile
(
'textbox_deploy.prototxt'
):
print
" Model files not found in current directory. Aborting"
print
" Model files should be downloaded from https://github.com/sghoshcvc/TextBox-Models"
quit
()
cv2
.
text
.
cnn_config
.
caffe_backend
.
setCaffeGpuMode
(
True
);
pathname
=
os
.
path
.
dirname
(
sys
.
argv
[
0
])
img
=
cv2
.
imread
(
str
(
sys
.
argv
[
1
]))
textSpotter
=
cv2
.
text
.
textDetector_create
(
"textbox_deploy.prototxt"
,
"textbox.caffemodel"
)
rects
,
outProbs
=
textSpotter
.
textDetectInImage
(
img
);
# for visualization
vis
=
img
.
copy
()
# Threshold to select rectangles : All rectangles for which outProbs is more than this threshold will be shown
thres
=
0.6
#Visualization
for
r
in
range
(
0
,
np
.
shape
(
rects
)[
0
]):
if
outProbs
[
r
]
>
thres
:
rect
=
rects
[
r
]
cv2
.
rectangle
(
vis
,
(
rect
[
0
],
rect
[
1
]),
(
rect
[
0
]
+
rect
[
2
],
rect
[
1
]
+
rect
[
3
]),
(
255
,
0
,
0
),
2
)
# cv2.rectangle(vis, (rect[0],rect[1]), (rect[0]+rect[2],rect[1]+rect[3]), (255, 255, 255), 1)
#Visualization
cv2
.
imshow
(
"Text detection result"
,
vis
)
cv2
.
waitKey
(
0
)
\ No newline at end of file
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