Skip to content

Commit b691b74

Browse files
jacosovrasov
authored andcommitted
noise control implementation started
noise control implementation ended noise control errors fixed (part I) noise control errors fixed (ended) Perf Test for staticSaliencySpectralResidual and objectnessBING added improvements and bugs fixed saliency perf test added matrices optimization Where possible, CV_8U matrices have been used in place of CV_32F new sorting algorithm implemented (first part) new sorting algorithm implemented (second part) new sorting algorithm implemented (finished)
1 parent e80393b commit b691b74

File tree

8 files changed

+636
-143
lines changed

8 files changed

+636
-143
lines changed

modules/saliency/include/opencv2/saliency/saliencySpecializedClasses.hpp

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,28 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
234234
bool templateOrdering();
235235
bool templateReplacement( const Mat& finalBFMask, const Mat& image );
236236

237+
// Decision threshold adaptation and Activity control function
238+
bool activityControl(const Mat& current_noisePixelsMask);
239+
bool decisionThresholdAdaptation();
240+
237241
// changing structure
238242
std::vector<Ptr<Mat> > backgroundModel;// The vector represents the background template T0---TK of reference paper.
239243
// Matrices are two-channel matrix. In the first layer there are the B (background value)
240244
// for each pixel. In the second layer, there are the C (efficacy) value for each pixel
241245
Mat potentialBackground;// Two channel Matrix. For each pixel, in the first level there are the Ba value (potential background value)
242246
// and in the secon level there are the Ca value, the counter for each potential value.
243-
Mat epslonPixelsValue; // epslon threshold
247+
Mat epslonPixelsValue;// epslon threshold
248+
249+
Mat activityPixelsValue;// Activity level of each pixel
250+
251+
//vector<Mat> noisePixelMask; // We define a ‘noise-pixel’ as a pixel that has been classified as a foreground pixel during the full resolution
252+
Mat noisePixelMask;// We define a ‘noise-pixel’ as a pixel that has been classified as a foreground pixel during the full resolution
253+
//detection process,however, after the low resolution detection, it has become a
254+
// background pixel. The matrix is two-channel matrix. In the first layer there is the mask ( the identified noise-pixels are set to 1 while other pixels are 0)
255+
// for each pixel. In the second layer, there is the value of activity level A for each pixel.
244256

245257
//fixed parameter
258+
bool activityControlFlag;
246259
bool neighborhoodCheck;
247260
int N_DS;// Number of template to be downsampled and used in lowResolutionDetection function
248261
CV_PROP_RW int imageWidth;// Width of input image
@@ -257,6 +270,13 @@ class CV_EXPORTS_W MotionSaliencyBinWangApr2014 : public MotionSaliency
257270
// long-term template, regardless of any subsequent background changes. A relatively large (eg gamma=3) will
258271
//restrain the generation of ghosts.
259272

273+
int Ainc;// Activity Incrementation;
274+
int Bmax;// Upper-bound value for pixel activity
275+
int Bth;// Max activity threshold
276+
int Binc, Bdec;// Threshold for pixel-level decision threshold (epslon) adaptation
277+
float deltaINC, deltaDEC;// Increment-decrement value for epslon adaptation
278+
int epslonMIN, epslonMAX;// Range values for epslon threshold
279+
260280
};
261281

262282
/************************************ Specific Objectness Specialized Classes ************************************/
@@ -417,38 +437,38 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
417437
int _Clr;//
418438
static const char* _clrName[3];
419439

420-
// Names and paths to read model and to store results
440+
// Names and paths to read model and to store results
421441
std::string _modelName, _bbResDir, _trainingPath, _resultsDir;
422442

423443
std::vector<int> _svmSzIdxs;// Indexes of active size. It's equal to _svmFilters.size() and _svmReW1f.rows
424444
Mat _svmFilter;// Filters learned at stage I, each is a _H by _W CV_32F matrix
425445
FilterTIG _tigF;// TIG filter
426446
Mat _svmReW1f;// Re-weight parameters learned at stage II.
427447

428-
// List of the rectangles' objectness value, in the same order as
429-
// the vector<Vec4i> objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function)
448+
// List of the rectangles' objectness value, in the same order as
449+
// the vector<Vec4i> objectnessBoundingBox returned by the algorithm (in computeSaliencyImpl function)
430450
std::vector<float> objectnessValues;
431451

432452
private:
433-
// functions
453+
// functions
434454

435455
inline static float LoG( float x, float y, float delta )
436456
{
437457
float d = - ( x * x + y * y ) / ( 2 * delta * delta );
438458
return -1.0f / ( (float) ( CV_PI ) * pow( delta, 4 ) ) * ( 1 + d ) * exp( d );
439459
} // Laplacian of Gaussian
440460

441-
// Read matrix from binary file
461+
// Read matrix from binary file
442462
static bool matRead( const std::string& filename, Mat& M );
443463

444464
void setColorSpace( int clr = MAXBGR );
445465

446-
// Load trained model.
466+
// Load trained model.
447467
int loadTrainedModel( std::string modelName = "" );// Return -1, 0, or 1 if partial, none, or all loaded
448468

449-
// Get potential bounding boxes, each of which is represented by a Vec4i for (minX, minY, maxX, maxY).
450-
// The trained model should be prepared before calling this function: loadTrainedModel() or trainStageI() + trainStageII().
451-
// Use numDet to control the final number of proposed bounding boxes, and number of per size (scale and aspect ratio)
469+
// Get potential bounding boxes, each of which is represented by a Vec4i for (minX, minY, maxX, maxY).
470+
// The trained model should be prepared before calling this function: loadTrainedModel() or trainStageI() + trainStageII().
471+
// Use numDet to control the final number of proposed bounding boxes, and number of per size (scale and aspect ratio)
452472
void getObjBndBoxes( Mat &img3u, ValStructVec<float, Vec4i> &valBoxes, int numDetPerSize = 120 );
453473
void getObjBndBoxesForSingleImage( Mat img, ValStructVec<float, Vec4i> &boxes, int numDetPerSize );
454474

@@ -460,7 +480,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
460480
void predictBBoxSI( Mat &mag3u, ValStructVec<float, Vec4i> &valBoxes, std::vector<int> &sz, int NUM_WIN_PSZ = 100, bool fast = true );
461481
void predictBBoxSII( ValStructVec<float, Vec4i> &valBoxes, const std::vector<int> &sz );
462482

463-
// Calculate the image gradient: center option as in VLFeat
483+
// Calculate the image gradient: center option as in VLFeat
464484
void gradientMag( Mat &imgBGR3u, Mat &mag1u );
465485

466486
static void gradientRGB( Mat &bgr3u, Mat &mag1u );
@@ -479,7 +499,7 @@ class CV_EXPORTS_W ObjectnessBING : public Objectness
479499
return abs( u[0] - v[0] ) + abs( u[1] - v[1] ) + abs( u[2] - v[2] );
480500
}
481501

482-
//Non-maximal suppress
502+
//Non-maximal suppress
483503
static void nonMaxSup( Mat &matchCost1f, ValStructVec<float, Point> &matchCost, int NSS = 1, int maxPoint = 50, bool fast = true );
484504

485505
};

modules/saliency/perf/perf_main.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#include "perf_precomp.hpp"
2+
3+
CV_PERF_TEST_MAIN(saliency)
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*M///////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4+
//
5+
// By downloading, copying, installing or using the software you agree to this license.
6+
// If you do not agree to this license, do not download, install,
7+
// copy or use the software.
8+
//
9+
//
10+
// License Agreement
11+
// For Open Source Computer Vision Library
12+
//
13+
// Copyright (C) 2014, OpenCV Foundation, all rights reserved.
14+
// Third party copyrights are property of their respective owners.
15+
//
16+
// Redistribution and use in source and binary forms, with or without modification,
17+
// are permitted provided that the following conditions are met:
18+
//
19+
// * Redistribution's of source code must retain the above copyright notice,
20+
// this list of conditions and the following disclaimer.
21+
//
22+
// * Redistribution's in binary form must reproduce the above copyright notice,
23+
// this list of conditions and the following disclaimer in the documentation
24+
// and/or other materials provided with the distribution.
25+
//
26+
// * The name of the copyright holders may not be used to endorse or promote products
27+
// derived from this software without specific prior written permission.
28+
//
29+
// This software is provided by the copyright holders and contributors "as is" and
30+
// any express or implied warranties, including, but not limited to, the implied
31+
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32+
// In no event shall the Intel Corporation or contributors be liable for any direct,
33+
// indirect, incidental, special, exemplary, or consequential damages
34+
// (including, but not limited to, procurement of substitute goods or services;
35+
// loss of use, data, or profits; or business interruption) however caused
36+
// and on any theory of liability, whether in contract, strict liability,
37+
// or tort (including negligence or otherwise) arising in any way out of
38+
// the use of this software, even if advised of the possibility of such damage.
39+
//
40+
//M*/
41+
42+
#include "perf_precomp.hpp"
43+
#include <fstream>
44+
#include <opencv2/videoio.hpp>
45+
46+
//write sanity: ./bin/opencv_perf_saliency --perf_write_sanity=true
47+
//verify sanity: ./bin/opencv_perf_saliency
48+
49+
using namespace std;
50+
using namespace cv;
51+
using namespace perf;
52+
53+
#define TESTSET_NAMES \
54+
"/cv/saliency/motion/blizzard.webm",\
55+
"/cv/saliency/motion/pedestrian.webm" ,\
56+
"/cv/saliency/motion/snowFall.webm"
57+
58+
const string SALIENCY_DIR = "cv/saliency";
59+
60+
typedef perf::TestBaseWithParam<std::string> sal;
61+
62+
PERF_TEST_P(sal, motionSaliencyBinWangApr2014, testing::Values(TESTSET_NAMES))
63+
{
64+
string filename = getDataPath(GetParam());
65+
int startFrame=0;
66+
Mat frame;
67+
Mat saliencyMap;
68+
int videoSize=0;
69+
70+
Ptr<saliency::Saliency> saliencyAlgorithm = saliency::Saliency::create( "BinWangApr2014" );
71+
72+
TEST_CYCLE_N(1)
73+
{
74+
VideoCapture c;
75+
c.open( filename);
76+
videoSize=c.get( CAP_PROP_FRAME_COUNT);
77+
c.set( CAP_PROP_POS_FRAMES, startFrame );
78+
79+
for ( int frameCounter = 0; frameCounter < videoSize; frameCounter++ )
80+
{
81+
c >> frame;
82+
83+
if( frame.empty() )
84+
{
85+
break;
86+
}
87+
88+
saliencyAlgorithm.dynamicCast<saliency::MotionSaliencyBinWangApr2014>()->setImagesize( frame.cols, frame.rows );
89+
saliencyAlgorithm.dynamicCast<saliency::MotionSaliencyBinWangApr2014>()->init();
90+
91+
if( saliencyAlgorithm->computeSaliency( frame, saliencyMap ) )
92+
{
93+
94+
}
95+
else
96+
{
97+
FAIL()<< "***Error in the instantiation of the saliency algorithm...***\n" << endl;
98+
return;
99+
}
100+
101+
}
102+
}
103+
104+
SANITY_CHECK(saliencyMap);
105+
106+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*M///////////////////////////////////////////////////////////////////////////////////////
2+
//
3+
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4+
//
5+
// By downloading, copying, installing or using the software you agree to this license.
6+
// If you do not agree to this license, do not download, install,
7+
// copy or use the software.
8+
//
9+
//
10+
// License Agreement
11+
// For Open Source Computer Vision Library
12+
//
13+
// Copyright (C) 2014, OpenCV Foundation, all rights reserved.
14+
// Third party copyrights are property of their respective owners.
15+
//
16+
// Redistribution and use in source and binary forms, with or without modification,
17+
// are permitted provided that the following conditions are met:
18+
//
19+
// * Redistribution's of source code must retain the above copyright notice,
20+
// this list of conditions and the following disclaimer.
21+
//
22+
// * Redistribution's in binary form must reproduce the above copyright notice,
23+
// this list of conditions and the following disclaimer in the documentation
24+
// and/or other materials provided with the distribution.
25+
//
26+
// * The name of the copyright holders may not be used to endorse or promote products
27+
// derived from this software without specific prior written permission.
28+
//
29+
// This software is provided by the copyright holders and contributors "as is" and
30+
// any express or implied warranties, including, but not limited to, the implied
31+
// warranties of merchantability and fitness for a particular purpose are disclaimed.
32+
// In no event shall the Intel Corporation or contributors be liable for any direct,
33+
// indirect, incidental, special, exemplary, or consequential damages
34+
// (including, but not limited to, procurement of substitute goods or services;
35+
// loss of use, data, or profits; or business interruption) however caused
36+
// and on any theory of liability, whether in contract, strict liability,
37+
// or tort (including negligence or otherwise) arising in any way out of
38+
// the use of this software, even if advised of the possibility of such damage.
39+
//
40+
//M*/
41+
42+
#include "perf_precomp.hpp"
43+
44+
//write sanity: ./bin/opencv_perf_saliency --perf_write_sanity=true
45+
//verify sanity: ./bin/opencv_perf_saliency
46+
47+
using namespace std;
48+
using namespace cv;
49+
using namespace perf;
50+
using std::tr1::make_tuple;
51+
using std::tr1::get;
52+
53+
typedef perf::TestBaseWithParam<std::string> sal;
54+
55+
#define BING_IMAGES \
56+
"cv/saliency/objectness/000021.jpg", \
57+
"cv/saliency/objectness/000022.jpg"
58+
59+
void getMatOfRects( const vector<Vec4i>& saliencyMap, Mat& bbs_mat )
60+
{
61+
for ( size_t b = 0; b < saliencyMap.size(); b++ )
62+
{
63+
bbs_mat.at<int>( b, 0 ) = saliencyMap[b].val[0];
64+
bbs_mat.at<int>( b, 1 ) = saliencyMap[b].val[1];
65+
bbs_mat.at<int>( b, 2 ) = saliencyMap[b].val[2];
66+
bbs_mat.at<int>( b, 3 ) = saliencyMap[b].val[3];
67+
}
68+
}
69+
70+
PERF_TEST_P(sal, objectnessBING, testing::Values(BING_IMAGES))
71+
{
72+
string filename = getDataPath(GetParam());
73+
cout<<endl<<endl<<"path "<<filename<<endl<<endl;
74+
Mat image = imread(filename);
75+
vector<Vec4i> saliencyMap;
76+
String training_path = "/home/puja/src/opencv_contrib/modules/saliency/samples/ObjectnessTrainedModel";
77+
78+
if (image.empty())
79+
FAIL() << "Unable to load source image " << filename;
80+
81+
Ptr<saliency::Saliency> saliencyAlgorithm = saliency::Saliency::create( "BING" );
82+
83+
TEST_CYCLE_N(1)
84+
{
85+
if( training_path.empty() )
86+
{
87+
FAIL() << "Path of trained files missing! " << endl;
88+
return;
89+
}
90+
91+
else
92+
{
93+
saliencyAlgorithm.dynamicCast<saliency::ObjectnessBING>()->setTrainingPath( training_path );
94+
saliencyAlgorithm.dynamicCast<saliency::ObjectnessBING>()->setBBResDir( training_path + "/Results" );
95+
96+
if( saliencyAlgorithm->computeSaliency( image, saliencyMap ) )
97+
{
98+
99+
}
100+
}
101+
} //end CYCLE
102+
103+
//save the bounding boxes in a Mat
104+
Mat bbs_mat( saliencyMap.size(), 4, CV_32F );
105+
getMatOfRects( saliencyMap, bbs_mat );
106+
107+
SANITY_CHECK( bbs_mat);
108+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifdef __GNUC__
2+
# pragma GCC diagnostic ignored "-Wmissing-declarations"
3+
# if defined __clang__ || defined __APPLE__
4+
# pragma GCC diagnostic ignored "-Wmissing-prototypes"
5+
# pragma GCC diagnostic ignored "-Wextra"
6+
# endif
7+
#endif
8+
9+
#ifndef __OPENCV_SALIENCY_PRECOMP_HPP__
10+
#define __OPENCV_SALIENCY_PRECOMP_HPP__
11+
12+
#include <opencv2/ts.hpp>
13+
#include <opencv2/imgproc.hpp>
14+
#include <opencv2/saliency.hpp>
15+
#include <opencv2/highgui.hpp>
16+
17+
#ifdef GTEST_CREATE_SHARED_LIBRARY
18+
#error no modules except ts should have GTEST_CREATE_SHARED_LIBRARY defined
19+
#endif
20+
21+
#endif

0 commit comments

Comments
 (0)