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
6f322a89
Commit
6f322a89
authored
Nov 20, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bioinspired(ocl): refactor OpenCL conditions
parent
a30fb44d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
60 deletions
+51
-60
retina_kernel.cl
modules/bioinspired/src/opencl/retina_kernel.cl
+1
-1
retina.cpp
modules/bioinspired/src/retina.cpp
+37
-35
retina_ocl.cpp
modules/bioinspired/src/retina_ocl.cpp
+10
-17
retina_ocl.hpp
modules/bioinspired/src/retina_ocl.hpp
+2
-2
test_retina_ocl.cpp
modules/bioinspired/test/test_retina_ocl.cpp
+1
-5
No files found.
modules/bioinspired/src/opencl/retina_kernel.cl
View file @
6f322a89
...
...
@@ -25,7 +25,7 @@
//
//
*
Redistribution
's
in
binary
form
must
reproduce
the
above
copyright
notice,
//
this
list
of
conditions
and
the
following
disclaimer
in
the
documentation
//
and/or
other
oclM
aterials
provided
with
the
distribution.
//
and/or
other
m
aterials
provided
with
the
distribution.
//
//
*
The
name
of
the
copyright
holders
may
not
be
used
to
endorse
or
promote
products
//
derived
from
this
software
without
specific
prior
written
permission.
...
...
modules/bioinspired/src/retina.cpp
View file @
6f322a89
...
...
@@ -269,7 +269,7 @@ private:
std
::
valarray
<
float
>
_inputBuffer
;
//!< buffer used to convert input cv::Mat to internal retina buffers format (valarrays)
// pointer to retina model
RetinaFilter
*
_retinaFilter
;
//!< the pointer to the retina module, allocated with instance construction
cv
::
Ptr
<
RetinaFilter
>
_retinaFilter
;
//!< the pointer to the retina module, allocated with instance construction
//! private method called by constructors, gathers their parameters and use them in a unified way
void
_init
(
const
Size
inputSize
,
const
bool
colorMode
,
int
colorSamplingMethod
=
RETINA_COLOR_BAYER
,
const
bool
useRetinaLogSampling
=
false
,
const
float
reductionFactor
=
1.0
f
,
const
float
samplingStrenght
=
10.0
f
);
...
...
@@ -295,7 +295,7 @@ private:
bool
_wasOCLRunCalled
;
#ifdef HAVE_OPENCL
ocl
::
RetinaOCLImpl
*
_ocl_retina
;
cv
::
Ptr
<
ocl
::
RetinaOCLImpl
>
_ocl_retina
;
bool
ocl_run
(
InputArray
inputImage
);
bool
ocl_getParvo
(
OutputArray
retinaOutput_parvo
);
...
...
@@ -320,36 +320,26 @@ Ptr<Retina> Retina::create(Size inputSize, const bool colorMode, int colorSampli
// RetinaImpl code
RetinaImpl
::
RetinaImpl
(
const
cv
::
Size
inputSz
)
{
_retinaFilter
=
0
;
_init
(
inputSz
,
true
,
RETINA_COLOR_BAYER
,
false
);
#ifdef HAVE_OPENCL
_ocl_retina
=
0
;
if
(
inputSz
.
width
%
4
==
0
)
_ocl_retina
=
new
ocl
::
RetinaOCLImpl
(
inputSz
);
if
(
inputSz
.
width
%
4
==
0
&&
cv
::
ocl
::
useOpenCL
())
_ocl_retina
.
reset
(
new
ocl
::
RetinaOCLImpl
(
inputSz
));
#endif
}
RetinaImpl
::
RetinaImpl
(
const
cv
::
Size
inputSz
,
const
bool
colorMode
,
int
colorSamplingMethod
,
const
bool
useRetinaLogSampling
,
const
float
reductionFactor
,
const
float
samplingStrenght
)
{
_retinaFilter
=
0
;
_init
(
inputSz
,
colorMode
,
colorSamplingMethod
,
useRetinaLogSampling
,
reductionFactor
,
samplingStrenght
);
#ifdef HAVE_OPENCL
_ocl_retina
=
0
;
if
(
inputSz
.
width
%
4
==
0
&&
!
useRetinaLogSampling
)
_ocl_retina
=
new
ocl
::
RetinaOCLImpl
(
inputSz
,
colorMode
,
colorSamplingMethod
,
useRetinaLogSampling
,
reductionFactor
,
samplingStrenght
);
if
(
inputSz
.
width
%
4
==
0
&&
!
useRetinaLogSampling
&&
cv
::
ocl
::
useOpenCL
())
_ocl_retina
.
reset
(
new
ocl
::
RetinaOCLImpl
(
inputSz
,
colorMode
,
colorSamplingMethod
,
useRetinaLogSampling
,
reductionFactor
,
samplingStrenght
));
#endif
}
RetinaImpl
::~
RetinaImpl
()
{
if
(
_retinaFilter
)
delete
_retinaFilter
;
#ifdef HAVE_OPENCL
if
(
_ocl_retina
)
delete
_ocl_retina
;
#endif
// nothing
}
/**
...
...
@@ -572,14 +562,14 @@ bool RetinaImpl::ocl_run(InputArray inputMatToConvert)
void
RetinaImpl
::
run
(
InputArray
inputMatToConvert
)
{
CV_OCL_RUN
((
_ocl_retina
!=
0
),
ocl_run
(
inputMatToConvert
));
CV_OCL_RUN
((
_ocl_retina
!=
0
&&
inputMatToConvert
.
isUMat
()
),
ocl_run
(
inputMatToConvert
));
_wasOCLRunCalled
=
false
;
// first convert input image to the compatible format : std::valarray<float>
const
bool
colorMode
=
_convertCvMat2ValarrayBuffer
(
inputMatToConvert
.
getMat
(),
_inputBuffer
);
// process the retina
if
(
!
_retinaFilter
->
runFilter
(
_inputBuffer
,
colorMode
,
false
,
_retinaParameters
.
OPLandIplParvo
.
colorMode
&&
colorMode
,
false
))
throw
cv
::
Exception
(
-
1
,
"RetinaImpl cannot be applied, wrong input buffer size"
,
"RetinaImpl::run"
,
"RetinaImpl.h"
,
0
);
CV_Error
(
Error
::
StsBadArg
,
"RetinaImpl cannot be applied, wrong input buffer size"
);
}
void
RetinaImpl
::
applyFastToneMapping
(
InputArray
inputImage
,
OutputArray
outputToneMappedImage
)
...
...
@@ -614,8 +604,11 @@ bool RetinaImpl::ocl_getParvo(OutputArray retinaOutput_parvo)
void
RetinaImpl
::
getParvo
(
OutputArray
retinaOutput_parvo
)
{
CV_OCL_RUN
((
_ocl_retina
!=
0
)
&&
retinaOutput_parvo
.
isUMat
(),
ocl_getParvo
(
retinaOutput_parvo
));
CV_Assert
(
!
_wasOCLRunCalled
);
if
(
_wasOCLRunCalled
)
{
CV_OCL_RUN
(
true
,
ocl_getParvo
(
retinaOutput_parvo
));
CV_Error
(
Error
::
StsInternal
,
""
);
}
if
(
_retinaFilter
->
getColorMode
())
{
...
...
@@ -640,8 +633,11 @@ bool RetinaImpl::ocl_getMagno(OutputArray retinaOutput_magno)
void
RetinaImpl
::
getMagno
(
OutputArray
retinaOutput_magno
)
{
CV_OCL_RUN
((
_ocl_retina
!=
0
)
&&
retinaOutput_magno
.
isUMat
(),
ocl_getMagno
(
retinaOutput_magno
));
CV_Assert
(
!
_wasOCLRunCalled
);
if
(
_wasOCLRunCalled
)
{
CV_OCL_RUN
(
true
,
ocl_getMagno
(
retinaOutput_magno
));
CV_Error
(
Error
::
StsInternal
,
""
);
}
// reallocate output buffer (if necessary)
_convertValarrayBuffer2cvMat
(
_retinaFilter
->
getMovingContours
(),
_retinaFilter
->
getOutputNBrows
(),
_retinaFilter
->
getOutputNBcolumns
(),
false
,
retinaOutput_magno
);
...
...
@@ -658,10 +654,14 @@ bool RetinaImpl::ocl_getMagnoRAW(OutputArray magnoOutputBufferCopy)
#endif
// original API level data accessors : copy buffers if size matches, reallocate if required
void
RetinaImpl
::
getMagnoRAW
(
OutputArray
magnoOutputBufferCopy
){
void
RetinaImpl
::
getMagnoRAW
(
OutputArray
magnoOutputBufferCopy
)
{
if
(
_wasOCLRunCalled
)
{
CV_OCL_RUN
(
true
,
ocl_getMagnoRAW
(
magnoOutputBufferCopy
));
CV_Error
(
Error
::
StsInternal
,
""
);
}
CV_OCL_RUN
((
_ocl_retina
!=
0
)
&&
magnoOutputBufferCopy
.
isUMat
(),
ocl_getMagnoRAW
(
magnoOutputBufferCopy
));
CV_Assert
(
!
_wasOCLRunCalled
);
// get magno channel header
const
cv
::
Mat
magnoChannel
=
cv
::
Mat
(
getMagnoRAW
());
// copy data
...
...
@@ -677,10 +677,14 @@ bool RetinaImpl::ocl_getParvoRAW(OutputArray parvoOutputBufferCopy)
}
#endif
void
RetinaImpl
::
getParvoRAW
(
OutputArray
parvoOutputBufferCopy
){
void
RetinaImpl
::
getParvoRAW
(
OutputArray
parvoOutputBufferCopy
)
{
if
(
_wasOCLRunCalled
)
{
CV_OCL_RUN
(
true
,
ocl_getParvoRAW
(
parvoOutputBufferCopy
));
CV_Error
(
Error
::
StsInternal
,
""
);
}
CV_OCL_RUN
((
_ocl_retina
!=
0
)
&&
parvoOutputBufferCopy
.
isUMat
(),
ocl_getParvoRAW
(
parvoOutputBufferCopy
));
CV_Assert
(
!
_wasOCLRunCalled
);
// get parvo channel header
const
cv
::
Mat
parvoChannel
=
cv
::
Mat
(
getParvoRAW
());
// copy data
...
...
@@ -713,16 +717,14 @@ void RetinaImpl::_init(const cv::Size inputSz, const bool colorMode, int colorSa
_wasOCLRunCalled
=
false
;
// basic error check
if
(
inputSz
.
height
*
inputSz
.
width
<=
0
)
throw
cv
::
Exception
(
-
1
,
"Bad retina size setup : size height and with must be superior to zero"
,
"RetinaImpl::setup"
,
"Retina.cpp"
,
0
);
CV_Error
(
Error
::
StsBadArg
,
"Bad retina size setup : size height and with must be superior to zero"
);
unsigned
int
nbPixels
=
inputSz
.
height
*
inputSz
.
width
;
// resize buffers if size does not match
_inputBuffer
.
resize
(
nbPixels
*
3
);
// buffer supports gray images but also 3 channels color buffers... (larger is better...)
// allocate the retina model
if
(
_retinaFilter
)
delete
_retinaFilter
;
_retinaFilter
=
new
RetinaFilter
(
inputSz
.
height
,
inputSz
.
width
,
colorMode
,
colorSamplingMethod
,
useRetinaLogSampling
,
reductionFactor
,
samplingStrenght
);
_retinaFilter
.
reset
(
new
RetinaFilter
(
inputSz
.
height
,
inputSz
.
width
,
colorMode
,
colorSamplingMethod
,
useRetinaLogSampling
,
reductionFactor
,
samplingStrenght
));
_retinaParameters
.
OPLandIplParvo
.
colorMode
=
colorMode
;
// prepare the default parameter XML file with default setup
...
...
@@ -776,7 +778,7 @@ bool RetinaImpl::_convertCvMat2ValarrayBuffer(InputArray inputMat, std::valarray
const
Mat
inputMatToConvert
=
inputMat
.
getMat
();
// first check input consistency
if
(
inputMatToConvert
.
empty
())
throw
cv
::
Exception
(
-
1
,
"RetinaImpl cannot be applied, input buffer is empty"
,
"RetinaImpl::run"
,
"RetinaImpl.h"
,
0
);
CV_Error
(
Error
::
StsBadArg
,
"RetinaImpl cannot be applied, input buffer is empty"
);
// retreive color mode from image input
int
imageNumberOfChannels
=
inputMatToConvert
.
channels
();
...
...
modules/bioinspired/src/retina_ocl.cpp
View file @
6f322a89
...
...
@@ -25,7 +25,7 @@
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other
oclM
aterials provided with the distribution.
// and/or other
m
aterials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
...
...
@@ -78,22 +78,17 @@ using namespace cv::ocl;
RetinaOCLImpl
::
RetinaOCLImpl
(
const
cv
::
Size
inputSz
)
{
_retinaFilter
=
0
;
_init
(
inputSz
,
true
,
RETINA_COLOR_BAYER
,
false
);
}
RetinaOCLImpl
::
RetinaOCLImpl
(
const
cv
::
Size
inputSz
,
const
bool
colorMode
,
int
colorSamplingMethod
,
const
bool
useRetinaLogSampling
,
const
double
reductionFactor
,
const
double
samplingStrenght
)
{
_retinaFilter
=
0
;
_init
(
inputSz
,
colorMode
,
colorSamplingMethod
,
useRetinaLogSampling
,
reductionFactor
,
samplingStrenght
);
}
RetinaOCLImpl
::~
RetinaOCLImpl
()
{
if
(
_retinaFilter
)
{
delete
_retinaFilter
;
}
// nothing
}
/**
...
...
@@ -323,13 +318,13 @@ void RetinaOCLImpl::run(InputArray input)
// process the retina
if
(
!
_retinaFilter
->
runFilter
(
_inputBuffer
,
colorMode
,
false
,
_retinaParameters
.
OPLandIplParvo
.
colorMode
&&
colorMode
,
false
))
{
throw
cv
::
Exception
(
-
1
,
"Retina cannot be applied, wrong input buffer size"
,
"RetinaOCLImpl::run"
,
"Retina.h"
,
0
);
CV_Error
(
Error
::
StsBadArg
,
"Retina cannot be applied, wrong input buffer size"
);
}
}
void
RetinaOCLImpl
::
getParvo
(
OutputArray
output
)
{
UMat
&
retinaOutput_parvo
=
output
.
getUMatRef
()
;
UMat
retinaOutput_parvo
;
if
(
_retinaFilter
->
getColorMode
())
{
// reallocate output buffer (if necessary)
...
...
@@ -341,13 +336,15 @@ void RetinaOCLImpl::getParvo(OutputArray output)
convertToInterleaved
(
_retinaFilter
->
getContours
(),
false
,
retinaOutput_parvo
);
}
//retinaOutput_parvo/=255.0;
output
.
assign
(
retinaOutput_parvo
);
}
void
RetinaOCLImpl
::
getMagno
(
OutputArray
output
)
{
UMat
&
retinaOutput_magno
=
output
.
getUMatRef
()
;
UMat
retinaOutput_magno
;
// reallocate output buffer (if necessary)
convertToInterleaved
(
_retinaFilter
->
getMovingContours
(),
false
,
retinaOutput_magno
);
//retinaOutput_magno/=255.0;
output
.
assign
(
retinaOutput_magno
);
}
// private method called by constructors
void
RetinaOCLImpl
::
_init
(
const
cv
::
Size
inputSz
,
const
bool
colorMode
,
int
colorSamplingMethod
,
const
bool
useRetinaLogSampling
,
const
double
reductionFactor
,
const
double
samplingStrenght
)
...
...
@@ -355,15 +352,11 @@ void RetinaOCLImpl::_init(const cv::Size inputSz, const bool colorMode, int colo
// basic error check
if
(
inputSz
.
height
*
inputSz
.
width
<=
0
)
{
throw
cv
::
Exception
(
-
1
,
"Bad retina size setup : size height and with must be superior to zero"
,
"RetinaOCLImpl::setup"
,
"Retina.h"
,
0
);
CV_Error
(
Error
::
StsBadArg
,
"Bad retina size setup : size height and with must be superior to zero"
);
}
// allocate the retina model
if
(
_retinaFilter
)
{
delete
_retinaFilter
;
}
_retinaFilter
=
new
RetinaFilter
(
inputSz
.
height
,
inputSz
.
width
,
colorMode
,
colorSamplingMethod
,
useRetinaLogSampling
,
reductionFactor
,
samplingStrenght
);
_retinaFilter
.
reset
(
new
RetinaFilter
(
inputSz
.
height
,
inputSz
.
width
,
colorMode
,
colorSamplingMethod
,
useRetinaLogSampling
,
reductionFactor
,
samplingStrenght
));
// prepare the default parameter XML file with default setup
setup
(
_retinaParameters
);
...
...
@@ -1514,4 +1507,4 @@ void RetinaFilter::_processRetinaParvoMagnoMapping()
}
/* namespace bioinspired */
}
/* namespace cv */
#endif
/
* #ifdef HAVE_OPENCL */
#endif /
/ HAVE_OPENCL
modules/bioinspired/src/retina_ocl.hpp
View file @
6f322a89
...
...
@@ -25,7 +25,7 @@
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other
oclM
aterials provided with the distribution.
// and/or other
m
aterials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
...
...
@@ -669,7 +669,7 @@ public:
protected
:
RetinaParameters
_retinaParameters
;
UMat
_inputBuffer
;
RetinaFilter
*
_retinaFilter
;
cv
::
Ptr
<
RetinaFilter
>
_retinaFilter
;
bool
convertToColorPlanes
(
const
UMat
&
input
,
UMat
&
output
);
void
convertToInterleaved
(
const
UMat
&
input
,
bool
colorMode
,
UMat
&
output
);
void
_init
(
const
Size
getInputSize
,
const
bool
colorMode
,
int
colorSamplingMethod
=
RETINA_COLOR_BAYER
,
const
bool
useRetinaLogSampling
=
false
,
const
double
reductionFactor
=
1.0
,
const
double
samplingStrenght
=
10.0
);
...
...
modules/bioinspired/test/test_retina_ocl.cpp
View file @
6f322a89
...
...
@@ -25,7 +25,7 @@
//
// * Redistribution's in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other
oclM
aterials provided with the distribution.
// and/or other
m
aterials provided with the distribution.
//
// * The name of the copyright holders may not be used to endorse or promote products
// derived from this software without specific prior written permission.
...
...
@@ -46,8 +46,6 @@
#include "test_precomp.hpp"
#include "opencv2/ts/ocl_test.hpp"
#ifdef HAVE_OPENCL
#define RETINA_ITERATIONS 5
namespace
cvtest
{
...
...
@@ -116,5 +114,3 @@ OCL_INSTANTIATE_TEST_CASE_P(Contrib, Retina_OCL, testing::Combine(
testing
::
Values
(
10.0
,
5.0
)));
}
}
// namespace cvtest::ocl
#endif // HAVE_OPENCL
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