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
e7955998
Commit
e7955998
authored
Oct 27, 2017
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1412 from berak:fix_saliency
parents
087db723
00ea0f49
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
31 additions
and
11 deletions
+31
-11
saliencySpecializedClasses.hpp
...y/include/opencv2/saliency/saliencySpecializedClasses.hpp
+1
-1
computeSaliency.cpp
modules/saliency/samples/computeSaliency.cpp
+20
-3
CmFile.cpp
modules/saliency/src/BING/CmFile.cpp
+1
-1
objectnessBING.cpp
modules/saliency/src/BING/objectnessBING.cpp
+9
-6
No files found.
modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp
View file @
e7955998
...
...
@@ -464,7 +464,7 @@ private:
void
setColorSpace
(
int
clr
=
MAXBGR
);
// Load trained model.
int
loadTrainedModel
(
std
::
string
modelName
=
""
);
// Return -1, 0, or 1 if partial, none, or all loaded
int
loadTrainedModel
();
// Return -1, 0, or 1 if partial, none, or all loaded
// Get potential bounding boxes, each of which is represented by a Vec4i for (minX, minY, maxX, maxY).
// The trained model should be prepared before calling this function: loadTrainedModel() or trainStageI() + trainStageII().
...
...
modules/saliency/samples/computeSaliency.cpp
View file @
e7955998
...
...
@@ -52,7 +52,7 @@ static const char* keys =
{
"{@saliency_algorithm | | Saliency algorithm <saliencyAlgorithmType.[saliencyAlgorithmTypeSubType]> }"
"{@video_name | | video name }"
"{@start_frame |1| Start frame }"
"{@training_path |
1
| Path of the folder containing the trained files}"
};
"{@training_path |
ObjectnessTrainedModel
| Path of the folder containing the trained files}"
};
static
void
help
()
{
...
...
@@ -150,11 +150,28 @@ int main( int argc, char** argv )
saliencyAlgorithm
=
ObjectnessBING
::
create
();
vector
<
Vec4i
>
saliencyMap
;
saliencyAlgorithm
.
dynamicCast
<
ObjectnessBING
>
()
->
setTrainingPath
(
training_path
);
saliencyAlgorithm
.
dynamicCast
<
ObjectnessBING
>
()
->
setBBResDir
(
training_path
+
"/
Results"
);
saliencyAlgorithm
.
dynamicCast
<
ObjectnessBING
>
()
->
setBBResDir
(
"
Results"
);
if
(
saliencyAlgorithm
->
computeSaliency
(
image
,
saliencyMap
)
)
{
std
::
cout
<<
"Objectness done"
<<
std
::
endl
;
int
ndet
=
int
(
saliencyMap
.
size
());
std
::
cout
<<
"Objectness done "
<<
ndet
<<
std
::
endl
;
// The result are sorted by objectness. We only use the first maxd boxes here.
int
maxd
=
7
,
step
=
255
/
maxd
,
jitter
=
9
;
// jitter to seperate single rects
Mat
draw
=
image
.
clone
();
for
(
int
i
=
0
;
i
<
std
::
min
(
maxd
,
ndet
);
i
++
)
{
Vec4i
bb
=
saliencyMap
[
i
];
Scalar
col
=
Scalar
(((
i
*
step
)
%
255
),
50
,
255
-
((
i
*
step
)
%
255
));
Point
off
(
theRNG
().
uniform
(
-
jitter
,
jitter
),
theRNG
().
uniform
(
-
jitter
,
jitter
));
rectangle
(
draw
,
Point
(
bb
[
0
]
+
off
.
x
,
bb
[
1
]
+
off
.
y
),
Point
(
bb
[
2
]
+
off
.
x
,
bb
[
3
]
+
off
.
y
),
col
,
2
);
rectangle
(
draw
,
Rect
(
20
,
20
+
i
*
10
,
10
,
10
),
col
,
-
1
);
// mini temperature scale
}
imshow
(
"BING"
,
draw
);
waitKey
();
}
else
{
std
::
cout
<<
"No saliency found for "
<<
video_name
<<
std
::
endl
;
}
}
...
...
modules/saliency/src/BING/CmFile.cpp
View file @
e7955998
...
...
@@ -76,7 +76,7 @@ bool CmFile::MkDir( std::string &_path )
buffer
[
i
]
=
'/'
;
}
}
mkdir
(
_path
.
c_str
(),
0
);
mkdir
(
_path
.
c_str
(),
S_IRWXU
|
S_IRWXG
|
S_IROTH
|
S_IXOTH
);
return
true
;
#endif
}
...
...
modules/saliency/src/BING/objectnessBING.cpp
View file @
e7955998
...
...
@@ -95,16 +95,14 @@ void ObjectnessBING::setBBResDir(const String &resultsDir )
_resultsDir
=
resultsDir
;
}
int
ObjectnessBING
::
loadTrainedModel
(
std
::
string
modelName
)
// Return -1, 0, or 1 if partial, none, or all loaded
int
ObjectnessBING
::
loadTrainedModel
()
// Return -1, 0, or 1 if partial, none, or all loaded
{
if
(
modelName
.
size
()
==
0
)
modelName
=
_modelName
;
CStr
s1
=
modelName
+
".wS1"
,
s2
=
modelName
+
".wS2"
,
sI
=
modelName
+
".idx"
;
CStr
s1
=
_modelName
+
".wS1"
,
s2
=
_modelName
+
".wS2"
,
sI
=
_modelName
+
".idx"
;
Mat
filters1f
,
reW1f
,
idx1i
,
show3u
;
if
(
!
matRead
(
s1
,
filters1f
)
||
!
matRead
(
sI
,
idx1i
)
)
{
printf
(
"Can't load model: %s or %s
\n
"
,
s1
.
c_str
(),
sI
.
c_str
()
);
printf
(
"Can't load model: %s or %s
\
r\
n
"
,
s1
.
c_str
(),
sI
.
c_str
()
);
return
0
;
}
...
...
@@ -384,7 +382,9 @@ void ObjectnessBING::getObjBndBoxesForSingleImage( Mat img, ValStructVec<float,
for
(
int
clr
=
MAXBGR
;
clr
<=
G
;
clr
++
)
{
setColorSpace
(
clr
);
loadTrainedModel
();
if
(
!
loadTrainedModel
())
continue
;
CmTimer
tm
(
"Predict"
);
tm
.
Start
();
...
...
@@ -439,6 +439,9 @@ bool ObjectnessBING::matRead( const std::string& filename, Mat& _M )
String
filenamePlusExt
(
filename
.
c_str
()
);
filenamePlusExt
+=
".yml.gz"
;
FileStorage
fs2
(
filenamePlusExt
,
FileStorage
::
READ
);
if
(
!
fs2
.
isOpened
())
// wrong trainingPath
return
false
;
Mat
M
;
fs2
[
String
(
removeExtension
(
basename
(
filename
)
).
c_str
()
)]
>>
M
;
...
...
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