Skip to content

Commit

Permalink
feat(threeFrequencyHeterodynePattern.h/.cpp): finish code.
Browse files Browse the repository at this point in the history
1. new feature that support three frequency heterodyne pattern.
2. gui has added this feature.
3. precise test and perfermance test has added.
4. rename binos to bino that word is wrong.
5. new precise test data has added into /data folder.
  • Loading branch information
Practice3DVision committed Apr 17, 2024
1 parent 517971c commit 58e7323
Show file tree
Hide file tree
Showing 52 changed files with 646 additions and 385 deletions.
Binary file added data/threeFrequencyHeterodyne/0.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/1.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/10.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/11.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/2.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/3.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/4.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/5.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/6.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/7.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/8.bmp
Binary file not shown.
Binary file added data/threeFrequencyHeterodyne/9.bmp
Binary file not shown.
6 changes: 3 additions & 3 deletions gui/qml/ui/global/Lang.qml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ QtObject {
property string enable_gpu
property string texture
property string sinus_comple_gray_code
property string multi_frequency_heterodyne
property string three_frequency_heterodyne
property string reserved
property string please_select
property string select_finished
Expand Down Expand Up @@ -407,7 +407,7 @@ QtObject {
enable_gpu = "GPU加速";
texture = "纹理";
sinus_comple_gray_code = "正弦互补格雷码";
multi_frequency_heterodyne = "多频外差";
three_frequency_heterodyne = "三频外差";
reserved = "保留";
please_select = "请通过右键点击屏幕以绘制包围盒!";
select_finished = "包围盒绘制完成!";
Expand Down Expand Up @@ -672,7 +672,7 @@ QtObject {
enable_gpu = "GPU Accelerate";
texture = "Texture";
sinus_comple_gray_code = "Sinusoidal Complementary Gray Code";
multi_frequency_heterodyne = "Multi Frequency Heterodyne";
three_frequency_heterodyne = "Three Frequency Heterodyne";
reserved = "Reserved";
please_select = "Please select end point through right button click to finish draw bounding box!";
select_finished = "Select bounding box finish!";
Expand Down
2 changes: 1 addition & 1 deletion gui/qml/ui/page/Page_Device.qml
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,7 @@ FluContentPage{

FluComboBox {
Layout.fillWidth: true
model: [Lang.sine_complementary_gray_code, Lang.multi_frequency_heterodyne, Lang.multi_view_stereo_geometry, Lang.sine_shift_gray_code, Lang.interzone_sinus_four_grayscale]
model: [Lang.sine_complementary_gray_code, Lang.three_frequency_heterodyne, Lang.multi_view_stereo_geometry, Lang.sine_shift_gray_code, Lang.interzone_sinus_four_grayscale]
currentIndex: root.stripe_type

onCurrentIndexChanged: {
Expand Down
2 changes: 1 addition & 1 deletion gui/qml/ui/page/Page_Scan.qml
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ FluContentPage {

FluComboBox {
Layout.fillWidth: true
model: [Lang.sinus_comple_gray_code, Lang.multi_frequency_heterodyne, Lang.multi_view_stereo_geometry, Lang.sine_shift_gray_code, Lang.interzone_sinus_four_grayscale]
model: [Lang.sinus_comple_gray_code, Lang.three_frequency_heterodyne, Lang.multi_view_stereo_geometry, Lang.sine_shift_gray_code, Lang.interzone_sinus_four_grayscale]
currentIndex: root.cur_method

onCurrentIndexChanged: {
Expand Down
2 changes: 1 addition & 1 deletion gui/src/AppType.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AppType : public QObject

enum PatternMethod {
SinusCompleGrayCode = 0,
MutiplyFrequency,
ThreeFrequencyHeterodyne,
MultiViewStereoGeometry,
SinusShiftGrayCode,
InterzoneSinusFourGrayscale,
Expand Down
3 changes: 1 addition & 2 deletions gui/src/CalibrateEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,8 +712,7 @@ bool CalibrateEngine::captureOnce() {
pattern->computePhaseMap(imgs, wrappedPhaseMap);
pattern->computeFloorMap(imgs, confidenceMap, wrappedPhaseMap,
floorMap);
pattern->unwrapPhaseMap(wrappedPhaseMap, floorMap, unwrapMap,
confidenceMap > params.confidenceThreshold);
pattern->unwrapPhaseMap(wrappedPhaseMap, floorMap, confidenceMap, unwrapMap);

cv::normalize(unwrapMap, normalizeUnwrapMap, 0, 255, cv::NORM_MINMAX);

Expand Down
94 changes: 81 additions & 13 deletions gui/src/CameraEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,
const bool isKeepAdd) {
qInfo() << "start create stripe...";

int sinusImgsCount = 0;
std::shared_ptr<Pattern> pattern;

if (stripeType == AppType::PatternMethod::SinusCompleGrayCode) {
BinoSinusCompleGrayCodePattern::Params params;

Expand All @@ -79,7 +81,21 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,
params.horizontal_ = direction == AppType::Direction::Horizion;
params.shiftTime_ = shiftTime;

sinusImgsCount = params.shiftTime_;

pattern = BinoSinusCompleGrayCodePattern::create(params);
} else if (stripeType == AppType::PatternMethod::ThreeFrequencyHeterodyne) {
MonoThreeFrequencyHeterodynePattern::Params params;

params.height_ = imgHeight;
params.width_ = imgWidth;
params.cycles_ = cycles;
params.horizontal_ = direction == AppType::Direction::Horizion;
params.shiftTime_ = shiftTime;

sinusImgsCount = params.shiftTime_ * 3;

pattern = MonoThreeFrequencyHeterodynePattern::create(params);
} else if (stripeType == AppType::PatternMethod::MultiViewStereoGeometry) {
TrinocularMultiViewStereoGeometryPattern::Params params;

Expand All @@ -89,6 +105,8 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,
params.horizontal_ = direction == AppType::Direction::Horizion;
params.shiftTime_ = shiftTime;

sinusImgsCount = params.shiftTime_;

pattern = TrinocularMultiViewStereoGeometryPattern::create(params);
} else if (stripeType == AppType::PatternMethod::SinusShiftGrayCode) {
MonoSinusShiftGrayCodePattern::Params params;
Expand All @@ -99,8 +117,11 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,
params.horizontal_ = direction == AppType::Direction::Horizion;
params.shiftTime_ = shiftTime;

sinusImgsCount = params.shiftTime_;

pattern = MonoSinusShiftGrayCodePattern::create(params);
} else if (stripeType == AppType::PatternMethod::InterzoneSinusFourGrayscale) {
} else if (stripeType ==
AppType::PatternMethod::InterzoneSinusFourGrayscale) {
MonoInterzoneSinusFourGrayscalePattern::Params params;

params.height_ = imgHeight;
Expand All @@ -109,14 +130,16 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,
params.horizontal_ = direction == AppType::Direction::Horizion;
params.shiftTime_ = shiftTime;

sinusImgsCount = params.shiftTime_;

pattern = MonoInterzoneSinusFourGrayscalePattern::create(params);
}

std::vector<cv::Mat> imgs;
pattern->generate(imgs);

if (defocusMethod != AppType::DefocusEncoding::Disable) {
defocusStripeCreate(imgs, direction, cycles, shiftTime,
defocusStripeCreate(imgs, direction, cycles, sinusImgsCount, shiftTime,
AppType::DefocusEncoding(defocusMethod));
}

Expand Down Expand Up @@ -166,13 +189,14 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,

void CameraEngine::defocusStripeCreate(std::vector<cv::Mat> &imgs,
const int direction, const int cycles,
const int sinusImgsCount,
const int shiftTime,
AppType::DefocusEncoding method) {
Q_ASSERT(!imgs.empty());

// TODO@Evans Liu: 使用浮点数相移图案会更精确点
for (int i = 0; i < imgs.size(); ++i) {
if (i < shiftTime) {
if (i < sinusImgsCount) {
if (method == AppType::DefocusEncoding::ErrorDiffusionMethod) {
twoDimensionErrorExpand(imgs[i]);
} else if (method == AppType::DefocusEncoding::Binary) {
Expand All @@ -184,9 +208,11 @@ void CameraEngine::defocusStripeCreate(std::vector<cv::Mat> &imgs,
opwm(imgs[i], cycles, shiftVal,
direction == AppType::Direction::Horizion);
}
} else {
binary(imgs[i]);
}

continue;
}

binary(imgs[i]);
}
}

Expand Down Expand Up @@ -646,8 +672,22 @@ void CameraEngine::setPatternType(const int patternType) {
params.costMinDiff_ = costMinDiff;

pattern_ = BinoSinusCompleGrayCodePattern::create(params);
} else if (patternType == AppType::PatternMethod::MutiplyFrequency) {
} else if (patternType ==
AppType::PatternMethod::ThreeFrequencyHeterodyne) {
BinoThreeFrequencyHeterodynePattern::Params params;

params.shiftTime_ = std::round(shiftTime);
params.cycles_ = std::round(cycles);
params.horizontal_ = !isVertical;
params.width_ = std::stoi(dlpWidth);
params.height_ = std::stoi(dlpHeight);
params.confidenceThreshold_ = confidenceThreshold;
params.maxCost_ = maxCost;
params.minDisparity_ = minDisp;
params.maxDisparity_ = maxDisp;
params.costMinDiff_ = costMinDiff;

pattern_ = BinoThreeFrequencyHeterodynePattern::create(params);
} else if (patternType == AppType::PatternMethod::SinusShiftGrayCode) {
BinoSinusShiftGrayCodePattern::Params params;

Expand All @@ -663,8 +703,8 @@ void CameraEngine::setPatternType(const int patternType) {
params.costMinDiff_ = costMinDiff;

pattern_ = BinoSinusShiftGrayCodePattern::create(params);
}
else if(patternType_ == AppType::PatternMethod::InterzoneSinusFourGrayscale) {
} else if (patternType_ ==
AppType::PatternMethod::InterzoneSinusFourGrayscale) {
BinoInterzoneSinusFourGrayscalePattern::Params params;

params.shiftTime_ = std::round(shiftTime);
Expand Down Expand Up @@ -740,10 +780,38 @@ void CameraEngine::setPatternType(const int patternType) {
cv::cv2eigen(PR4, params.PR4_);

pattern_ = MonoSinusShiftGrayCodePattern::create(params);
}
else if (patternType == AppType::PatternMethod::MutiplyFrequency) {
}
else if(patternType_ == AppType::PatternMethod::InterzoneSinusFourGrayscale) {
} else if (patternType ==
AppType::PatternMethod::ThreeFrequencyHeterodyne) {
MonoThreeFrequencyHeterodynePattern::Params params;

params.shiftTime_ = std::round(shiftTime);
params.cycles_ = std::round(cycles);
params.horizontal_ = !isVertical;
params.width_ = std::stoi(dlpWidth);
params.height_ = std::stoi(dlpHeight);
params.confidenceThreshold_ = confidenceThreshold;
params.minDepth_ = minDepth;
params.maxDepth_ = maxDepth;

cv::Mat PL1 = cv::Mat::eye(4, 4, CV_32FC1);
slCamera->getCaliInfo()->info_.M1_.copyTo(
PL1(cv::Rect(0, 0, 3, 3)));
cv::cv2eigen(PL1, params.PL1_);

cv::Mat PR4 = cv::Mat::eye(4, 4, CV_32FC1);
slCamera->getCaliInfo()->info_.Rlp_.copyTo(
PR4(cv::Rect(0, 0, 3, 3)));
slCamera->getCaliInfo()->info_.Tlp_.copyTo(
PR4(cv::Rect(3, 0, 1, 3)));
cv::Mat M4Normal = cv::Mat::eye(4, 4, CV_32FC1);
slCamera->getCaliInfo()->info_.M4_.copyTo(
M4Normal(cv::Rect(0, 0, 3, 3)));
PR4 = M4Normal * PR4;
cv::cv2eigen(PR4, params.PR4_);

pattern_ = MonoThreeFrequencyHeterodynePattern::create(params);
} else if (patternType_ ==
AppType::PatternMethod::InterzoneSinusFourGrayscale) {
MonoInterzoneSinusFourGrayscalePattern::Params params;

params.shiftTime_ = std::round(shiftTime);
Expand Down
2 changes: 1 addition & 1 deletion gui/src/CameraEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ class CameraEngine : public QObject {
CameraEngine(const CameraEngine &) = delete;
const CameraEngine &operator=(const CameraEngine &) = delete;
void defocusStripeCreate(std::vector<cv::Mat> &imgs, const int direction,
const int cycles, const int shiftTime,
const int cycles, const int sinusImgsCount, const int shiftTime,
AppType::DefocusEncoding method);
void realTimeRenderImg(const QImage &img);
void createTenLine();
Expand Down
12 changes: 12 additions & 0 deletions perf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,16 @@ target_link_libraries(
PRIVATE
benchmark::benchmark
slmaster
)

add_executable(
PerfThreeFrequencyHeterodynePattern
${CMAKE_CURRENT_SOURCE_DIR}/perfThreeFrequencyHeterodynePattern.cpp
)

target_link_libraries(
PerfThreeFrequencyHeterodynePattern
PRIVATE
benchmark::benchmark
slmaster
)
4 changes: 2 additions & 2 deletions perf/perfInterzoneSinusFourGrayscalePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BENCHMARK_DEFINE_F(InterzoneSinusFourGrayscalePatternSuit, testGenerate)
}
}

BENCHMARK_DEFINE_F(InterzoneSinusFourGrayscalePatternSuit, testUnwrap)
BENCHMARK_DEFINE_F(InterzoneSinusFourGrayscalePatternSuit, testGenerateUnwrap)
(benchmark::State &state) {
auto params = InterzoneSinusFourGrayscalePattern::Params();
params.shiftTime = 3;
Expand All @@ -56,6 +56,6 @@ BENCHMARK_DEFINE_F(InterzoneSinusFourGrayscalePatternSuit, testUnwrap)
}

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

BENCHMARK_MAIN();
6 changes: 3 additions & 3 deletions perf/perfShiftGrayCodePattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testGenerate)
}
}

BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testUnwrap)
BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testGenerateUnwrap)
(benchmark::State &state) {
auto params = SinusShiftGrayCodePattern::Params();
params.shiftTime = 4;
Expand All @@ -50,15 +50,15 @@ BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testUnwrap)
pattern->computePhaseMap(imgs, wrapPhaseMap);
pattern->computeConfidenceMap(imgs, confidenceMap);
pattern->computeFloorMap(imgs, confidenceMap, wrapPhaseMap, floorMap);
pattern->unwrapPhaseMap(wrapPhaseMap, floorMap, unwrapPhaseMap);
pattern->unwrapPhaseMap(wrapPhaseMap, floorMap, confidenceMap, unwrapPhaseMap);
}
}

BENCHMARK_REGISTER_F(ShiftGrayCodePatternSuit, testGenerate)
->MeasureProcessCPUTime()
->UseRealTime()
->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(ShiftGrayCodePatternSuit, testUnwrap)
BENCHMARK_REGISTER_F(ShiftGrayCodePatternSuit, testGenerateUnwrap)
->MeasureProcessCPUTime()
->UseRealTime()
->Unit(benchmark::TimeUnit::kMillisecond);
Expand Down
75 changes: 75 additions & 0 deletions perf/perfThreeFrequencyHeterodynePattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <benchmark/benchmark.h>

#include <slmaster.h>

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

const string imgsPath = "../../data/threeFrequencyHeterodyne/";

class ThreeFrequencyHeterodynePatternSuit : public benchmark::Fixture {
public:
void SetUp(const benchmark::State &) {
for (int i = 0; i < 12; ++i) {
Mat temp = imread(imgsPath + to_string(i) + ".bmp", 0);
imgs.emplace_back(temp);
}
}

vector<Mat> imgs;
};

BENCHMARK_DEFINE_F(ThreeFrequencyHeterodynePatternSuit, testGenerate)(benchmark::State& state) {
auto params = ThreeFrequencyHeterodynePattern::Params();
params.shiftTime = 4;
params.height = 1080;
params.width = 1920;
params.horizontal = false;
params.nbrOfPeriods = 64;

auto pattern = ThreeFrequencyHeterodynePattern::create(params);

vector<Mat> imgs;

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

BENCHMARK_DEFINE_F(ThreeFrequencyHeterodynePatternSuit, testGenerateUnwrap)(benchmark::State& state) {
auto params = ThreeFrequencyHeterodynePattern::Params();
params.shiftTime = 4;
params.height = 1080;
params.width = 1920;
params.horizontal = false;
params.nbrOfPeriods = 70;

auto pattern = ThreeFrequencyHeterodynePattern::create(params);

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


for (auto _ : state) {
vector<Mat> wrappedPhaseMaps;
Mat floorMap, confidenceMap, unwrapPhaseMap;
pattern->computePhaseMap(imgs, wrappedPhaseMaps);
pattern->computeConfidenceMap(imgs, confidenceMap);
pattern->computeFloorMap(wrappedPhaseMaps, confidenceMap, floorMap);
pattern->unwrapPhaseMap(wrappedPhaseMaps[0], floorMap, confidenceMap,
unwrapPhaseMap);
}
}

BENCHMARK_REGISTER_F(ThreeFrequencyHeterodynePatternSuit, testGenerate)
->MeasureProcessCPUTime()
->UseRealTime()
->Unit(benchmark::TimeUnit::kMillisecond);
BENCHMARK_REGISTER_F(ThreeFrequencyHeterodynePatternSuit, testGenerateUnwrap)
->MeasureProcessCPUTime()
->UseRealTime()
->Unit(benchmark::TimeUnit::kMillisecond);

BENCHMARK_MAIN();
Loading

0 comments on commit 58e7323

Please sign in to comment.