Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
b4d42ae6
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b4d42ae6
编写于
8月 13, 2011
作者:
A
Alexandre Benoit
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimised input image management
上级
1a749c51
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
43 deletion
+46
-43
modules/contrib/src/retina.cpp
modules/contrib/src/retina.cpp
+46
-43
未找到文件。
modules/contrib/src/retina.cpp
浏览文件 @
b4d42ae6
...
...
@@ -92,6 +92,11 @@ Retina::~Retina()
delete
_retinaFilter
;
}
void
Retina
::
setColorSaturation
(
const
bool
saturateColors
,
const
double
colorSaturationValue
)
{
_retinaFilter
->
setColorSaturation
(
saturateColors
,
colorSaturationValue
);
}
void
Retina
::
setup
(
std
::
string
retinaParameterFile
,
const
bool
applyDefaultSetupOnFailure
)
{
// open specified parameters file
...
...
@@ -263,47 +268,10 @@ void Retina::setupIPLMagnoChannel(const bool normaliseOutput, const double paras
}
void
Retina
::
run
(
const
cv
::
Mat
&
input
Image
)
void
Retina
::
run
(
const
cv
::
Mat
&
input
MatToConvert
)
{
// first check input consistency
if
(
inputImage
.
empty
())
throw
cv
::
Exception
(
-
1
,
"Retina cannot be applied, input buffer is empty"
,
"Retina::run"
,
"Retina.h"
,
0
);
// retreive color mode from image input
bool
colorMode
=
inputImage
.
channels
()
>=
3
;
// TODO : ensure input color image is CV_BGR coded
//if (inputImage.flags!=CV_BGR)
// throw cv::Exception(-1, "Retina color input must be BGR coded", "Retina::run", "Retina.h", 0);
// first convert input image to the compatible format : std::valarray<double>
double
*
imagePTR
=&
_inputBuffer
[
0
];
if
(
!
colorMode
)
{
for
(
int
i
=
0
;
i
<
inputImage
.
size
().
height
;
++
i
)
{
const
unsigned
char
*
linePTR
=
inputImage
.
ptr
<
unsigned
char
>
(
i
);
for
(
int
j
=
0
;
j
<
inputImage
.
size
().
width
;
++
j
)
*
(
imagePTR
++
)
=
(
double
)
*
(
linePTR
++
);
}
}
else
{
const
unsigned
int
doubleNBpixelsPerLayer
=
_retinaFilter
->
getInputNBpixels
()
*
2
;
for
(
int
i
=
0
;
i
<
inputImage
.
size
().
height
;
++
i
)
{
for
(
int
j
=
0
;
j
<
inputImage
.
size
().
width
;
++
j
,
++
imagePTR
)
{
cv
::
Point2d
pixel
(
j
,
i
);
cv
::
Vec3b
pixelValue
=
inputImage
.
at
<
cv
::
Vec3b
>
(
pixel
);
*
(
imagePTR
)
=
(
double
)
pixelValue
[
2
];
*
(
imagePTR
+
_retinaFilter
->
getInputNBpixels
())
=
(
double
)
pixelValue
[
1
];
*
(
imagePTR
+
doubleNBpixelsPerLayer
)
=
(
double
)
pixelValue
[
0
];
}
}
}
const
bool
colorMode
=
_convertCvMat2ValarrayBuffer
(
inputMatToConvert
,
_inputBuffer
);
// process the retina
if
(
!
_retinaFilter
->
runFilter
(
_inputBuffer
,
colorMode
,
false
,
colorMode
,
false
))
throw
cv
::
Exception
(
-
1
,
"Retina cannot be applied, wrong input buffer size"
,
"Retina::run"
,
"Retina.h"
,
0
);
...
...
@@ -314,21 +282,22 @@ void Retina::getParvo(cv::Mat &retinaOutput_parvo)
if
(
_retinaFilter
->
getColorMode
())
{
// reallocate output buffer (if necessary)
_convertValarray
Gray
Buffer2cvMat
(
_retinaFilter
->
getColorOutput
(),
_retinaFilter
->
getOutputNBrows
(),
_retinaFilter
->
getOutputNBcolumns
(),
true
,
retinaOutput_parvo
);
_convertValarrayBuffer2cvMat
(
_retinaFilter
->
getColorOutput
(),
_retinaFilter
->
getOutputNBrows
(),
_retinaFilter
->
getOutputNBcolumns
(),
true
,
retinaOutput_parvo
);
}
else
{
// reallocate output buffer (if necessary)
_convertValarray
Gray
Buffer2cvMat
(
_retinaFilter
->
getContours
(),
_retinaFilter
->
getOutputNBrows
(),
_retinaFilter
->
getOutputNBcolumns
(),
false
,
retinaOutput_parvo
);
_convertValarrayBuffer2cvMat
(
_retinaFilter
->
getContours
(),
_retinaFilter
->
getOutputNBrows
(),
_retinaFilter
->
getOutputNBcolumns
(),
false
,
retinaOutput_parvo
);
}
//retinaOutput_parvo/=255.0;
}
void
Retina
::
getMagno
(
cv
::
Mat
&
retinaOutput_magno
)
{
// reallocate output buffer (if necessary)
_convertValarray
Gray
Buffer2cvMat
(
_retinaFilter
->
getMovingContours
(),
_retinaFilter
->
getOutputNBrows
(),
_retinaFilter
->
getOutputNBcolumns
(),
false
,
retinaOutput_magno
);
_convertValarrayBuffer2cvMat
(
_retinaFilter
->
getMovingContours
(),
_retinaFilter
->
getOutputNBrows
(),
_retinaFilter
->
getOutputNBcolumns
(),
false
,
retinaOutput_magno
);
//retinaOutput_magno/=255.0;
}
// private method called by constructirs
void
Retina
::
_init
(
const
std
::
string
parametersSaveFile
,
const
cv
::
Size
inputSize
,
const
bool
colorMode
,
RETINA_COLORSAMPLINGMETHOD
colorSamplingMethod
,
const
bool
useRetinaLogSampling
,
const
double
reductionFactor
,
const
double
samplingStrenght
)
{
...
...
@@ -369,7 +338,7 @@ void Retina::_init(const std::string parametersSaveFile, const cv::Size inputSiz
std
::
cout
<<
printSetup
()
<<
std
::
endl
;
}
void
Retina
::
_convertValarray
Gray
Buffer2cvMat
(
const
std
::
valarray
<
double
>
&
grayMatrixToConvert
,
const
unsigned
int
nbRows
,
const
unsigned
int
nbColumns
,
const
bool
colorMode
,
cv
::
Mat
&
outBuffer
)
void
Retina
::
_convertValarrayBuffer2cvMat
(
const
std
::
valarray
<
double
>
&
grayMatrixToConvert
,
const
unsigned
int
nbRows
,
const
unsigned
int
nbColumns
,
const
bool
colorMode
,
cv
::
Mat
&
outBuffer
)
{
// fill output buffer with the valarray buffer
const
double
*
valarrayPTR
=
get_data
(
grayMatrixToConvert
);
...
...
@@ -404,6 +373,40 @@ void Retina::_convertValarrayGrayBuffer2cvMat(const std::valarray<double> &grayM
}
}
const
bool
Retina
::
_convertCvMat2ValarrayBuffer
(
const
cv
::
Mat
inputMatToConvert
,
std
::
valarray
<
double
>
&
outputValarrayMatrix
)
{
// first check input consistency
if
(
inputMatToConvert
.
empty
())
throw
cv
::
Exception
(
-
1
,
"Retina cannot be applied, input buffer is empty"
,
"Retina::run"
,
"Retina.h"
,
0
);
// retreive color mode from image input
bool
colorMode
=
inputMatToConvert
.
channels
()
>=
3
;
// convert to double AND fill the valarray buffer
const
int
dsttype
=
CV_64F
;
// output buffer is double format
if
(
colorMode
)
{
// create a cv::Mat table (for RGB planes)
cv
::
Mat
planes
[]
=
{
cv
::
Mat
(
inputMatToConvert
.
size
(),
dsttype
,
&
outputValarrayMatrix
[
_retinaFilter
->
getInputNBpixels
()
*
2
]),
cv
::
Mat
(
inputMatToConvert
.
size
(),
dsttype
,
&
outputValarrayMatrix
[
_retinaFilter
->
getInputNBpixels
()]),
cv
::
Mat
(
inputMatToConvert
.
size
(),
dsttype
,
&
outputValarrayMatrix
[
0
])
};
// split color cv::Mat in 3 planes... it fills valarray directely
cv
::
split
(
Mat_
<
double
>
(
inputMatToConvert
),
planes
);
}
else
{
// create a cv::Mat header for the valarray
cv
::
Mat
dst
(
inputMatToConvert
.
size
(),
dsttype
,
&
outputValarrayMatrix
[
0
]);
inputMatToConvert
.
convertTo
(
dst
,
dsttype
);
}
return
colorMode
;
}
void
Retina
::
clearBuffers
()
{
_retinaFilter
->
clearAllBuffers
();}
}
// end of namespace cv
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录