Skip to content

Commit

Permalink
Bug fix: generation of binary maps & normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
plebreton committed Feb 27, 2018
1 parent cafd1fe commit ae1d77c
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 20 deletions.
Binary file modified lib/libgbvs/bin/gbvs
Binary file not shown.
Binary file modified lib/libhmd/bin/hmd
Binary file not shown.
Binary file modified lib/liblinper/bin/linper
Binary file not shown.
76 changes: 58 additions & 18 deletions truth/SaliencyBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ SaliencyBuilder::SaliencyBuilder(int rows, int cols, int framerate, float fov) {
m_fixationMaps = false;
m_nbFrames = -1;
m_videoOverlayType = 1;
m_rawOutputMode = 0;
}


Expand Down Expand Up @@ -153,21 +154,29 @@ void SaliencyBuilder::applyLog(const std::vector<Record>& records) {
}

cv::GaussianBlur(gauss, gauss, cv::Size(203,203), 30, 30);
cv::normalize(gauss, gauss, 1, 0, cv::NORM_MINMAX);
cv::normalize(gauss, gauss, 0, 1, cv::NORM_MINMAX);


cv::VideoWriter outputVideo;
cv::VideoCapture inputVideo;
cv::Size S = cv::Size(m_cols, m_rows);
FILE *binFile = NULL;

// --------------------------------------------------------------------------------------------------------
// define output path

std::string outputFile;
std::string extension;

if(m_rawOutputMode > 0)
extension = ".bin";
else
extension = ".mkv";

if(m_mergeHMDs)
outputFile = records[0].m_name + ".mkv";
outputFile = records[0].m_name + extension;
else
outputFile = records[0].m_hmd + "_" + records[0].m_name + ".mkv";
outputFile = records[0].m_hmd + "_" + records[0].m_name + extension;


if(m_skipExisting) {
Expand Down Expand Up @@ -195,11 +204,17 @@ void SaliencyBuilder::applyLog(const std::vector<Record>& records) {
// --------------------------------------------------------------------------------------------------------
// handle output video

if(m_rawOutputMode == 0) {
outputVideo.open(outputFile, CV_FOURCC(m_fourcc[0], m_fourcc[1], m_fourcc[2], m_fourcc[3]), m_framerate, S, !m_videoOverlay.empty()); // !m_videoOverlay.empty() -> if there is no RGB video, we can only use a B&W output

outputVideo.open(outputFile, CV_FOURCC(m_fourcc[0], m_fourcc[1], m_fourcc[2], m_fourcc[3]), m_framerate, S, !m_videoOverlay.empty()); // !m_videoOverlay.empty() -> if there is no RGB video, we can only use a B&W output

if(!outputVideo.isOpened()) {
std::cerr << "Cannot write: " << (records[0].m_name + ".mkv") << std::endl;
if(!outputVideo.isOpened()) {
std::cerr << "Cannot write: " << (records[0].m_name + ".mkv") << std::endl;
}
} else {
binFile = fopen(outputFile.c_str(), "wb");
if(binFile == NULL) {
std::cerr << "Cannot write: " << (records[0].m_name + ".bin") << std::endl;
}
}


Expand Down Expand Up @@ -282,22 +297,23 @@ void SaliencyBuilder::applyLog(const std::vector<Record>& records) {
while(pitch < -90.f) pitch += 180.f;
while(pitch > 90.f) pitch -= 180.f;

pitch = (pitch + 90.f) / 180.f;
int y = static_cast<int>(pitch*salMap.rows);
pitch = pitch / 180.f;
int y = salMap.rows/2 + static_cast<int>(pitch*salMap.rows);
if(y >= salMap.rows) y = salMap.rows - 1;
if(y < 0) y = 0;


float yaw = job.m_yaw;
while(yaw < -180.f) pitch += 360.f;
while(yaw > 180.f) pitch -= 360.f;
yaw = (yaw + 180.f) / 360.f;
while(yaw < -180.f) yaw += 360.f;
while(yaw > 180.f) yaw -= 360.f;
yaw = yaw / 360.f;

int x = static_cast<int>(yaw*salMap.cols);
int x = salMap.cols/2 + static_cast<int>(yaw*salMap.cols);
if(x >= salMap.cols) x = salMap.cols - 1;
if(x < 0) x = 0;

salMap.at<float>(y, x) = 1.0f;

}


Expand All @@ -319,7 +335,7 @@ void SaliencyBuilder::applyLog(const std::vector<Record>& records) {
salMap += job.m_frame;
}

cv::normalize(salMap, salMap, 1, 0, cv::NORM_MINMAX);
cv::normalize(salMap, salMap, 0, 1, cv::NORM_MINMAX);



Expand All @@ -338,7 +354,7 @@ void SaliencyBuilder::applyLog(const std::vector<Record>& records) {
++depth;
}

cv::normalize(salMap, salMap, 1, 0, cv::NORM_MINMAX);
cv::normalize(salMap, salMap, 0, 1, cv::NORM_MINMAX);

}

Expand Down Expand Up @@ -407,8 +423,12 @@ void SaliencyBuilder::applyLog(const std::vector<Record>& records) {
// write output video

if(m_videoOverlay.empty()) {
salMap = salMap * 255;
salMap.convertTo(salMap, CV_8UC1);

if(m_rawOutputMode == 0) {
salMap = salMap * 255;
salMap.convertTo(salMap, CV_8UC1);
}

} else {
if(!inputVideo.isOpened()) {
cv::Mat colorImage(salMap.size(), CV_8UC3);
Expand All @@ -422,11 +442,31 @@ void SaliencyBuilder::applyLog(const std::vector<Record>& records) {
}
}

outputVideo << salMap;
if(m_rawOutputMode == 0) {
outputVideo << salMap;
} else {
switch(m_rawOutputMode) {
case 1:
cv::normalize(salMap, salMap, 0, 1, cv::NORM_MINMAX);
salMap = salMap * 255;
salMap.convertTo(salMap, CV_8UC1);
fwrite(salMap.data, 1, salMap.cols * salMap.rows, binFile);
break;

case 2:
default:
fwrite(salMap.data, sizeof(float), salMap.cols * salMap.rows, binFile);
break;
}
}


if(frame == m_nbFrames) break;
}

if(binFile != NULL) {
fclose(binFile);
}

}

Expand Down
4 changes: 2 additions & 2 deletions truth/SaliencyBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class SaliencyBuilder {
bool m_skipExisting;
bool m_inversePitchAxis;
bool m_fixationMaps;
int m_rawOutputMode;
std::string m_processedVideo;
std::string m_filterHMD;
std::string m_videoOverlay;
Expand Down Expand Up @@ -101,8 +102,7 @@ class SaliencyBuilder {
inline void setProcessedVideo(const std::string& vid) { m_processedVideo = vid; }
inline void setInversePitchAxis(bool value) { m_inversePitchAxis = value; }
inline void setFixationMaps (bool value) { m_fixationMaps = value; }


inline void setRawOutputMode(int mode) { m_rawOutputMode = mode; }

};

Expand Down
6 changes: 6 additions & 0 deletions truth/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ int main(int argc, char **argv) {
("select-video", po::value< std::string >(), "Generate the saliency map only for the requested video.")
("invert-pitch-axis", "Inverse the direction of a positive pitch value.")
("fixation-map", "Generate fixation maps instead (binary maps)")
("raw-output", po::value< int >(), "Write maps in a binary file. Raster scan order. Argument select bit depth (UChar:1, Float:2)")
;


Expand Down Expand Up @@ -174,6 +175,11 @@ int main(int argc, char **argv) {
builder.setFixationMaps(true);
}

if(vm.count("raw-output")) {
builder.setRawOutputMode(vm["raw-output"].as< int >());
}



// ----------------------------------------------------------------------------------------------------------------
// list all the JSON files, and add the files to the saliency map builder
Expand Down

0 comments on commit ae1d77c

Please sign in to comment.