Skip to content

Commit 3e0639f

Browse files
committed
Fixes previous mistaken rebase
1 parent 2476dac commit 3e0639f

File tree

4 files changed

+313
-310
lines changed

4 files changed

+313
-310
lines changed

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

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -154,46 +154,45 @@ class CV_EXPORTS_W StaticSaliencyFineGrained : public StaticSaliency
154154
void getIntensity(Mat srcArg, Mat dstArg, Mat dstOnArg, Mat dstOffArg, bool generateOnOff);
155155
};
156156

157-
/** @brief the Deep Gaze 1 Saliency approach from @cite
157+
/** @brief the Deep Gaze 1 Saliency approach from
158158
159159
This method use the convolution layers of the pretrained AlexNet, linear combination, center bias and softmax to generate saliency map
160160
*/
161-
162161
class CV_EXPORTS_W DeepGaze1 : public StaticSaliency
163162
{
164163
private:
165-
dnn::Net net;
166-
std::vector<std::string> layers_names;
167-
std::vector<double> weights;
164+
dnn::Net net;
165+
std::vector<std::string> layers_names;
166+
std::vector<double> weights;
168167

169168
public:
170-
DeepGaze1();
171-
DeepGaze1(std::string, std::string, std::vector<std::string>, unsigned);
172-
virtual ~DeepGaze1();
173-
CV_WRAP static Ptr<DeepGaze1> create()
174-
{
175-
return makePtr<DeepGaze1>();
176-
}
177-
bool computeSaliency(InputArray image, OutputArray saliencyMap)
178-
{
179-
if(image.empty())
180-
return false;
181-
return computeSaliencyImpl(image, saliencyMap);
182-
}
183-
Mat saliencyMapGenerator(Mat, Size = Size(227, 227));
184-
void training(std::vector<Mat>&, std::vector<Mat>&, unsigned = 100, double = 0.9, double = 0.01, double = 0.01, Size = Size(227, 227));
185-
double computeAUC(InputArray _saliencyMap, InputArray _fixtionMap);
186-
void saliencyMapVisualize(InputArray _saliencyMap);
169+
DeepGaze1();
170+
DeepGaze1( std::string, std::string, std::vector<std::string>, unsigned );
171+
virtual ~DeepGaze1();
172+
CV_WRAP static Ptr<DeepGaze1> create()
173+
{
174+
return makePtr<DeepGaze1>();
175+
}
176+
CV_WRAP bool computeSaliency( InputArray image, OutputArray saliencyMap )
177+
{
178+
if( image.empty() )
179+
return false;
180+
return computeSaliencyImpl( image, saliencyMap );
181+
}
182+
Mat saliencyMapGenerator( Mat, Size = Size(227, 227) );
183+
void training( std::vector<Mat>&, std::vector<Mat>&, unsigned = 100, double = 0.9, double = 0.01, double = 0.01, Size = Size(227, 227) );
184+
double computeAUC( InputArray _saliencyMap, InputArray _fixtionMap );
185+
void saliencyMapVisualize( InputArray _saliencyMap );
187186
protected:
188-
bool computeSaliencyImpl(InputArray image, OutputArray saliencyMap);
189-
std::vector<Mat> featureMapGenerator(Mat, Size);
190-
static Mat comb(std::vector<Mat>&, std::vector<double>);
191-
static Mat softmax(Mat);
192-
static std::vector<double> evalGrad(std::vector<Mat>&, std::vector<unsigned>&, std::vector<double>, Size);
193-
std::vector<unsigned> batchIndex(unsigned, unsigned);
194-
static double loss(std::vector<double>, std::vector<double>);
195-
static std::vector<double> mapSampler(Mat, std::vector<unsigned>);
196-
std::vector<unsigned> fixationLoc(Mat, Size);
187+
bool computeSaliencyImpl( InputArray image, OutputArray saliencyMap );
188+
std::vector<Mat> featureMapGenerator( Mat, Size );
189+
static Mat comb( std::vector<Mat>&, std::vector<double> );
190+
static Mat softmax( Mat );
191+
static std::vector<double> evalGrad( std::vector<Mat>&, std::vector<unsigned>&, std::vector<double>, Size );
192+
std::vector<unsigned> batchIndex( unsigned, unsigned );
193+
static double loss( std::vector<double>, std::vector<double> );
194+
static std::vector<double> mapSampler( Mat, std::vector<unsigned> );
195+
std::vector<unsigned> fixationLoc( Mat, Size );
197196
};
198197

199198

modules/saliency/samples/DeepGaze1Sample.cpp

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -8,57 +8,59 @@
88
#include <opencv2/saliency.hpp>
99
#include <vector>
1010
#include <string>
11-
#include <dirent.h>
11+
//#include <dirent.h>
1212
#include <iostream>
1313
#include <fstream>
1414

1515
using namespace std;
1616
using namespace cv;
1717
using namespace cv::dnn;
18+
using namespace cv::saliency;
1819
/* Find best class for the blob (i. e. class with maximal probability) */
1920

20-
int main(int argc, char **argv)
21+
int main()
2122
{
22-
DeepGaze1 g = DeepGaze1();
23-
vector<Mat> images;
24-
vector<Mat> fixs;
23+
DeepGaze1 g = DeepGaze1();
24+
vector<Mat> images;
25+
vector<Mat> fixs;
2526

2627
//Download mit1003 saliency dataset in the working directory
2728
//ALLSTIMULI folder store images
2829
//ALLFIXATIONMAPS foler store training eye fixation
29-
DIR *dp;
30-
struct dirent *dirp;
31-
if((dp = opendir("ALLSTIMULI")) == NULL)
32-
{
33-
cout << "Can not open dataset directory" << endl;
34-
}
35-
unsigned n = 0;
36-
while((dirp = readdir(dp)) != NULL)
37-
{
38-
if(dirp->d_type != 8) continue;
39-
if((n++) >= 400) break;
40-
string f_name(dirp->d_name);
41-
images.push_back(imread("ALLSTIMULI/" + f_name));
42-
fixs.push_back(imread("ALLFIXATIONMAPS/" + f_name.substr(0, f_name.find_first_of('.')) + "_fixPts.jpg", 0));
43-
}
30+
//************ Code only work in linux platform ****
31+
/* DIR *dp;
32+
struct dirent *dirp;
33+
if ( ( dp = opendir( "ALLSTIMULI" ) ) == NULL )
34+
{
35+
cout << "Can not open dataset directory" << endl;
36+
}
37+
unsigned n = 0;
38+
while ( ( dirp = readdir( dp ) ) != NULL )
39+
{
40+
if ( dirp->d_type != 8 ) continue;
41+
if ( (n++) >= 400 ) break;
42+
string f_name( dirp->d_name );
43+
images.push_back( imread( "ALLSTIMULI/" + f_name ) );
44+
fixs.push_back( imread( "ALLFIXATIONMAPS/" + f_name.substr( 0, f_name.find_first_of('.') ) + "_fixPts.jpg", 0 ) );
45+
}
4446
45-
g.training(images, fixs);
46-
ofstream file;
47-
Mat res2;
48-
g.computeSaliency(imread("ALLSTIMULI/i05june05_static_street_boston_p1010764.jpeg"), res2);
49-
log(res2, res2);
50-
resize(res2, res2, Size(1024, 768));
51-
cout << "AUC = " << g.computeAUC(res2, imread("ALLSTIMULI/i05june05_static_street_boston_p1010764_fixPts.jpeg", 0)) << endl;;
52-
g.saliencyMapVisualize(res2);
53-
file.open("saliency.csv");
54-
for (int i = 0;i < res2.rows;i++)
55-
{
56-
for (int j=0;j < res2.cols;j++)
57-
{
58-
file << res2.at<double>(i, j) << " ";
59-
}
60-
file << endl;
61-
}
62-
file.close();
47+
g.training( images, fixs );*/
48+
ofstream file;
49+
Mat res2;
50+
g.computeSaliency( imread( "ALLSTIMULI/i05june05_static_street_boston_p1010764.jpeg"), res2 );
51+
log( res2, res2 );
52+
resize( res2, res2, Size( 1024, 768 ) );
53+
cout << "AUC = " << g.computeAUC( res2, imread( "ALLFIXATIONMAPS/i05june05_static_street_boston_p1010764_fixPts.jpeg", 0 ) ) << endl;;
54+
g.saliencyMapVisualize( res2 );
55+
file.open( "saliency.csv" );
56+
for ( int i = 0; i < res2.rows; i++)
57+
{
58+
for ( int j=0; j < res2.cols; j++)
59+
{
60+
file << res2.at<double>( i, j ) << " ";
61+
}
62+
file << endl;
63+
}
64+
file.close();
6365
return 0;
6466
} //main

0 commit comments

Comments
 (0)