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
af536b13
Commit
af536b13
authored
Sep 05, 2017
by
sghoshcvc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
seperate image pre-processing from ocr code
parent
e98f42ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
387 additions
and
367 deletions
+387
-367
image_preprocessor.cpp
modules/text/src/image_preprocessor.cpp
+387
-0
ocr_holistic.cpp
modules/text/src/ocr_holistic.cpp
+0
-367
No files found.
modules/text/src/image_preprocessor.cpp
0 → 100644
View file @
af536b13
#include "precomp.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/core.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <queue>
#include <algorithm>
#include <iosfwd>
#include <memory>
#include <string>
#include <utility>
#include <vector>
namespace
cv
{
namespace
text
{
//************************************************************************************
//****************** ImagePreprocessor *******************************************
//************************************************************************************
void
ImagePreprocessor
::
preprocess
(
InputArray
input
,
OutputArray
output
,
Size
sz
,
int
outputChannels
){
Mat
inpImg
=
input
.
getMat
();
Mat
outImg
;
this
->
preprocess_
(
inpImg
,
outImg
,
sz
,
outputChannels
);
outImg
.
copyTo
(
output
);
}
void
ImagePreprocessor
::
set_mean
(
Mat
mean
){
this
->
set_mean_
(
mean
);
}
class
ResizerPreprocessor
:
public
ImagePreprocessor
{
protected
:
void
preprocess_
(
const
Mat
&
input
,
Mat
&
output
,
Size
outputSize
,
int
outputChannels
){
//TODO put all the logic of channel and depth conversions in ImageProcessor class
CV_Assert
(
outputChannels
==
1
||
outputChannels
==
3
);
CV_Assert
(
input
.
channels
()
==
1
||
input
.
channels
()
==
3
);
if
(
input
.
channels
()
!=
outputChannels
)
{
Mat
tmpInput
;
if
(
outputChannels
==
1
){
cvtColor
(
input
,
tmpInput
,
COLOR_BGR2GRAY
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
cvtColor
(
input
,
tmpInput
,
COLOR_GRAY2BGR
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
else
{
if
(
input
.
channels
()
==
1
)
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
if
(
input
.
depth
()
==
CV_8U
){
input
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
if
(
outputSize
.
width
!=
0
&&
outputSize
.
height
!=
0
)
{
resize
(
output
,
output
,
outputSize
);
}
}
//void set_mean_(Mat m){}
public
:
ResizerPreprocessor
(){}
~
ResizerPreprocessor
(){}
};
class
StandarizerPreprocessor
:
public
ImagePreprocessor
{
protected
:
double
sigma_
;
//void set_mean_(Mat M){}
void
preprocess_
(
const
Mat
&
input
,
Mat
&
output
,
Size
outputSize
,
int
outputChannels
){
//TODO put all the logic of channel and depth conversions in ImageProcessor class
CV_Assert
(
outputChannels
==
1
||
outputChannels
==
3
);
CV_Assert
(
input
.
channels
()
==
1
||
input
.
channels
()
==
3
);
if
(
input
.
channels
()
!=
outputChannels
)
{
Mat
tmpInput
;
if
(
outputChannels
==
1
)
{
cvtColor
(
input
,
tmpInput
,
COLOR_BGR2GRAY
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
cvtColor
(
input
,
tmpInput
,
COLOR_GRAY2BGR
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
else
{
if
(
input
.
channels
()
==
1
)
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
if
(
outputSize
.
width
!=
0
&&
outputSize
.
height
!=
0
)
{
resize
(
output
,
output
,
outputSize
);
}
Scalar
mean
,
dev
;
meanStdDev
(
output
,
mean
,
dev
);
subtract
(
output
,
mean
[
0
],
output
);
divide
(
output
,(
dev
[
0
]
/
sigma_
),
output
);
}
public
:
StandarizerPreprocessor
(
double
sigma
)
:
sigma_
(
sigma
){}
~
StandarizerPreprocessor
(){}
};
class
customPreprocessor
:
public
ImagePreprocessor
{
protected
:
double
rawval_
;
Mat
mean_
;
String
channel_order_
;
void
set_mean_
(
Mat
imMean_
){
imMean_
.
copyTo
(
this
->
mean_
);
}
void
set_raw_scale
(
int
rawval
){
rawval_
=
rawval
;
}
void
set_channels
(
String
channel_order
){
channel_order_
=
channel_order
;
}
void
preprocess_
(
const
Mat
&
input
,
Mat
&
output
,
Size
outputSize
,
int
outputChannels
){
//TODO put all the logic of channel and depth conversions in ImageProcessor class
CV_Assert
(
outputChannels
==
1
||
outputChannels
==
3
);
CV_Assert
(
input
.
channels
()
==
1
||
input
.
channels
()
==
3
);
if
(
input
.
channels
()
!=
outputChannels
)
{
Mat
tmpInput
;
if
(
outputChannels
==
1
)
{
cvtColor
(
input
,
tmpInput
,
COLOR_BGR2GRAY
);
if
(
input
.
depth
()
==
CV_8U
)
{
if
(
rawval_
==
1
)
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
else
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
else
{
//Assuming values are at the desired [0,1] range
if
(
rawval_
==
1
)
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
else
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
rawval_
);
}
}
else
{
cvtColor
(
input
,
tmpInput
,
COLOR_GRAY2BGR
);
if
(
input
.
depth
()
==
CV_8U
)
{
if
(
rawval_
==
1
)
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
else
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
else
{
//Assuming values are at the desired [0,1] range
if
(
rawval_
==
1
)
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
else
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
rawval_
);
}
}
}
else
{
if
(
input
.
channels
()
==
1
)
{
if
(
input
.
depth
()
==
CV_8U
)
{
if
(
rawval_
==
1
)
input
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
else
input
.
convertTo
(
output
,
CV_32FC1
);
}
else
{
//Assuming values are at the desired [0,1] range
if
(
rawval_
==
1
)
input
.
convertTo
(
output
,
CV_32FC1
);
else
input
.
convertTo
(
output
,
CV_32FC1
,
rawval_
);
}
}
else
{
if
(
input
.
depth
()
==
CV_8U
)
{
if
(
rawval_
==
1
)
input
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
else
input
.
convertTo
(
output
,
CV_32FC3
);
}
else
{
//Assuming values are at the desired [0,1] range
if
(
rawval_
==
1
)
input
.
convertTo
(
output
,
CV_32FC3
);
else
input
.
convertTo
(
output
,
CV_32FC3
,
rawval_
);
}
}
}
if
(
outputSize
.
width
!=
0
&&
outputSize
.
height
!=
0
)
{
resize
(
output
,
output
,
outputSize
);
}
if
(
!
this
->
mean_
.
empty
()){
Scalar
mean_s
(
this
->
mean_
.
at
<
uchar
>
(
0
,
0
),
this
->
mean_
.
at
<
uchar
>
(
0
,
1
),
this
->
mean_
.
at
<
uchar
>
(
0
,
2
));
subtract
(
output
,
mean_s
,
output
);
}
else
{
Scalar
mean_s
;
mean_s
=
mean
(
output
);
subtract
(
output
,
mean_s
,
output
);
}
}
public
:
customPreprocessor
(
double
rawval
,
String
channel_order
)
:
rawval_
(
rawval
),
channel_order_
(
channel_order
){}
~
customPreprocessor
(){}
};
class
MeanSubtractorPreprocessor
:
public
ImagePreprocessor
{
protected
:
Mat
mean_
;
//void set_mean_(Mat m){}
void
preprocess_
(
const
Mat
&
input
,
Mat
&
output
,
Size
outputSize
,
int
outputChannels
){
//TODO put all the logic of channel and depth conversions in ImageProcessor class
CV_Assert
(
this
->
mean_
.
cols
==
outputSize
.
width
&&
this
->
mean_
.
rows
==
outputSize
.
height
);
CV_Assert
(
outputChannels
==
1
||
outputChannels
==
3
);
CV_Assert
(
input
.
channels
()
==
1
||
input
.
channels
()
==
3
);
if
(
input
.
channels
()
!=
outputChannels
)
{
Mat
tmpInput
;
if
(
outputChannels
==
1
)
{
cvtColor
(
input
,
tmpInput
,
COLOR_BGR2GRAY
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
cvtColor
(
input
,
tmpInput
,
COLOR_GRAY2BGR
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
else
{
if
(
input
.
channels
()
==
1
)
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
if
(
outputSize
.
width
!=
0
&&
outputSize
.
height
!=
0
)
{
resize
(
output
,
output
,
outputSize
);
}
subtract
(
output
,
this
->
mean_
,
output
);
}
public
:
MeanSubtractorPreprocessor
(
Mat
mean
)
{
mean
.
copyTo
(
this
->
mean_
);
}
~
MeanSubtractorPreprocessor
(){}
};
Ptr
<
ImagePreprocessor
>
ImagePreprocessor
::
createResizer
()
{
return
Ptr
<
ImagePreprocessor
>
(
new
ResizerPreprocessor
);
}
Ptr
<
ImagePreprocessor
>
ImagePreprocessor
::
createImageStandarizer
(
double
sigma
)
{
return
Ptr
<
ImagePreprocessor
>
(
new
StandarizerPreprocessor
(
sigma
));
}
Ptr
<
ImagePreprocessor
>
ImagePreprocessor
::
createImageCustomPreprocessor
(
double
rawval
,
String
channel_order
)
{
return
Ptr
<
ImagePreprocessor
>
(
new
customPreprocessor
(
rawval
,
channel_order
));
}
Ptr
<
ImagePreprocessor
>
ImagePreprocessor
::
createImageMeanSubtractor
(
InputArray
meanImg
)
{
Mat
tmp
=
meanImg
.
getMat
();
return
Ptr
<
ImagePreprocessor
>
(
new
MeanSubtractorPreprocessor
(
tmp
));
}
}
}
modules/text/src/ocr_holistic.cpp
View file @
af536b13
...
...
@@ -36,374 +36,7 @@ inline bool fileExists (String filename) {
return
f
.
good
();
}
//************************************************************************************
//****************** ImagePreprocessor *******************************************
//************************************************************************************
void
ImagePreprocessor
::
preprocess
(
InputArray
input
,
OutputArray
output
,
Size
sz
,
int
outputChannels
){
Mat
inpImg
=
input
.
getMat
();
Mat
outImg
;
this
->
preprocess_
(
inpImg
,
outImg
,
sz
,
outputChannels
);
outImg
.
copyTo
(
output
);
}
void
ImagePreprocessor
::
set_mean
(
Mat
mean
){
this
->
set_mean_
(
mean
);
}
class
ResizerPreprocessor
:
public
ImagePreprocessor
{
protected
:
void
preprocess_
(
const
Mat
&
input
,
Mat
&
output
,
Size
outputSize
,
int
outputChannels
){
//TODO put all the logic of channel and depth conversions in ImageProcessor class
CV_Assert
(
outputChannels
==
1
||
outputChannels
==
3
);
CV_Assert
(
input
.
channels
()
==
1
||
input
.
channels
()
==
3
);
if
(
input
.
channels
()
!=
outputChannels
)
{
Mat
tmpInput
;
if
(
outputChannels
==
1
){
cvtColor
(
input
,
tmpInput
,
COLOR_BGR2GRAY
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
cvtColor
(
input
,
tmpInput
,
COLOR_GRAY2BGR
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
else
{
if
(
input
.
channels
()
==
1
)
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
if
(
input
.
depth
()
==
CV_8U
){
input
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
if
(
outputSize
.
width
!=
0
&&
outputSize
.
height
!=
0
)
{
resize
(
output
,
output
,
outputSize
);
}
}
//void set_mean_(Mat m){}
public
:
ResizerPreprocessor
(){}
~
ResizerPreprocessor
(){}
};
class
StandarizerPreprocessor
:
public
ImagePreprocessor
{
protected
:
double
sigma_
;
//void set_mean_(Mat M){}
void
preprocess_
(
const
Mat
&
input
,
Mat
&
output
,
Size
outputSize
,
int
outputChannels
){
//TODO put all the logic of channel and depth conversions in ImageProcessor class
CV_Assert
(
outputChannels
==
1
||
outputChannels
==
3
);
CV_Assert
(
input
.
channels
()
==
1
||
input
.
channels
()
==
3
);
if
(
input
.
channels
()
!=
outputChannels
)
{
Mat
tmpInput
;
if
(
outputChannels
==
1
)
{
cvtColor
(
input
,
tmpInput
,
COLOR_BGR2GRAY
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
cvtColor
(
input
,
tmpInput
,
COLOR_GRAY2BGR
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
else
{
if
(
input
.
channels
()
==
1
)
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
if
(
outputSize
.
width
!=
0
&&
outputSize
.
height
!=
0
)
{
resize
(
output
,
output
,
outputSize
);
}
Scalar
mean
,
dev
;
meanStdDev
(
output
,
mean
,
dev
);
subtract
(
output
,
mean
[
0
],
output
);
divide
(
output
,(
dev
[
0
]
/
sigma_
),
output
);
}
public
:
StandarizerPreprocessor
(
double
sigma
)
:
sigma_
(
sigma
){}
~
StandarizerPreprocessor
(){}
};
class
customPreprocessor
:
public
ImagePreprocessor
{
protected
:
double
rawval_
;
Mat
mean_
;
String
channel_order_
;
void
set_mean_
(
Mat
imMean_
){
imMean_
.
copyTo
(
this
->
mean_
);
}
void
set_raw_scale
(
int
rawval
){
rawval_
=
rawval
;
}
void
set_channels
(
String
channel_order
){
channel_order_
=
channel_order
;
}
void
preprocess_
(
const
Mat
&
input
,
Mat
&
output
,
Size
outputSize
,
int
outputChannels
){
//TODO put all the logic of channel and depth conversions in ImageProcessor class
CV_Assert
(
outputChannels
==
1
||
outputChannels
==
3
);
CV_Assert
(
input
.
channels
()
==
1
||
input
.
channels
()
==
3
);
if
(
input
.
channels
()
!=
outputChannels
)
{
Mat
tmpInput
;
if
(
outputChannels
==
1
)
{
cvtColor
(
input
,
tmpInput
,
COLOR_BGR2GRAY
);
if
(
input
.
depth
()
==
CV_8U
)
{
if
(
rawval_
==
1
)
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
else
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
else
{
//Assuming values are at the desired [0,1] range
if
(
rawval_
==
1
)
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
else
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
rawval_
);
}
}
else
{
cvtColor
(
input
,
tmpInput
,
COLOR_GRAY2BGR
);
if
(
input
.
depth
()
==
CV_8U
)
{
if
(
rawval_
==
1
)
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
else
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
else
{
//Assuming values are at the desired [0,1] range
if
(
rawval_
==
1
)
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
else
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
rawval_
);
}
}
}
else
{
if
(
input
.
channels
()
==
1
)
{
if
(
input
.
depth
()
==
CV_8U
)
{
if
(
rawval_
==
1
)
input
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
else
input
.
convertTo
(
output
,
CV_32FC1
);
}
else
{
//Assuming values are at the desired [0,1] range
if
(
rawval_
==
1
)
input
.
convertTo
(
output
,
CV_32FC1
);
else
input
.
convertTo
(
output
,
CV_32FC1
,
rawval_
);
}
}
else
{
if
(
input
.
depth
()
==
CV_8U
)
{
if
(
rawval_
==
1
)
input
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
else
input
.
convertTo
(
output
,
CV_32FC3
);
}
else
{
//Assuming values are at the desired [0,1] range
if
(
rawval_
==
1
)
input
.
convertTo
(
output
,
CV_32FC3
);
else
input
.
convertTo
(
output
,
CV_32FC3
,
rawval_
);
}
}
}
if
(
outputSize
.
width
!=
0
&&
outputSize
.
height
!=
0
)
{
resize
(
output
,
output
,
outputSize
);
}
if
(
!
this
->
mean_
.
empty
()){
Scalar
mean_s
(
this
->
mean_
.
at
<
uchar
>
(
0
,
0
),
this
->
mean_
.
at
<
uchar
>
(
0
,
1
),
this
->
mean_
.
at
<
uchar
>
(
0
,
2
));
subtract
(
output
,
mean_s
,
output
);
}
else
{
Scalar
mean_s
;
mean_s
=
mean
(
output
);
subtract
(
output
,
mean_s
,
output
);
}
}
public
:
customPreprocessor
(
double
rawval
,
String
channel_order
)
:
rawval_
(
rawval
),
channel_order_
(
channel_order
){}
~
customPreprocessor
(){}
};
class
MeanSubtractorPreprocessor
:
public
ImagePreprocessor
{
protected
:
Mat
mean_
;
//void set_mean_(Mat m){}
void
preprocess_
(
const
Mat
&
input
,
Mat
&
output
,
Size
outputSize
,
int
outputChannels
){
//TODO put all the logic of channel and depth conversions in ImageProcessor class
CV_Assert
(
this
->
mean_
.
cols
==
outputSize
.
width
&&
this
->
mean_
.
rows
==
outputSize
.
height
);
CV_Assert
(
outputChannels
==
1
||
outputChannels
==
3
);
CV_Assert
(
input
.
channels
()
==
1
||
input
.
channels
()
==
3
);
if
(
input
.
channels
()
!=
outputChannels
)
{
Mat
tmpInput
;
if
(
outputChannels
==
1
)
{
cvtColor
(
input
,
tmpInput
,
COLOR_BGR2GRAY
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
cvtColor
(
input
,
tmpInput
,
COLOR_GRAY2BGR
);
if
(
input
.
depth
()
==
CV_8U
)
{
tmpInput
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
tmpInput
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
else
{
if
(
input
.
channels
()
==
1
)
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC1
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC1
);
}
}
else
{
if
(
input
.
depth
()
==
CV_8U
)
{
input
.
convertTo
(
output
,
CV_32FC3
,
1
/
255.0
);
}
else
{
//Assuming values are at the desired [0,1] range
input
.
convertTo
(
output
,
CV_32FC3
);
}
}
}
if
(
outputSize
.
width
!=
0
&&
outputSize
.
height
!=
0
)
{
resize
(
output
,
output
,
outputSize
);
}
subtract
(
output
,
this
->
mean_
,
output
);
}
public
:
MeanSubtractorPreprocessor
(
Mat
mean
)
{
mean
.
copyTo
(
this
->
mean_
);
}
~
MeanSubtractorPreprocessor
(){}
};
Ptr
<
ImagePreprocessor
>
ImagePreprocessor
::
createResizer
()
{
return
Ptr
<
ImagePreprocessor
>
(
new
ResizerPreprocessor
);
}
Ptr
<
ImagePreprocessor
>
ImagePreprocessor
::
createImageStandarizer
(
double
sigma
)
{
return
Ptr
<
ImagePreprocessor
>
(
new
StandarizerPreprocessor
(
sigma
));
}
Ptr
<
ImagePreprocessor
>
ImagePreprocessor
::
createImageCustomPreprocessor
(
double
rawval
,
String
channel_order
)
{
return
Ptr
<
ImagePreprocessor
>
(
new
customPreprocessor
(
rawval
,
channel_order
));
}
Ptr
<
ImagePreprocessor
>
ImagePreprocessor
::
createImageMeanSubtractor
(
InputArray
meanImg
)
{
Mat
tmp
=
meanImg
.
getMat
();
return
Ptr
<
ImagePreprocessor
>
(
new
MeanSubtractorPreprocessor
(
tmp
));
}
//************************************************************************************
//****************** TextImageClassifier *****************************************
...
...
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