Skip to content

Commit

Permalink
feat(interzonSinusFourGrayscalePattern.hpp/.cpp/...): new pattern met…
Browse files Browse the repository at this point in the history
…hod.

1. support interzon sinus fourgray scale pattern.(detail see paper @cite)
2. add precise test and perfermance test for pattern.
  • Loading branch information
Practice3DVision committed Apr 14, 2024
1 parent 677de63 commit a0d0447
Show file tree
Hide file tree
Showing 10 changed files with 543 additions and 251 deletions.
12 changes: 12 additions & 0 deletions perf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,16 @@ target_link_libraries(
PRIVATE
benchmark::benchmark
slmaster
)

add_executable(
PerfInterzoneSinusFourGrayscalePattern
${CMAKE_CURRENT_SOURCE_DIR}/perfInterzoneSinusFourGrayscalePattern.cpp
)

target_link_libraries(
PerfInterzoneSinusFourGrayscalePattern
PRIVATE
benchmark::benchmark
slmaster
)
61 changes: 61 additions & 0 deletions perf/perfInterzoneSinusFourGrayscalePattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#include <benchmark/benchmark.h>

#include <slmaster.h>

using namespace slmaster;
using namespace slmaster::algorithm;
using namespace std;
using namespace cv;

class InterzoneSinusFourGrayscalePatternSuit : public benchmark::Fixture {
public:
void SetUp(const benchmark::State &) override {}
};

BENCHMARK_DEFINE_F(InterzoneSinusFourGrayscalePatternSuit, testGenerate)
(benchmark::State &state) {
auto params = InterzoneSinusFourGrayscalePattern::Params();
params.shiftTime = 3;
params.height = 1080;
params.width = 1920;
params.horizontal = false;
params.nbrOfPeriods = 16;

auto pattern = InterzoneSinusFourGrayscalePattern::create(params);

vector<Mat> imgs;

for (auto _ : state) {
pattern->generate(imgs);
}
}

BENCHMARK_DEFINE_F(InterzoneSinusFourGrayscalePatternSuit, testUnwrap)
(benchmark::State &state) {
auto params = InterzoneSinusFourGrayscalePattern::Params();
params.shiftTime = 3;
params.height = 1080;
params.width = 1920;
params.horizontal = false;
params.nbrOfPeriods = 16;

auto pattern = InterzoneSinusFourGrayscalePattern::create(params);

vector<Mat> imgs;
pattern->generate(imgs);

Mat wrappedPhaseMap, floorMap, confidenceMap, unwrapPhaseMap;

for (auto _ : state) {
pattern->computePhaseMap(imgs, wrappedPhaseMap);
pattern->computeConfidenceMap(imgs, confidenceMap);
pattern->computeFloorMap(imgs, confidenceMap, floorMap);
pattern->unwrapPhaseMap(wrappedPhaseMap, confidenceMap, floorMap,
unwrapPhaseMap);
}
}

BENCHMARK_REGISTER_F(InterzoneSinusFourGrayscalePatternSuit, testGenerate)->MeasureProcessCPUTime()->UseRealTime()->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(InterzoneSinusFourGrayscalePatternSuit, testUnwrap)->MeasureProcessCPUTime()->UseRealTime()->Unit(benchmark::TimeUnit::kMillisecond);

BENCHMARK_MAIN();
109 changes: 63 additions & 46 deletions perf/perfLaserLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,82 +12,99 @@ using namespace std;
const string laserLineImgsPath = "../../data/laserLine/";

class LaserLineSuit : public benchmark::Fixture {
protected:
void SetUp(const benchmark::State &) override {
auto background = imread(laserLineImgsPath + "21.bmp", 0);
auto front = imread(laserLineImgsPath + "21-laser.bmp", 0);
mask = front - background;
threshold(mask, mask, 0, 255, THRESH_OTSU);
img = front.clone();

int xBegin = INT_MAX, xEnd = -INT_MAX, yBegin = INT_MAX, yEnd = -INT_MAX;
for (int i = 0; i < background.rows; ++i) {
auto ptrBackground = background.ptr<uchar>(i);
auto ptrFront = front.ptr<uchar>(i);
auto ptrMask = mask.ptr<uchar>(i);

for (int j = 0; j < background.cols; ++j) {
if(ptrMask[j] != 0) {
xBegin = xBegin > j ? j : xBegin;
xEnd = xEnd < j ? j : xEnd;
yBegin = yBegin > i ? i : yBegin;
yEnd = yEnd < i ? i : yEnd;
}
protected:
void SetUp(const benchmark::State &) override {
auto background = imread(laserLineImgsPath + "21.bmp", 0);
auto front = imread(laserLineImgsPath + "21-laser.bmp", 0);
mask = front - background;
threshold(mask, mask, 0, 255, THRESH_OTSU);
img = front.clone();

int xBegin = INT_MAX, xEnd = -INT_MAX, yBegin = INT_MAX,
yEnd = -INT_MAX;
for (int i = 0; i < background.rows; ++i) {
auto ptrBackground = background.ptr<uchar>(i);
auto ptrFront = front.ptr<uchar>(i);
auto ptrMask = mask.ptr<uchar>(i);

for (int j = 0; j < background.cols; ++j) {
if (ptrMask[j] != 0) {
xBegin = xBegin > j ? j : xBegin;
xEnd = xEnd < j ? j : xEnd;
yBegin = yBegin > i ? i : yBegin;
yEnd = yEnd < i ? i : yEnd;
}
}
}

GaussianBlur(img, img, Size(9, 9), 0, 0);
GaussianBlur(img, img, Size(9, 9), 0, 0);

calibrateImgs.emplace_back(imread(laserLineImgsPath + "21.bmp", 0));
calibrateImgs.emplace_back(
imread(laserLineImgsPath + "21-laser.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "22.bmp", 0));
calibrateImgs.emplace_back(
imread(laserLineImgsPath + "22-laser.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "23.bmp", 0));
calibrateImgs.emplace_back(
imread(laserLineImgsPath + "23-laser.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "24.bmp", 0));
calibrateImgs.emplace_back(
imread(laserLineImgsPath + "24-laser.bmp", 0));
}

calibrateImgs.emplace_back(imread(laserLineImgsPath + "21.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "21-laser.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "22.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "22-laser.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "23.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "23-laser.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "24.bmp", 0));
calibrateImgs.emplace_back(imread(laserLineImgsPath + "24-laser.bmp", 0));
}

Mat img;
Mat mask;
vector<Mat> calibrateImgs;
Mat img;
Mat mask;
vector<Mat> calibrateImgs;
};

BENCHMARK_DEFINE_F(LaserLineSuit, testStegerExtract)(benchmark::State& state) {
BENCHMARK_DEFINE_F(LaserLineSuit, testStegerExtract)(benchmark::State &state) {
vector<Point2f> outPoints;

for (auto _ : state) {
stegerExtract(img, outPoints, mask);
}
}

BENCHMARK_DEFINE_F(LaserLineSuit, testCalibration)(benchmark::State& state){
BENCHMARK_DEFINE_F(LaserLineSuit, testCalibration)(benchmark::State &state) {
CaliInfo info(laserLineImgsPath + "caliInfo.yml");

HiddenMethodCalibrator calibrator;
Calibrator* chessCalibrator = new ChessBoardCalibrator();
Calibrator *chessCalibrator = new ChessBoardCalibrator();
calibrator.setCalibrator(chessCalibrator);

for (auto _ : state) {
calibrator.calibration(calibrateImgs, info.info_.M1_, info.info_.D1_, Size(11, 8), 20.f, info.info_.lightPlaneEq_, false);
calibrator.calibration(calibrateImgs, info.info_.M1_, info.info_.D1_,
Size(11, 8), 20.f, info.info_.lightPlaneEq_,
false);
}
}

BENCHMARK_DEFINE_F(LaserLineSuit, testRecoverDepth)(benchmark::State& state){
BENCHMARK_DEFINE_F(LaserLineSuit, testRecoverDepth)(benchmark::State &state) {
CaliInfo info(laserLineImgsPath + "caliInfo.yml");

vector<Point2f> points2D;
stegerExtract(img, points2D, mask);

vector<Point3f> points3D;

for(auto _ : state) {
recoverDepthFromLightPlane(points2D, info.info_.lightPlaneEq_, info.info_.M1_, points3D);
for (auto _ : state) {
recoverDepthFromLightPlane(points2D, info.info_.lightPlaneEq_,
info.info_.M1_, points3D);
}
}

BENCHMARK_REGISTER_F(LaserLineSuit, testStegerExtract)->MeasureProcessCPUTime()->UseRealTime()->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(LaserLineSuit, testCalibration)->MeasureProcessCPUTime()->UseRealTime()->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(LaserLineSuit, testRecoverDepth)->MeasureProcessCPUTime()->UseRealTime()->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(LaserLineSuit, testStegerExtract)
->MeasureProcessCPUTime()
->UseRealTime()
->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(LaserLineSuit, testCalibration)
->MeasureProcessCPUTime()
->UseRealTime()
->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(LaserLineSuit, testRecoverDepth)
->MeasureProcessCPUTime()
->UseRealTime()
->Unit(benchmark::TimeUnit::kMillisecond);

BENCHMARK_MAIN();
22 changes: 14 additions & 8 deletions perf/perfShiftGrayCodePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ using namespace std;
using namespace cv;

class ShiftGrayCodePatternSuit : public benchmark::Fixture {
public:
void SetUp(const benchmark::State &) override{

}
public:
void SetUp(const benchmark::State &) override {}
};

BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testGenerate)(benchmark::State& state) {
BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testGenerate)
(benchmark::State &state) {
auto params = SinusShiftGrayCodePattern::Params();
params.shiftTime = 4;
params.height = 1080;
Expand All @@ -31,7 +30,8 @@ BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testGenerate)(benchmark::State& sta
}
}

BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testUnwrap)(benchmark::State& state) {
BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testUnwrap)
(benchmark::State &state) {
auto params = SinusShiftGrayCodePattern::Params();
params.shiftTime = 4;
params.height = 1080;
Expand All @@ -54,7 +54,13 @@ BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testUnwrap)(benchmark::State& state
}
}

BENCHMARK_REGISTER_F(ShiftGrayCodePatternSuit, testGenerate)->MeasureProcessCPUTime()->UseRealTime()->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(ShiftGrayCodePatternSuit, testUnwrap)->MeasureProcessCPUTime()->UseRealTime()->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(ShiftGrayCodePatternSuit, testGenerate)
->MeasureProcessCPUTime()
->UseRealTime()
->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(ShiftGrayCodePatternSuit, testUnwrap)
->MeasureProcessCPUTime()
->UseRealTime()
->Unit(benchmark::TimeUnit::kMillisecond);

BENCHMARK_MAIN();
Loading

0 comments on commit a0d0447

Please sign in to comment.