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
b78f7136
Commit
b78f7136
authored
Jul 23, 2014
by
jaco
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lowResolutionDetection bug fixed
parent
7e589c5b
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
18 deletions
+88
-18
computeSaliency.cpp
modules/saliency/samples/computeSaliency.cpp
+21
-2
motionSaliencyBinWangApr2014.cpp
modules/saliency/src/motionSaliencyBinWangApr2014.cpp
+67
-16
No files found.
modules/saliency/samples/computeSaliency.cpp
View file @
b78f7136
...
...
@@ -156,10 +156,29 @@ int main( int argc, char** argv )
}
else
if
(
saliency_algorithm
.
find
(
"BinWangApr2014"
)
==
0
)
{
Ptr
<
Size
>
size
=
Ptr
<
Size
>
(
new
Size
(
64
,
64
)
)
;
saliencyAlgorithm
.
dynamicCast
<
MotionSaliencyBinWangApr2014
>
()
->
setWsize
(
size
);
saliencyAlgorithm
.
dynamicCast
<
MotionSaliencyBinWangApr2014
>
()
->
init
();
// Create an fake image test
Mat
test
(
64
,
64
,
CV_8U
);
RNG
rand
;
for
(
int
i
=
0
;
i
<
test
.
rows
;
i
++
)
for
(
int
j
=
0
;
j
<
test
.
cols
;
j
++
)
{
if
(
i
<
12
&&
i
>=
6
&&
j
<
12
&&
j
>=
6
)
test
.
at
<
uchar
>
(
i
,
j
)
=
255
;
else
test
.
at
<
uchar
>
(
i
,
j
)
=
rand
.
uniform
(
40
,
60
);
}
//imshow("Test", test);
//waitKey(0);
Mat
saliencyMap
;
if
(
saliencyAlgorithm
->
computeSaliency
(
image
,
saliencyMap
)
)
if
(
saliencyAlgorithm
->
computeSaliency
(
test
,
saliencyMap
)
)
{
std
::
cout
<<
"
OKKKK
"
<<
std
::
endl
;
std
::
cout
<<
"
motion saliency done
"
<<
std
::
endl
;
}
}
...
...
modules/saliency/src/motionSaliencyBinWangApr2014.cpp
View file @
b78f7136
...
...
@@ -40,6 +40,8 @@
//M*/
#include "precomp.hpp"
//TODO delete highgui include
#include <opencv2/highgui.hpp>
namespace
cv
{
...
...
@@ -74,11 +76,13 @@ bool MotionSaliencyBinWangApr2014::init()
epslonPixelsValue
=
Mat
(
imgSize
->
height
,
imgSize
->
width
,
CV_32F
);
potentialBackground
=
Mat
(
imgSize
->
height
,
imgSize
->
width
,
CV_32FC2
);
backgroundModel
=
std
::
vector
<
Mat
>
(
K
+
1
,
Mat
::
zeros
(
imgSize
->
height
,
imgSize
->
width
,
CV_32FC2
)
);
//TODO set to nan
potentialBackground
.
setTo
(
0
);
potentialBackground
.
setTo
(
NAN
);
for
(
size_t
i
=
0
;
i
<
backgroundModel
.
size
();
i
++
)
backgroundModel
[
i
].
setTo
(
NAN
);
//TODO set to nan
for
(
size_t
i
=
0
;
i
<
backgroundModel
.
size
();
i
++
){
backgroundModel
[
i
].
setTo
(
0
);
}
epslonPixelsValue
.
setTo
(
48.5
);
// Median of range [18, 80] advised in reference paper.
// Since data is even, the median is estimated using two values that occupy
...
...
@@ -157,7 +161,6 @@ bool MotionSaliencyBinWangApr2014::fullResolutionDetection( const Mat& image, Ma
return
true
;
}
//typedef Rect_<uint> Rect;
bool
MotionSaliencyBinWangApr2014
::
lowResolutionDetection
(
const
Mat
&
image
,
Mat
&
lowResBFMask
)
{
float
currentPixelValue
;
...
...
@@ -175,13 +178,16 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat
Mat
currentModel
;
// Initially, all pixels are considered as foreground and then we evaluate with the background model
lowResBFMask
.
create
(
image
.
size
().
height
/
(
N
*
N
),
image
.
size
().
width
/
(
N
*
N
),
CV_8UC1
);
//lowResBFMask.create( image.size().height / ( N * N ), image.size().width / ( N * N ), CV_8UC1 );
//lowResBFMask.setTo( 1 );
lowResBFMask
.
create
(
image
.
rows
,
image
.
cols
,
CV_8UC1
);
lowResBFMask
.
setTo
(
1
);
// Scan all the ROI of original matrices that correspond to the pixels of new resized matrices
for
(
int
i
=
0
;
i
<
image
.
rows
/
(
N
*
N
)
;
i
++
)
for
(
int
i
=
0
;
i
<
image
.
rows
/
N
;
i
++
)
{
for
(
int
j
=
0
;
j
<
image
.
cols
/
(
N
*
N
)
;
j
++
)
for
(
int
j
=
0
;
j
<
image
.
cols
/
N
;
j
++
)
{
// Reset and update ROI mask
ROIMask
.
setTo
(
0
);
...
...
@@ -207,21 +213,23 @@ bool MotionSaliencyBinWangApr2014::lowResolutionDetection( const Mat& image, Mat
{
// The correspondence pixel in the BF mask is set as background ( 0 value)
// TODO replace "at" with more efficient matrix access
lowResBFMask
.
at
<
uchar
>
(
i
,
j
)
=
0
;
//lowResBFMask.at<uchar>( i, j ) = 0;
lowResBFMask
.
setTo
(
0
,
ROIMask
);
break
;
}
}
}
// Shift the ROI from left to right follow the block dimension
roi
=
roi
+
Point
(
0
,
N
);
roi
=
roi
+
Point
(
N
,
0
);
}
//Shift the ROI from up to down follow the block dimension, also bringing it back to beginning of row
roi
=
roi
+
Point
(
N
,
-
(
image
.
cols
-
N
)
);
roi
.
x
=
0
;
roi
.
y
+=
N
;
}
// UPSAMPLE the lowResBFMask to the original image dimension, so that it's then possible to compare the results
// of lowlResolutionDetection with the fullResolutionDetection
resize
(
lowResBFMask
,
lowResBFMask
,
image
.
size
(),
0
,
0
,
INTER_LINEAR
);
//
resize( lowResBFMask, lowResBFMask, image.size(), 0, 0, INTER_LINEAR );
return
true
;
}
...
...
@@ -246,8 +254,51 @@ bool MotionSaliencyBinWangApr2014::templateReplacement( Mat finalBFMask )
bool
MotionSaliencyBinWangApr2014
::
computeSaliencyImpl
(
const
InputArray
image
,
OutputArray
saliencyMap
)
{
Mat
highResBFMask
;
Mat
lowResBFMask
;
Mat
t
(
image
.
getMat
().
rows
,
image
.
getMat
().
cols
,
CV_32FC2
);
t
.
setTo
(
50
);
backgroundModel
.
at
(
0
)
=
t
;
fullResolutionDetection
(
image
.
getMat
(),
highResBFMask
);
lowResolutionDetection
(
image
.
getMat
(),
lowResBFMask
);
std
::
ofstream
ofs
;
ofs
.
open
(
"highResBFMask.txt"
,
std
::
ofstream
::
out
);
for
(
int
i
=
0
;
i
<
highResBFMask
.
rows
;
i
++
)
{
for
(
int
j
=
0
;
j
<
highResBFMask
.
cols
;
j
++
)
{
//highResBFMask.at<int>( i, j ) = i + j;
stringstream
str
;
str
<<
(
int
)
highResBFMask
.
at
<
uchar
>
(
i
,
j
)
<<
" "
;
ofs
<<
str
.
str
();
}
stringstream
str2
;
str2
<<
"
\n
"
;
ofs
<<
str2
.
str
();
}
ofs
.
close
();
std
::
ofstream
ofs2
;
ofs2
.
open
(
"lowResBFMask.txt"
,
std
::
ofstream
::
out
);
for
(
int
i
=
0
;
i
<
lowResBFMask
.
rows
;
i
++
)
{
for
(
int
j
=
0
;
j
<
lowResBFMask
.
cols
;
j
++
)
{
stringstream
str
;
str
<<
(
int
)
lowResBFMask
.
at
<
uchar
>
(
i
,
j
)
<<
" "
;
ofs2
<<
str
.
str
();
}
stringstream
str2
;
str2
<<
"
\n
"
;
ofs2
<<
str2
.
str
();
}
ofs2
.
close
();
Mat
Test
(
36
,
3
6
,
CV_32F
);
/*Mat Test( 16, 1
6, CV_32F );
Mat Results;
std::ofstream ofs;
...
...
@@ -268,9 +319,9 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image,
}
ofs.close();
//blur( Test, Results, Size( 4, 4 ) );
//blur( Test, Results, Size( 4, 4 ) );
medianBlur( Test, Results, 3 );
//pyrDown(Results,Results, Size(Test.size().height/9, Test.size().width/9));
//pyrDown(Results,Results, Size(Test.size().height/9, Test.size().width/9));
std::ofstream ofs2;
ofs2.open( "RESULTS.txt", std::ofstream::out );
...
...
@@ -290,7 +341,7 @@ bool MotionSaliencyBinWangApr2014::computeSaliencyImpl( const InputArray image,
ofs2.close();
std::cout << "TEST SIZE: " << Test.size().height << " " << Test.size().width << " RESULTS SIZE: " << Results.size().height << " "
<<
Results
.
size
().
width
<<
std
::
endl
;
<< Results.size().width << std::endl; */
return
true
;
}
...
...
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