Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
name: Build

on: [push, pull_request]
on:
push:
branches:
- main
pull_request:

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion lib/gpc/Feature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
#include <cmath> //for log2
#include <fstream>
#include <gpc/buffer.hpp>
#include <gpc/filter.hpp>
#include <iostream>
#include <iterator>
#include <gpc/filter.hpp>
#include <random>
#include <set>
#include <string>
Expand Down
56 changes: 26 additions & 30 deletions lib/gpc/SintelOpticalFlow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <Eigen/Dense>
#include <algorithm>
#include <cstring>
#include <filesystem>
#include <iostream>
#include <random>
#include <string>
Expand Down Expand Up @@ -81,6 +82,19 @@ class SintelOpticalFlow {
return false;
}

static std::string makeFramePath(const std::filesystem::path& baseDir,
const std::string& scene,
int idx) {
std::ostringstream os;
os << std::setw(4) << std::setfill('0') << idx;

// <base>/<scene>/frame_XXXX.png
std::filesystem::path p =
baseDir / scene / ("frame_" + os.str() + ".png");

return p.string();
}

public:
SintelOpticalFlow(std::string basePath) {
if (basePath.back() != '/') basePath += "/";
Expand Down Expand Up @@ -173,7 +187,8 @@ class SintelOpticalFlow {
} // scene loop

// Random shuffle the data
std::random_shuffle(trainingData.begin(), trainingData.end());
std::mt19937 rng(12345);
std::shuffle(trainingData.begin(), trainingData.end(), rng);
return trainingData;
}

Expand Down Expand Up @@ -363,15 +378,8 @@ class SintelOpticalFlow {
* @return The bw.
*/
int getBW(int id, ndb::Buffer<uint8_t>& L, ndb::Buffer<uint8_t>& R) {
char buf[16];

sprintf(buf, "%04d", id);
int err1 = L.readPNG(cleanDir + "/" + selectedScene + "/frame_" + buf +
".png");
sprintf(buf, "%04d", id + 1);
int err2 = R.readPNG(cleanDir + "/" + selectedScene + "/frame_" + buf +
".png");

int err1 = L.readPNG(makeFramePath(cleanDir, selectedScene, id));
int err2 = R.readPNG(makeFramePath(cleanDir, selectedScene, id + 1));
return err1 | err2;
}

Expand All @@ -385,14 +393,8 @@ class SintelOpticalFlow {
* @return 0 if success
*/
int getRGB(int id, ndb::Buffer<uint8_t>& L, ndb::Buffer<uint8_t>& R) {
char buf[16];
sprintf(buf, "%04d", id);
int err1 = L.readPNG(cleanDir + "/" + selectedScene + "/frame_" + buf +
".png");
sprintf(buf, "%04d", id + 1);
int err2 = R.readPNG(cleanDir + "/" + selectedScene + "/frame_" + buf +
".png");

int err1 = L.readPNG(makeFramePath(cleanDir, selectedScene, id));
int err2 = R.readPNG(makeFramePath(cleanDir, selectedScene, id + 1));
return err1 | err2;
}

Expand All @@ -406,10 +408,10 @@ class SintelOpticalFlow {
* @return 0 if success
*/
int getFlow(int id, Eigen::MatrixXd& uMat, Eigen::MatrixXd& vMat) {
char tbuf[16];
sprintf(tbuf, "%04d", id);
string filename =
flowDir + "/" + selectedScene + "/frame_" + tbuf + ".flo";
std::ostringstream os;
os << std::setw(4) << std::setfill('0') << id;
std::string filename =
(flowDir + "/" + selectedScene + "/frame_" + os.str() + ".flo");

// Read file into buffer
FILE* readFile = fopen(filename.c_str(), "rb");
Expand Down Expand Up @@ -463,10 +465,7 @@ class SintelOpticalFlow {
* @return 0 if success.
*/
int getOcclusion(int id, ndb::Buffer<uint8_t>& O) {
char buf[16];
sprintf(buf, "%04d", id);
return O.readPNG(oclDir + "/" + selectedScene + "/frame_" + buf +
".png");
return O.readPNG(makeFramePath(oclDir, selectedScene, id));
}
/**
* @brief Gets the invalid pixel map (out of frame)
Expand All @@ -477,10 +476,7 @@ class SintelOpticalFlow {
* @return The invalid.
*/
int getInvalid(int id, ndb::Buffer<uint8_t>& I) {
char buf[16];
sprintf(buf, "%04d", id);
return I.readPNG(invDir + "/" + selectedScene + "/frame_" + buf +
".png");
return I.readPNG(makeFramePath(invDir, selectedScene, id));
}

/**
Expand Down
49 changes: 21 additions & 28 deletions lib/gpc/SintelStereo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ class SintelStereo {
else
return false;
}
static std::string makeFramePath(const std::filesystem::path& baseDir,
const std::string& scene,
int idx) {
std::ostringstream os;
os << std::setw(4) << std::setfill('0') << idx;

// <base>/<scene>/frame_XXXX.png
std::filesystem::path p =
baseDir / scene / ("frame_" + os.str() + ".png");

return p.string();
}

public:
SintelStereo(std::string basePath) {
Expand Down Expand Up @@ -163,7 +175,8 @@ class SintelStereo {
}
} // image loop
} // scene loop
std::random_shuffle(trainingData.begin(), trainingData.end());
std::mt19937 rng(12345);
std::shuffle(trainingData.begin(), trainingData.end(), rng);
return trainingData;
}

Expand Down Expand Up @@ -307,14 +320,8 @@ class SintelStereo {
* @return The bw.
*/
int getBW(int id, ndb::Buffer<uint8_t>& L, ndb::Buffer<uint8_t>& R) {
char buf[16];

sprintf(buf, "%04d", id);
int err1 = L.readPNG(cleanLeftDir + "/" + selectedScene + "/frame_" +
buf + ".png");
int err2 = R.readPNG(cleanRightDir + "/" + selectedScene + "/frame_" +
buf + ".png");

int err1 = L.readPNG(makeFramePath(cleanLeftDir, selectedScene, id));
int err2 = R.readPNG(makeFramePath(cleanRightDir, selectedScene, id));
return err1 | err2;
}

Expand All @@ -328,13 +335,8 @@ class SintelStereo {
* @return The rgb.
*/
int getRGB(int id, ndb::Buffer<uint8_t>& L, ndb::Buffer<uint8_t>& R) {
char buf[16];
sprintf(buf, "%04d", id);
int err1 = L.readPNG(cleanLeftDir + "/" + selectedScene + "/frame_" +
buf + ".png");
int err2 = R.readPNG(cleanRightDir + "/" + selectedScene + "/frame_" +
buf + ".png");

int err1 = L.readPNG(makeFramePath(cleanLeftDir, selectedScene, id));
int err2 = R.readPNG(makeFramePath(cleanRightDir, selectedScene, id));
return err1 | err2;
}

Expand All @@ -347,10 +349,7 @@ class SintelStereo {
* @return 0 if succecss.
*/
int getOcclusion(int id, ndb::Buffer<uint8_t>& O) {
char buf[16];
sprintf(buf, "%04d", id);
return O.readPNG(oclDir + "/" + selectedScene + "/frame_" + buf +
".png");
return O.readPNG(makeFramePath(oclDir, selectedScene, id));
}
/**
* @brief Gets the disparity map
Expand All @@ -361,10 +360,7 @@ class SintelStereo {
* @return 0 if success.
*/
int getDisparity(int id, ndb::RGBBuffer& D) {
char buf[16];
sprintf(buf, "%04d", id);
return D.readPNGRGB(dispDir + "/" + selectedScene + "/frame_" + buf +
".png");
return D.readPNGRGB(makeFramePath(dispDir, selectedScene, id));
}

/**
Expand All @@ -376,10 +372,7 @@ class SintelStereo {
* @return 0 if success
*/
int getInvalid(int id, ndb::Buffer<uint8_t>& I) {
char buf[16];
sprintf(buf, "%04d", id);
return I.readPNG(oofDir + "/" + selectedScene + "/frame_" + buf +
".png");
return I.readPNG(makeFramePath(oofDir, selectedScene, id));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ include(CheckCXXSourceRuns)
project(openGPC CXX)
set (REQ_CPP11_FEATURES cxx_strong_enums cxx_auto_type)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

Expand Down