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
6bfb4022
Commit
6bfb4022
authored
Nov 10, 2015
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #416 from CoderBotOrg:master
parents
bcbbb63b
fe056816
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
167 additions
and
11 deletions
+167
-11
ocr.hpp
modules/text/include/opencv2/text/ocr.hpp
+0
-0
ocr_beamsearch_decoder.cpp
modules/text/src/ocr_beamsearch_decoder.cpp
+51
-3
ocr_hmm_decoder.cpp
modules/text/src/ocr_hmm_decoder.cpp
+66
-6
ocr_tesseract.cpp
modules/text/src/ocr_tesseract.cpp
+50
-2
No files found.
modules/text/include/opencv2/text/ocr.hpp
View file @
6bfb4022
This diff is collapsed.
Click to expand it.
modules/text/src/ocr_beamsearch_decoder.cpp
View file @
6bfb4022
...
...
@@ -88,6 +88,45 @@ void OCRBeamSearchDecoder::run(Mat& image, Mat& mask, string& output_text, vecto
component_confidences
->
clear
();
}
CV_WRAP
String
OCRBeamSearchDecoder
::
run
(
InputArray
image
,
int
min_confidence
,
int
component_level
)
{
std
::
string
output1
;
std
::
string
output2
;
vector
<
string
>
component_texts
;
vector
<
float
>
component_confidences
;
Mat
image_m
=
image
.
getMat
();
run
(
image_m
,
output1
,
NULL
,
&
component_texts
,
&
component_confidences
,
component_level
);
for
(
unsigned
int
i
=
0
;
i
<
component_texts
.
size
();
i
++
)
{
//cout << "confidence: " << component_confidences[i] << " text:" << component_texts[i] << endl;
if
(
component_confidences
[
i
]
>
min_confidence
)
{
output2
+=
component_texts
[
i
];
}
}
return
String
(
output2
);
}
CV_WRAP
String
OCRBeamSearchDecoder
::
run
(
InputArray
image
,
InputArray
mask
,
int
min_confidence
,
int
component_level
)
{
std
::
string
output1
;
std
::
string
output2
;
vector
<
string
>
component_texts
;
vector
<
float
>
component_confidences
;
Mat
image_m
=
image
.
getMat
();
Mat
mask_m
=
mask
.
getMat
();
run
(
image_m
,
mask_m
,
output1
,
NULL
,
&
component_texts
,
&
component_confidences
,
component_level
);
for
(
unsigned
int
i
=
0
;
i
<
component_texts
.
size
();
i
++
)
{
//cout << "confidence: " << component_confidences[i] << " text:" << component_texts[i] << endl;
if
(
component_confidences
[
i
]
>
min_confidence
)
{
output2
+=
component_texts
[
i
];
}
}
return
String
(
output2
);
}
void
OCRBeamSearchDecoder
::
ClassifierCallback
::
eval
(
InputArray
image
,
vector
<
vector
<
double
>
>&
recognition_probabilities
,
vector
<
int
>&
oversegmentation
)
{
...
...
@@ -460,6 +499,16 @@ Ptr<OCRBeamSearchDecoder> OCRBeamSearchDecoder::create( Ptr<OCRBeamSearchDecoder
return
makePtr
<
OCRBeamSearchDecoderImpl
>
(
_classifier
,
_vocabulary
,
transition_p
,
emission_p
,
_mode
,
_beam_size
);
}
CV_EXPORTS_W
Ptr
<
OCRBeamSearchDecoder
>
OCRBeamSearchDecoder
::
create
(
Ptr
<
OCRBeamSearchDecoder
::
ClassifierCallback
>
_classifier
,
const
String
&
_vocabulary
,
InputArray
transition_p
,
InputArray
emission_p
,
int
_mode
,
int
_beam_size
)
{
return
makePtr
<
OCRBeamSearchDecoderImpl
>
(
_classifier
,
_vocabulary
,
transition_p
,
emission_p
,
(
decoder_mode
)
_mode
,
_beam_size
);
}
class
CV_EXPORTS
OCRBeamSearchClassifierCNN
:
public
OCRBeamSearchDecoder
::
ClassifierCallback
{
...
...
@@ -727,11 +776,10 @@ double OCRBeamSearchClassifierCNN::eval_feature(Mat& feature, double* prob_estim
return
dec_max_idx
;
}
Ptr
<
OCRBeamSearchDecoder
::
ClassifierCallback
>
loadOCRBeamSearchClassifierCNN
(
const
std
::
string
&
filename
)
Ptr
<
OCRBeamSearchDecoder
::
ClassifierCallback
>
loadOCRBeamSearchClassifierCNN
(
const
String
&
filename
)
{
return
makePtr
<
OCRBeamSearchClassifierCNN
>
(
filename
);
return
makePtr
<
OCRBeamSearchClassifierCNN
>
(
std
::
string
(
filename
)
);
}
}
...
...
modules/text/src/ocr_hmm_decoder.cpp
View file @
6bfb4022
...
...
@@ -90,6 +90,46 @@ void OCRHMMDecoder::run(Mat& image, Mat& mask, string& output_text, vector<Rect>
component_confidences
->
clear
();
}
CV_WRAP
String
OCRHMMDecoder
::
run
(
InputArray
image
,
int
min_confidence
,
int
component_level
)
{
std
::
string
output1
;
std
::
string
output2
;
vector
<
string
>
component_texts
;
vector
<
float
>
component_confidences
;
Mat
image_m
=
image
.
getMat
();
run
(
image_m
,
output1
,
NULL
,
&
component_texts
,
&
component_confidences
,
component_level
);
for
(
unsigned
int
i
=
0
;
i
<
component_texts
.
size
();
i
++
)
{
//cout << "confidence: " << component_confidences[i] << " text:" << component_texts[i] << endl;
if
(
component_confidences
[
i
]
>
min_confidence
)
{
output2
+=
component_texts
[
i
];
}
}
return
String
(
output2
);
}
CV_WRAP
cv
::
String
OCRHMMDecoder
::
run
(
InputArray
image
,
InputArray
mask
,
int
min_confidence
,
int
component_level
)
{
std
::
string
output1
;
std
::
string
output2
;
vector
<
string
>
component_texts
;
vector
<
float
>
component_confidences
;
Mat
image_m
=
image
.
getMat
();
Mat
mask_m
=
mask
.
getMat
();
run
(
image_m
,
mask_m
,
output1
,
NULL
,
&
component_texts
,
&
component_confidences
,
component_level
);
for
(
unsigned
int
i
=
0
;
i
<
component_texts
.
size
();
i
++
)
{
cout
<<
"confidence: "
<<
component_confidences
[
i
]
<<
" text:"
<<
component_texts
[
i
]
<<
endl
;
if
(
component_confidences
[
i
]
>
min_confidence
)
{
output2
+=
component_texts
[
i
];
}
}
return
String
(
output2
);
}
void
OCRHMMDecoder
::
ClassifierCallback
::
eval
(
InputArray
image
,
vector
<
int
>&
out_class
,
vector
<
double
>&
out_confidence
)
{
CV_Assert
((
image
.
getMat
().
type
()
==
CV_8UC3
)
||
(
image
.
getMat
().
type
()
==
CV_8UC1
));
...
...
@@ -635,6 +675,16 @@ Ptr<OCRHMMDecoder> OCRHMMDecoder::create( Ptr<OCRHMMDecoder::ClassifierCallback>
}
Ptr
<
OCRHMMDecoder
>
OCRHMMDecoder
::
create
(
Ptr
<
OCRHMMDecoder
::
ClassifierCallback
>
_classifier
,
const
String
&
_vocabulary
,
InputArray
transition_p
,
InputArray
emission_p
,
int
_mode
)
{
return
makePtr
<
OCRHMMDecoderImpl
>
(
_classifier
,
_vocabulary
,
transition_p
,
emission_p
,
(
decoder_mode
)
_mode
);
}
class
CV_EXPORTS
OCRHMMClassifierKNN
:
public
OCRHMMDecoder
::
ClassifierCallback
{
public
:
...
...
@@ -867,14 +917,12 @@ void OCRHMMClassifierKNN::eval( InputArray _mask, vector<int>& out_class, vector
}
Ptr
<
OCRHMMDecoder
::
ClassifierCallback
>
loadOCRHMMClassifierNM
(
const
std
::
s
tring
&
filename
)
Ptr
<
OCRHMMDecoder
::
ClassifierCallback
>
loadOCRHMMClassifierNM
(
const
S
tring
&
filename
)
{
return
makePtr
<
OCRHMMClassifierKNN
>
(
filename
);
return
makePtr
<
OCRHMMClassifierKNN
>
(
std
::
string
(
filename
)
);
}
class
CV_EXPORTS
OCRHMMClassifierCNN
:
public
OCRHMMDecoder
::
ClassifierCallback
{
public
:
...
...
@@ -1139,10 +1187,10 @@ double OCRHMMClassifierCNN::eval_feature(Mat& feature, double* prob_estimates)
}
Ptr
<
OCRHMMDecoder
::
ClassifierCallback
>
loadOCRHMMClassifierCNN
(
const
std
::
s
tring
&
filename
)
Ptr
<
OCRHMMDecoder
::
ClassifierCallback
>
loadOCRHMMClassifierCNN
(
const
S
tring
&
filename
)
{
return
makePtr
<
OCRHMMClassifierCNN
>
(
filename
);
return
makePtr
<
OCRHMMClassifierCNN
>
(
std
::
string
(
filename
)
);
}
/** @brief Utility function to create a tailored language model transitions table from a given list of words (lexicon).
...
...
@@ -1201,5 +1249,17 @@ void createOCRHMMTransitionsTable(string& vocabulary, vector<string>& lexicon, O
return
;
}
Mat
createOCRHMMTransitionsTable
(
const
String
&
vocabulary
,
vector
<
cv
::
String
>&
lexicon
)
{
std
::
string
voc
(
vocabulary
);
vector
<
string
>
lex
;
for
(
vector
<
cv
::
String
>::
iterator
l
=
lexicon
.
begin
();
l
!=
lexicon
.
end
();
l
++
)
lex
.
push_back
(
std
::
string
(
*
l
));
Mat
_transitions
;
createOCRHMMTransitionsTable
(
voc
,
lex
,
_transitions
);
return
_transitions
;
}
}
}
modules/text/src/ocr_tesseract.cpp
View file @
6bfb4022
...
...
@@ -86,6 +86,47 @@ void OCRTesseract::run(Mat& image, Mat& mask, string& output_text, vector<Rect>*
component_confidences
->
clear
();
}
CV_WRAP
String
OCRTesseract
::
run
(
InputArray
image
,
int
min_confidence
,
int
component_level
)
{
std
::
string
output1
;
std
::
string
output2
;
vector
<
string
>
component_texts
;
vector
<
float
>
component_confidences
;
Mat
image_m
=
image
.
getMat
();
run
(
image_m
,
output1
,
NULL
,
&
component_texts
,
&
component_confidences
,
component_level
);
for
(
unsigned
int
i
=
0
;
i
<
component_texts
.
size
();
i
++
)
{
// cout << "confidence: " << component_confidences[i] << " text:" << component_texts[i] << endl;
if
(
component_confidences
[
i
]
>
min_confidence
)
{
output2
+=
component_texts
[
i
];
}
}
return
String
(
output2
);
}
CV_WRAP
String
OCRTesseract
::
run
(
InputArray
image
,
InputArray
mask
,
int
min_confidence
,
int
component_level
)
{
std
::
string
output1
;
std
::
string
output2
;
vector
<
string
>
component_texts
;
vector
<
float
>
component_confidences
;
Mat
image_m
=
image
.
getMat
();
Mat
mask_m
=
mask
.
getMat
();
run
(
image_m
,
mask_m
,
output1
,
NULL
,
&
component_texts
,
&
component_confidences
,
component_level
);
for
(
unsigned
int
i
=
0
;
i
<
component_texts
.
size
();
i
++
)
{
cout
<<
"confidence: "
<<
component_confidences
[
i
]
<<
" text:"
<<
component_texts
[
i
]
<<
endl
;
if
(
component_confidences
[
i
]
>
min_confidence
)
{
output2
+=
component_texts
[
i
];
}
}
return
String
(
output2
);
}
class
OCRTesseractImpl
:
public
OCRTesseract
{
private
:
...
...
@@ -215,13 +256,20 @@ public:
run
(
mask
,
output
,
component_rects
,
component_texts
,
component_confidences
,
component_level
);
}
void
setWhiteList
(
const
String
&
char_whitelist
)
{
#ifdef HAVE_TESSERACT
tess
.
SetVariable
(
"tessedit_char_whitelist"
,
char_whitelist
.
c_str
());
#else
(
void
)
char_whitelist
;
#endif
}
};
Ptr
<
OCRTesseract
>
OCRTesseract
::
create
(
const
char
*
datapath
,
const
char
*
language
,
const
char
*
char_whitelist
,
int
oem
,
int
psmode
)
{
return
makePtr
<
OCRTesseractImpl
>
(
datapath
,
language
,
char_whitelist
,
oem
,
psmode
);
return
makePtr
<
OCRTesseractImpl
>
(
datapath
,
language
,
char_whitelist
,
oem
,
psmode
);
}
...
...
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