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
41b0a71a
Commit
41b0a71a
authored
Oct 06, 2016
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #796 from sovrasov:saliency_python_bindings
parents
82e612bb
94e919eb
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
42 deletions
+94
-42
CMakeLists.txt
modules/saliency/CMakeLists.txt
+8
-0
saliencyBaseClasses.hpp
...saliency/include/opencv2/saliency/saliencyBaseClasses.hpp
+9
-9
saliencySpecializedClasses.hpp
...y/include/opencv2/saliency/saliencySpecializedClasses.hpp
+68
-29
objectnessBING.cpp
modules/saliency/src/BING/objectnessBING.cpp
+5
-2
staticSaliency.cpp
modules/saliency/src/staticSaliency.cpp
+4
-2
No files found.
modules/saliency/CMakeLists.txt
View file @
41b0a71a
set
(
the_description
"Saliency API"
)
set
(
OPENCV_MODULE_IS_PART_OF_WORLD OFF
)
add_definitions
(
-DOBJECTNESS_MODELS_PATH=
"
${
CMAKE_INSTALL_PREFIX
}
/
${
OPENCV_OTHER_INSTALL_PATH
}
/Objectness"
)
file
(
GLOB OBJECTNESS_TRAINED_MODELS samples/ObjectnessTrainedModel/*.yml.gz
)
install
(
FILES
${
OBJECTNESS_TRAINED_MODELS
}
DESTINATION
${
OPENCV_OTHER_INSTALL_PATH
}
/Objectness COMPONENT libs
)
install
(
DIRECTORY DESTINATION
${
OPENCV_OTHER_INSTALL_PATH
}
/Objectness/Results
)
ocv_define_module
(
saliency opencv_imgproc opencv_highgui opencv_features2d WRAP python
)
modules/saliency/include/opencv2/saliency/saliencyBaseClasses.hpp
View file @
41b0a71a
...
...
@@ -59,7 +59,7 @@ namespace saliency
/************************************ Saliency Base Class ************************************/
class
CV_EXPORTS
Saliency
:
public
virtual
Algorithm
class
CV_EXPORTS
_W
Saliency
:
public
virtual
Algorithm
{
public
:
/**
...
...
@@ -78,13 +78,13 @@ class CV_EXPORTS Saliency : public virtual Algorithm
* \param saliencyMap The computed saliency map.
* \return true if the saliency map is computed, false otherwise
*/
bool
computeSaliency
(
InputArray
image
,
OutputArray
saliencyMap
);
CV_WRAP
bool
computeSaliency
(
InputArray
image
,
OutputArray
saliencyMap
);
/**
* \brief Get the name of the specific saliency type
* \return The name of the tracker initializer
*/
String
getClassName
()
const
;
CV_WRAP
String
getClassName
()
const
;
protected
:
...
...
@@ -93,7 +93,7 @@ class CV_EXPORTS Saliency : public virtual Algorithm
};
/************************************ Static Saliency Base Class ************************************/
class
CV_EXPORTS
StaticSaliency
:
public
virtual
Saliency
class
CV_EXPORTS
_W
StaticSaliency
:
public
virtual
Saliency
{
public
:
...
...
@@ -109,17 +109,17 @@ class CV_EXPORTS StaticSaliency : public virtual Saliency
algorithm calculates the optimal threshold separating those two classes, so that their
intra-class variance is minimal.
@param saliencyMap the saliency map obtained through one of the specialized algorithms
@param binaryMap the binary map
@param
_
saliencyMap the saliency map obtained through one of the specialized algorithms
@param
_
binaryMap the binary map
*/
bool
computeBinaryMap
(
const
Mat
&
saliencyMap
,
Mat
&
binaryMap
);
CV_WRAP
bool
computeBinaryMap
(
InputArray
_saliencyMap
,
OutputArray
_
binaryMap
);
protected
:
virtual
bool
computeSaliencyImpl
(
InputArray
image
,
OutputArray
saliencyMap
)
=
0
;
};
/************************************ Motion Saliency Base Class ************************************/
class
CV_EXPORTS
MotionSaliency
:
public
virtual
Saliency
class
CV_EXPORTS
_W
MotionSaliency
:
public
virtual
Saliency
{
protected
:
...
...
@@ -128,7 +128,7 @@ class CV_EXPORTS MotionSaliency : public virtual Saliency
};
/************************************ Objectness Base Class ************************************/
class
CV_EXPORTS
Objectness
:
public
virtual
Saliency
class
CV_EXPORTS
_W
Objectness
:
public
virtual
Saliency
{
protected
:
...
...
modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp
View file @
41b0a71a
...
...
@@ -42,11 +42,11 @@
#ifndef __OPENCV_SALIENCY_SPECIALIZED_CLASSES_HPP__
#define __OPENCV_SALIENCY_SPECIALIZED_CLASSES_HPP__
//#include "opencv2/saliency/kyheader.hpp"
#include <cstdio>
#include <string>
#include <iostream>
#include <stdint.h>
#include "saliencyBaseClasses.hpp"
#include "opencv2/core.hpp"
namespace
cv
...
...
@@ -66,37 +66,50 @@ pre-attentive visual search. The algorithm analyze the log spectrum of each imag
spectral residual. Then transform the spectral residual to spatial domain to obtain the saliency
map, which suggests the positions of proto-objects.
*/
class
CV_EXPORTS
StaticSaliencySpectralResidual
:
public
StaticSaliency
class
CV_EXPORTS
_W
StaticSaliencySpectralResidual
:
public
StaticSaliency
{
public
:
StaticSaliencySpectralResidual
();
virtual
~
StaticSaliencySpectralResidual
();
void
read
(
const
FileNode
&
fn
);
CV_WRAP
static
Ptr
<
StaticSaliencySpectralResidual
>
create
()
{
return
makePtr
<
StaticSaliencySpectralResidual
>
();
}
CV_WRAP
bool
computeSaliency
(
InputArray
image
,
OutputArray
saliencyMap
)
{
if
(
image
.
empty
()
)
return
false
;
return
computeSaliencyImpl
(
image
,
saliencyMap
);
}
CV_WRAP
void
read
(
const
FileNode
&
fn
);
void
write
(
FileStorage
&
fs
)
const
;
int
getImageWidth
()
const
CV_WRAP
int
getImageWidth
()
const
{
return
resImWidth
;
}
inline
void
setImageWidth
(
int
val
)
CV_WRAP
inline
void
setImageWidth
(
int
val
)
{
resImWidth
=
val
;
}
int
getImageHeight
()
const
CV_WRAP
int
getImageHeight
()
const
{
return
resImHeight
;
}
void
setImageHeight
(
int
val
)
CV_WRAP
void
setImageHeight
(
int
val
)
{
resImHeight
=
val
;
}
protected
:
bool
computeSaliencyImpl
(
InputArray
image
,
OutputArray
saliencyMap
);
int
resImWidth
;
int
resImHeight
;
CV_PROP_RW
int
resImWidth
;
CV_PROP_RW
int
resImHeight
;
};
...
...
@@ -111,36 +124,49 @@ protected:
*/
/** @brief the Fast Self-tuning Background Subtraction Algorithm from @cite BinWangApr2014
*/
class
CV_EXPORTS
MotionSaliencyBinWangApr2014
:
public
MotionSaliency
class
CV_EXPORTS
_W
MotionSaliencyBinWangApr2014
:
public
MotionSaliency
{
public
:
MotionSaliencyBinWangApr2014
();
virtual
~
MotionSaliencyBinWangApr2014
();
CV_WRAP
static
Ptr
<
MotionSaliencyBinWangApr2014
>
create
()
{
return
makePtr
<
MotionSaliencyBinWangApr2014
>
();
}
CV_WRAP
bool
computeSaliency
(
InputArray
image
,
OutputArray
saliencyMap
)
{
if
(
image
.
empty
()
)
return
false
;
return
computeSaliencyImpl
(
image
,
saliencyMap
);
}
/** @brief This is a utility function that allows to set the correct size (taken from the input image) in the
corresponding variables that will be used to size the data structures of the algorithm.
@param W width of input image
@param H height of input image
*/
void
setImagesize
(
int
W
,
int
H
);
CV_WRAP
void
setImagesize
(
int
W
,
int
H
);
/** @brief This function allows the correct initialization of all data structures that will be used by the
algorithm.
*/
bool
init
();
CV_WRAP
bool
init
();
int
getImageWidth
()
const
CV_WRAP
int
getImageWidth
()
const
{
return
imageWidth
;
}
inline
void
setImageWidth
(
int
val
)
CV_WRAP
inline
void
setImageWidth
(
int
val
)
{
imageWidth
=
val
;
}
int
getImageHeight
()
const
CV_WRAP
int
getImageHeight
()
const
{
return
imageHeight
;
}
void
setImageHeight
(
int
val
)
CV_WRAP
void
setImageHeight
(
int
val
)
{
imageHeight
=
val
;
}
...
...
@@ -177,8 +203,8 @@ private:
//fixed parameter
bool
neighborhoodCheck
;
int
N_DS
;
// Number of template to be downsampled and used in lowResolutionDetection function
int
imageWidth
;
// Width of input image
int
imageHeight
;
//Height of input image
CV_PROP_RW
int
imageWidth
;
// Width of input image
CV_PROP_RW
int
imageHeight
;
//Height of input image
int
K
;
// Number of background model template
int
N
;
// NxN is the size of the block for downsampling in the lowlowResolutionDetection
float
alpha
;
// Learning rate
...
...
@@ -200,15 +226,28 @@ private:
/** @brief the Binarized normed gradients algorithm from @cite BING
*/
class
CV_EXPORTS
ObjectnessBING
:
public
Objectness
class
CV_EXPORTS
_W
ObjectnessBING
:
public
Objectness
{
public
:
ObjectnessBING
();
virtual
~
ObjectnessBING
();
void
read
();
void
write
()
const
;
CV_WRAP
static
Ptr
<
ObjectnessBING
>
create
()
{
return
makePtr
<
ObjectnessBING
>
();
}
CV_WRAP
bool
computeSaliency
(
InputArray
image
,
OutputArray
saliencyMap
)
{
if
(
image
.
empty
()
)
return
false
;
return
computeSaliencyImpl
(
image
,
saliencyMap
);
}
CV_WRAP
void
read
();
CV_WRAP
void
write
()
const
;
/** @brief Return the list of the rectangles' objectness value,
...
...
@@ -222,7 +261,7 @@ public:
the trained model.
@param trainingPath trained model path
*/
void
setTrainingPath
(
std
::
string
trainingPath
);
CV_WRAP
void
setTrainingPath
(
const
String
&
trainingPath
);
/** @brief This is a utility function that allows to set an arbitrary path in which the algorithm will save the
optional results
...
...
@@ -231,29 +270,29 @@ public:
each row).
@param resultsDir results' folder path
*/
void
setBBResDir
(
std
::
string
resultsDir
);
CV_WRAP
void
setBBResDir
(
const
String
&
resultsDir
);
double
getBase
()
const
CV_WRAP
double
getBase
()
const
{
return
_base
;
}
inline
void
setBase
(
double
val
)
CV_WRAP
inline
void
setBase
(
double
val
)
{
_base
=
val
;
}
int
getNSS
()
const
CV_WRAP
int
getNSS
()
const
{
return
_NSS
;
}
void
setNSS
(
int
val
)
CV_WRAP
void
setNSS
(
int
val
)
{
_NSS
=
val
;
}
int
getW
()
const
CV_WRAP
int
getW
()
const
{
return
_W
;
}
void
setW
(
int
val
)
CV_WRAP
void
setW
(
int
val
)
{
_W
=
val
;
}
...
...
modules/saliency/src/BING/objectnessBING.cpp
View file @
41b0a71a
...
...
@@ -71,6 +71,9 @@ ObjectnessBING::ObjectnessBING()
setColorSpace
(
_Clr
);
className
=
"BING"
;
setTrainingPath
(
OBJECTNESS_MODELS_PATH
);
setBBResDir
(
OBJECTNESS_MODELS_PATH
"/Results"
);
}
ObjectnessBING
::~
ObjectnessBING
()
...
...
@@ -85,12 +88,12 @@ void ObjectnessBING::setColorSpace( int clr )
_bbResDir
=
_resultsDir
+
"/"
+
std
::
string
(
format
(
"BBoxesB%gW%d%s/"
,
_base
,
_W
,
_clrName
[
_Clr
]
).
c_str
()
);
}
void
ObjectnessBING
::
setTrainingPath
(
std
::
string
trainingPath
)
void
ObjectnessBING
::
setTrainingPath
(
const
String
&
trainingPath
)
{
_trainingPath
=
trainingPath
;
}
void
ObjectnessBING
::
setBBResDir
(
std
::
string
resultsDir
)
void
ObjectnessBING
::
setBBResDir
(
const
String
&
resultsDir
)
{
_resultsDir
=
resultsDir
;
}
...
...
modules/saliency/src/staticSaliency.cpp
View file @
41b0a71a
...
...
@@ -50,9 +50,9 @@ namespace saliency
* StaticSaliency
*/
bool
StaticSaliency
::
computeBinaryMap
(
const
Mat
&
saliencyMap
,
Mat
&
B
inaryMap
)
bool
StaticSaliency
::
computeBinaryMap
(
InputArray
_saliencyMap
,
OutputArray
_b
inaryMap
)
{
Mat
saliencyMap
=
_saliencyMap
.
getMat
();
Mat
labels
=
Mat
::
zeros
(
saliencyMap
.
rows
*
saliencyMap
.
cols
,
1
,
1
);
Mat
samples
=
Mat_
<
float
>
(
saliencyMap
.
rows
*
saliencyMap
.
cols
,
1
);
Mat
centers
;
...
...
@@ -90,6 +90,8 @@ bool StaticSaliency::computeBinaryMap( const Mat& saliencyMap, Mat& BinaryMap )
outputMat
.
convertTo
(
outputMat
,
CV_8U
);
// adaptative thresholding using Otsu's method, to make saliency map binary
_binaryMap
.
createSameSize
(
outputMat
,
outputMat
.
type
());
Mat
BinaryMap
=
_binaryMap
.
getMat
();
threshold
(
outputMat
,
BinaryMap
,
0
,
255
,
THRESH_BINARY
|
THRESH_OTSU
);
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