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
b904b5b4
Commit
b904b5b4
authored
Aug 07, 2014
by
jaco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
efficient structures access restored
parent
e56f2870
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
44 deletions
+33
-44
motionSaliencyBinWangApr2014.cpp
modules/saliency/src/motionSaliencyBinWangApr2014.cpp
+33
-44
No files found.
modules/saliency/src/motionSaliencyBinWangApr2014.cpp
View file @
b904b5b4
...
@@ -61,10 +61,10 @@ MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014()
...
@@ -61,10 +61,10 @@ MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014()
K
=
3
;
// Number of background model template
K
=
3
;
// Number of background model template
N
=
4
;
// NxN is the size of the block for downsampling in the lowlowResolutionDetection
N
=
4
;
// NxN is the size of the block for downsampling in the lowlowResolutionDetection
alpha
=
0.01
;
// Learning rate
alpha
=
0.01
;
// Learning rate
L0
=
60
00
;
// Upper-bound values for C0 (efficacy of the first template (matrices) of backgroundModel
L0
=
3
00
;
// Upper-bound values for C0 (efficacy of the first template (matrices) of backgroundModel
L1
=
40
00
;
// Upper-bound values for C1 (efficacy of the second template (matrices) of backgroundModel
L1
=
2
00
;
// Upper-bound values for C1 (efficacy of the second template (matrices) of backgroundModel
thetaL
=
50
;
// T0, T1 swap threshold
thetaL
=
50
;
// T0, T1 swap threshold
thetaA
=
20
0
;
thetaA
=
5
0
;
gamma
=
3
;
gamma
=
3
;
neighborhoodCheck
=
true
;
neighborhoodCheck
=
true
;
...
@@ -74,31 +74,26 @@ MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014()
...
@@ -74,31 +74,26 @@ MotionSaliencyBinWangApr2014::MotionSaliencyBinWangApr2014()
bool
MotionSaliencyBinWangApr2014
::
init
()
bool
MotionSaliencyBinWangApr2014
::
init
()
{
{
epslonPixelsValue
=
Mat
(
imgSize
->
height
,
imgSize
->
width
,
CV_32F
);
epslonPixelsValue
=
Mat
(
imgSize
->
height
,
imgSize
->
width
,
CV_32F
,
Scalar
(
70
)
);
potentialBackground
=
Mat
(
imgSize
->
height
,
imgSize
->
width
,
CV_32FC2
);
// Median of range [18, 80] advised in reference paper.
//backgroundModel = std::vector<Mat>( K + 1, Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 ) );
// Since data is even, the median is estimated using two values that occupy
// the position (n / 2) and ((n / 2) +1) (choose their arithmetic mean).
//TODO set to nan
//TODO set to nan
potentialBackground
.
setTo
(
0
);
potentialBackground
=
Mat
(
imgSize
->
height
,
imgSize
->
width
,
CV_32FC2
,
Scalar
(
0
)
);
//backgroundModel = std::vector<Mat>( K + 1, Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 ) );
backgroundModel
.
resize
(
K
+
1
);
backgroundModel
.
resize
(
K
+
1
);
//TODO set to nan
//TODO set to nan
for
(
int
i
=
0
;
i
<
K
+
1
;
i
++
)
for
(
int
i
=
0
;
i
<
K
+
1
;
i
++
)
{
{
Mat
*
tmpm
=
new
Mat
;
Mat
*
tmpm
=
new
Mat
;
tmpm
->
create
(
imgSize
->
height
,
imgSize
->
width
,
CV_32FC2
);
tmpm
->
create
(
imgSize
->
height
,
imgSize
->
width
,
CV_32FC2
);
tmpm
->
setTo
(
0
);
tmpm
->
setTo
(
0
);
Ptr
<
Mat
>
tmp
=
Ptr
<
Mat
>
(
tmpm
);
Ptr
<
Mat
>
tmp
=
Ptr
<
Mat
>
(
tmpm
);
backgroundModel
[
i
]
=
tmp
;
backgroundModel
[
i
]
=
tmp
;
}
}
epslonPixelsValue
.
setTo
(
70
);
// Median of range [18, 80] advised in reference paper.
// Since data is even, the median is estimated using two values that occupy
// the position (n / 2) and ((n / 2) +1) (choose their arithmetic mean).
/* epslonPixelsValue = Mat::zeros( imgSize->height, imgSize->width, CV_8U );
potentialBackground = Mat::NAN( imgSize->height, imgSize->width, CV_32FC2 );
backgroundModel = std::vector<Mat>( 4, Mat::zeros( imgSize->height, imgSize->width, CV_32FC2 ) );*/
return
true
;
return
true
;
}
}
...
@@ -142,8 +137,6 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
...
@@ -142,8 +137,6 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
float
*
pEpslon
;
float
*
pEpslon
;
float
*
pMask
;
float
*
pMask
;
int
countDec
=
0
;
// Scan all pixels of image
// Scan all pixels of image
for
(
int
i
=
0
;
i
<
image
.
rows
;
i
++
)
for
(
int
i
=
0
;
i
<
image
.
rows
;
i
++
)
{
{
...
@@ -167,7 +160,7 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
...
@@ -167,7 +160,7 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
int
counter
=
0
;
int
counter
=
0
;
for
(
size_t
z
=
0
;
z
<
backgroundModel
.
size
();
z
++
)
for
(
size_t
z
=
0
;
z
<
backgroundModel
.
size
();
z
++
)
{
{
counter
+=
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
1
];
counter
+=
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
1
];
}
}
if
(
counter
!=
0
)
//if at least the first template is activated / initialized
if
(
counter
!=
0
)
//if at least the first template is activated / initialized
...
@@ -176,40 +169,38 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
...
@@ -176,40 +169,38 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
// scan background model vector
// scan background model vector
for
(
size_t
z
=
0
;
z
<
backgroundModel
.
size
();
z
++
)
for
(
size_t
z
=
0
;
z
<
backgroundModel
.
size
();
z
++
)
{
{
float
currentB
;
float
*
currentB
;
float
currentC
;
float
*
currentC
;
// TODO replace "at" with more efficient matrix access
// TODO replace "at" with more efficient matrix access
currentB
=
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
0
]
);
currentB
=
&
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
0
]
);
currentC
=
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
1
]
);
currentC
=
&
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
1
]
);
if
(
i
==
50
&&
j
==
50
)
if
(
i
==
50
&&
j
==
50
)
{
{
cout
<<
"zeta:"
<<
z
<<
" currentB :"
<<
currentB
<<
endl
<<
"currentC :"
<<
currentC
<<
endl
;
cout
<<
"zeta:"
<<
z
<<
" currentB :"
<<
*
currentB
<<
endl
<<
"currentC :"
<<
*
currentC
<<
endl
;
}
}
//continue;
//continue;
if
(
currentC
>
0
)
//The current template is active
if
(
*
currentC
>
0
)
//The current template is active
{
{
//cout<< "DIFFERENCE: "<<abs( currentPixelValue - ( *currentB ) )<<endl;
//cout<< "DIFFERENCE: "<<abs( currentPixelValue - ( *currentB ) )<<endl;
// If there is a match with a current background template
// If there is a match with a current background template
if
(
abs
(
currentPixelValue
-
(
currentB
)
)
<
currentEpslonValue
&&
!
backgFlag
)
if
(
abs
(
currentPixelValue
-
(
*
currentB
)
)
<
currentEpslonValue
&&
!
backgFlag
)
{
{
// The correspondence pixel in the BF mask is set as background ( 0 value)
// The correspondence pixel in the BF mask is set as background ( 0 value)
//highResBFMask.at<uchar>( i, j ) = 0;
//highResBFMask.at<uchar>( i, j ) = 0;
pMask
[
j
]
=
0
;
pMask
[
j
]
=
0
;
//if( ( *currentC < L0 && z == 0 ) || ( *currentC < L1 && z == 1 ) || ( z > 1 ) )
if
(
(
*
currentC
<
L0
&&
z
==
0
)
||
(
*
currentC
<
L1
&&
z
==
1
)
||
(
z
>
1
)
){
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
1
])
=
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
1
])
+
1
;
// increment the efficacy of this template
*
currentC
+=
1
;
// increment the efficacy of this template
}
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
0
])
=
(
(
1
-
alpha
)
*
(
currentB
)
)
+
(
alpha
*
currentPixelValue
);
// Update the template value
*
currentB
=
(
(
1
-
alpha
)
*
(
*
currentB
)
)
+
(
alpha
*
currentPixelValue
);
// Update the template value
backgFlag
=
true
;
backgFlag
=
true
;
//break;
//break;
}
}
else
else
{
{
if
(
z
==
0
)
*
currentC
-=
1
;
// decrement the efficacy of this template
countDec
++
;
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
1
])
=
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
1
])
-
1
;
// decrement the efficacy of this template
}
}
}
}
...
@@ -217,8 +208,8 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
...
@@ -217,8 +208,8 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image2, M
if
(
i
==
50
&&
j
==
50
)
if
(
i
==
50
&&
j
==
50
)
{
{
cout
<<
"DOPO IF: "
<<
endl
;
cout
<<
"DOPO IF: "
<<
endl
;
cout
<<
"zeta:"
<<
z
<<
" currentB_A :"
<<
&
currentB
<<
endl
<<
"currentC_A :"
<<
&
currentC
<<
endl
;
cout
<<
"zeta:"
<<
z
<<
" currentB_A :"
<<
currentB
<<
endl
<<
"currentC_A :"
<<
currentC
<<
endl
;
cout
<<
"zeta:"
<<
z
<<
" currentB :"
<<
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
0
])
<<
endl
<<
"currentC :"
<<
(
backgroundModel
.
at
(
z
)
->
at
<
Vec2f
>
(
i
,
j
)[
1
])
<<
endl
<<
endl
;
cout
<<
"zeta:"
<<
z
<<
" currentB :"
<<
*
currentB
<<
endl
<<
"currentC :"
<<
*
currentC
<<
endl
<<
endl
;
}
}
}
// end "for" cicle of template vector
}
// end "for" cicle of template vector
...
@@ -281,7 +272,7 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat
...
@@ -281,7 +272,7 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat
for
(
int
z
=
0
;
z
<
N_DS
;
z
++
)
for
(
int
z
=
0
;
z
<
N_DS
;
z
++
)
{
{
// Select the current template 2 channel matrix, select ROI and compute the mean for each channel separately
// Select the current template 2 channel matrix, select ROI and compute the mean for each channel separately
Mat
roiTemplate
=
(
*
(
backgroundModel
[
z
])
)(
roi
);
Mat
roiTemplate
=
(
*
(
backgroundModel
[
z
]
)
)(
roi
);
Scalar
templateMean
=
mean
(
roiTemplate
);
Scalar
templateMean
=
mean
(
roiTemplate
);
currentB
=
templateMean
[
0
];
currentB
=
templateMean
[
0
];
currentC
=
templateMean
[
1
];
currentC
=
templateMean
[
1
];
...
@@ -413,8 +404,8 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask,
...
@@ -413,8 +404,8 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask,
}
}
else
else
{
{
thetaA
=
20
0
;
thetaA
=
5
0
;
neighborhoodCheck
=
fals
e
;
neighborhoodCheck
=
tru
e
;
}
}
float
roiSize
=
3
;
// FIXED ROI SIZE, not change until you first appropriately adjust the following controls in the EVALUATION section!
float
roiSize
=
3
;
// FIXED ROI SIZE, not change until you first appropriately adjust the following controls in the EVALUATION section!
...
@@ -542,10 +533,8 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask,
...
@@ -542,10 +533,8 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( const Mat& finalBFMask,
}
}
else
else
{
{
((
backgroundModel
.
at
(
backgroundModel
.
size
()
-
1
))
->
at
<
Vec2f
>
(
i
,
j
))[
0
]
=
potentialBackground
.
at
<
Vec2f
>
(
i
,
j
)[
0
];
backgroundModel
[
backgroundModel
.
size
()
-
1
]
->
at
<
Vec2f
>
(
i
,
j
)
=
potentialBackground
.
at
<
Vec2f
>
(
i
,
j
);
((
backgroundModel
.
at
(
backgroundModel
.
size
()
-
1
))
->
at
<
Vec2f
>
(
i
,
j
))[
1
]
=
potentialBackground
.
at
<
Vec2f
>
(
i
,
j
)[
1
];
potentialBackground
.
at
<
Vec2f
>
(
i
,
j
)
=
0
;
potentialBackground
.
at
<
Vec2f
>
(
i
,
j
)[
0
]
=
0
;
potentialBackground
.
at
<
Vec2f
>
(
i
,
j
)[
1
]
=
0
;
//((backgroundModel.at(0))->at<Vec2f>( i, j ))[1] = 3;
//((backgroundModel.at(0))->at<Vec2f>( i, j ))[1] = 3;
}
}
}
// close if of EVALUATION
}
// close if of EVALUATION
...
...
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