Skip to content

Commit

Permalink
feat(mono/bino SinusShiftGrayCodePattern.cpp): gui support shift Gray…
Browse files Browse the repository at this point in the history
… code pattern.

1. support mono/bino camera to use shift Gray code pattern(include stripes create and restruction method change).
  • Loading branch information
Practice3DVision committed Apr 11, 2024
1 parent 109b678 commit 753967e
Show file tree
Hide file tree
Showing 17 changed files with 464 additions and 17 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ jobs:
set FLANN_INCLUDE_DIR="C:/vcpkg/installed/x64-windows/include/flann"
set FLANN_LIBRARY_SHARED="C:/vcpkg/installed/x64-windows/bin/flann.dll"
set FLANN_LIBRARY_DEBUG_SHARED="C:/vcpkg/installed/x64-windows/bin/flannd.dll"
set FLANN_LIBRARY="C:/vcpkg/installed/x64-windows/lib/flann_cpp.lib"
set FLANN_LIBRARY_DEBUG="C:/vcpkg/installed/x64-windows/lib/flann_cpp-gd.lib"
set BOOST_ROOT="C:/vcpkg/installed/x64-windows"
set Qhull_DIR="C:/vcpkg/installed/x64-windows/share/qhull"
Expand All @@ -117,7 +119,7 @@ jobs:
cd ../pcl-pcl-1.12.1
mkdir build
cd build
cmake .. -DBUILD_visualization:BOOL=ON -DBUILD_TESTS:BOOL=OFF -DBUILD_PERFORMANCE_TESTS:BOOL=OFF -DCMAKE_INSTALL_PREFIX="C:/Program Files" -DWITH_OPENNI:BOOL=OF -DPCL_BUILD_WITH_BOOST_DYNAMIC_LINKING_WIN32=ON -DVTK_DIR="C:\Program Files\VTK\lib\cmake\vtk-9.2" -DEIGEN_INCLUDE_DIR="C:/vcpkg/installed/x64-windows/include/eigen3" -DEIGEN_ROOT="C:/vcpkg/installed/x64-windows/include/eigen3" -Dflann_DIR="C:/vcpkg/installed/x64-windows/share/flann" -DFLANN_INCLUDE_DIR="C:/vcpkg/installed/x64-windows/include/flann" -DFLANN_LIBRARY_SHARED="C:/vcpkg/installed/x64-windows/bin/flann.dll" -DFLANN_LIBRARY_DEBUG_SHARED="C:/vcpkg/installed/x64-windows/bin/flannd.dll" -DBOOST_ROOT="C:/vcpkg/installed/x64-windows" -DQhull_DIR="C:/vcpkg/installed/x64-windows/share/qhull"
cmake .. -DBUILD_visualization:BOOL=ON -DBUILD_TESTS:BOOL=OFF -DBUILD_apps=OFF -DBUILD_global_tests=OFF -DCMAKE_INSTALL_PREFIX="C:/Program Files" -DWITH_OPENNI=OFF -DWITH_OPENNI2=OFF -DPCL_BUILD_WITH_BOOST_DYNAMIC_LINKING_WIN32=ON -DVTK_DIR="C:\Program Files\VTK\lib\cmake\vtk-9.2" -DEIGEN_INCLUDE_DIR="C:/vcpkg/installed/x64-windows/include/eigen3" -DEIGEN_ROOT="C:/vcpkg/installed/x64-windows/include/eigen3" -Dflann_DIR="C:/vcpkg/installed/x64-windows/share/flann" -DFLANN_INCLUDE_DIR="C:/vcpkg/installed/x64-windows/include/flann" -DFLANN_LIBRARY_SHARED="C:/vcpkg/installed/x64-windows/bin/flann.dll" -DFLANN_LIBRARY_DEBUG_SHARED="C:/vcpkg/installed/x64-windows/bin/flannd.dll" -DBOOST_ROOT="C:/vcpkg/installed/x64-windows" -DQhull_DIR="C:/vcpkg/installed/x64-windows/share/qhull" -DFLANN_LIBRARY="C:/vcpkg/installed/x64-windows/lib/flann_cpp.lib" -DFLANN_LIBRARY_DEBUG="C:/vcpkg/installed/x64-windows/lib/flann_cpp-gd.lib"
cmake --build . --config Release
- name: Install PCL
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.20)
project(SLMaster)

set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_BUILD_TYPE Release)
#Release模式必须使用以下属性
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} /O2 /Zi")

Expand Down
3 changes: 3 additions & 0 deletions gui/qml/ui/global/Lang.qml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ QtObject {
property string please_select_start_point
property string please_select_point_to_see_info
property string multi_view_stereo_geometry
property string sine_shift_gray_code
property string find_features_error
property string pure_scan_mode
property string pure_scan_desc
Expand Down Expand Up @@ -305,6 +306,7 @@ QtObject {
camera = "相机";
stripe_type = "条纹类型";
sine_complementary_gray_code = "正弦互补格雷码";
sine_shift_gray_code = "正弦移位格雷码";
encode = "编码";
save = "保存";
defocus_encoding = "离焦编码";
Expand Down Expand Up @@ -567,6 +569,7 @@ QtObject {
camera = "Camera";
stripe_type = "Stripe Type";
sine_complementary_gray_code = "Sine Complementary Gray Code";
sine_shift_gray_code = "Sine Shift Gray Code";
encode = "Encode";
save = "Save";
defocus_encoding = "Defocus Encoding";
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]
model: [Lang.sine_complementary_gray_code, Lang.multi_frequency_heterodyne, Lang.multi_view_stereo_geometry, Lang.sine_shift_gray_code]
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]
model: [Lang.sinus_comple_gray_code, Lang.multi_frequency_heterodyne, Lang.multi_view_stereo_geometry, Lang.sine_shift_gray_code]
currentIndex: root.cur_method

onCurrentIndexChanged: {
Expand Down
1 change: 1 addition & 0 deletions gui/src/AppType.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class AppType : public QObject
SinusCompleGrayCode = 0,
MutiplyFrequency,
MultiViewStereoGeometry,
SinusShiftGrayCode,
};

Q_ENUM(PageType)
Expand Down
76 changes: 67 additions & 9 deletions gui/src/CameraEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,16 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,
params.shiftTime_ = shiftTime;

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

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

pattern = MonoSinusShiftGrayCodePattern::create(params);
}

std::vector<cv::Mat> imgs;
Expand All @@ -100,8 +110,8 @@ int CameraEngine::createStripe(const int pixelDepth, const int direction,
AppType::DefocusEncoding(defocusMethod));
}

if(clipWidth < imgWidth || clipHeight < imgHeight) {
for (auto& img : imgs) {
if (clipWidth < imgWidth || clipHeight < imgHeight) {
for (auto &img : imgs) {
img(cv::Rect(0, 0, clipWidth, clipHeight)).copyTo(img);
}
}
Expand Down Expand Up @@ -610,8 +620,8 @@ void CameraEngine::setPatternType(const int patternType) {
slCamera->getNumbericalAttribute("Exposure Time", exposureTime);
slCamera->getNumbericalAttribute("Pattern", curPattern);

if (patternType == AppType::PatternMethod::SinusCompleGrayCode) {
if (cameraType_ == AppType::CameraType::BinocularSLCamera) {
if (cameraType_ == AppType::CameraType::BinocularSLCamera) {
if (patternType == AppType::PatternMethod::SinusCompleGrayCode) {
BinoSinusCompleGrayCodePattern::Params params;

params.shiftTime_ = std::round(shiftTime);
Expand All @@ -626,7 +636,27 @@ void CameraEngine::setPatternType(const int patternType) {
params.costMinDiff_ = costMinDiff;

pattern_ = BinoSinusCompleGrayCodePattern::create(params);
} else if (cameraType_ == AppType::CameraType::MonocularSLCamera) {
} else if (patternType == AppType::PatternMethod::MutiplyFrequency) {

} else if (patternType == AppType::PatternMethod::SinusShiftGrayCode) {
BinoSinusShiftGrayCodePattern::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_ = BinoSinusShiftGrayCodePattern::create(params);
}
}
if (cameraType_ == AppType::CameraType::MonocularSLCamera) {
if (patternType_ == AppType::PatternMethod::SinusCompleGrayCode) {
MonoSinusCompleGrayCodePattern::Params params;

params.shiftTime_ = std::round(shiftTime);
Expand Down Expand Up @@ -655,9 +685,37 @@ void CameraEngine::setPatternType(const int patternType) {
cv::cv2eigen(PR4, params.PR4_);

pattern_ = MonoSinusCompleGrayCodePattern::create(params);
}
} else if (patternType == AppType::PatternMethod::MutiplyFrequency) {
} else if (patternType == AppType::PatternMethod::SinusShiftGrayCode) {
MonoSinusShiftGrayCodePattern::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_ = MonoSinusShiftGrayCodePattern::create(params);
} else if (patternType == AppType::PatternMethod::MutiplyFrequency) {
}
} else if (patternType == AppType::PatternMethod::MultiViewStereoGeometry) {
TrinocularMultiViewStereoGeometryPattern::Params params;

Expand Down Expand Up @@ -974,11 +1032,11 @@ void CameraEngine::tenLine() {
workThread_ = std::thread(&CameraEngine::createTenLine, this);
}

bool CameraEngine::saveFrame(const QString& path) {
bool CameraEngine::saveFrame(const QString &path) {
auto fileName = path.mid(8, path.size() - 12);

qDebug() << QString("save frame, frame path is : %1").arg(fileName);

cv::imwrite(fileName.toStdString() + ".bmp", frame_.textureMap_);
cv::imwrite(fileName.toStdString() + ".tiff", frame_.depthMap_);

Expand Down
12 changes: 12 additions & 0 deletions perf/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,16 @@ target_link_libraries(
PRIVATE
benchmark::benchmark
slmaster
)

add_executable(
PerfShiftGrayCodePattern
${CMAKE_CURRENT_SOURCE_DIR}/perfShiftGrayCodePattern.cpp
)

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

#include <slmaster.h>

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

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

}
};

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

auto pattern = SinusShiftGrayCodePattern::create(params);

vector<Mat> imgs;

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

BENCHMARK_DEFINE_F(ShiftGrayCodePatternSuit, testUnwrap)(benchmark::State& state) {
auto params = SinusShiftGrayCodePattern::Params();
params.shiftTime = 4;
params.height = 1080;
params.width = 1920;
params.horizontal = false;
params.nbrOfPeriods = 32;

auto pattern = SinusShiftGrayCodePattern::create(params);

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

Mat wrapPhaseMap, floorMap, confidenceMap, unwrapPhaseMap;

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

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

BENCHMARK_MAIN();
2 changes: 1 addition & 1 deletion src/cameras/binosSinusCompleGrayCodePattern.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SLMASTER_API BinoSinusCompleGrayCodePattern : public Pattern {
public:
struct SLMASTER_API Params {
Params()
: width_(1920), height_(1080), shiftTime_(4), cycles_(40),
: width_(1920), height_(1080), shiftTime_(4), cycles_(32),
horizontal_(false), confidenceThreshold_(5.f), minDisparity_(0),
maxDisparity_(300), maxCost_(0.1f), costMinDiff_(0.0001f) {}
int width_;
Expand Down
82 changes: 82 additions & 0 deletions src/cameras/binosSinusShiftGrayCodePattern.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include "binosSinusShiftGrayCodePattern.h"

#include "../algorithm/algorithm.h"

using namespace cv;

namespace slmaster {
namespace cameras {

static BinoSinusShiftGrayCodePattern::Params params__;

BinoSinusShiftGrayCodePattern::BinoSinusShiftGrayCodePattern() {}

bool BinoSinusShiftGrayCodePattern::generate(
std::vector<cv::Mat> &imgs) const {
algorithm::SinusShiftGrayCodePattern::Params params;
params.width = params__.width_;
params.height = params__.height_;
params.nbrOfPeriods = params__.cycles_;
params.horizontal = params__.horizontal_;
params.maxCost = params__.maxCost_;
params.minDisparity = params__.minDisparity_;
params.maxDisparity = params__.maxDisparity_;
params.confidenceThreshold = params__.confidenceThreshold_;
params.shiftTime = params__.shiftTime_;

return algorithm::SinusShiftGrayCodePattern::create(params)
->generate(imgs);
}

std::shared_ptr<Pattern> BinoSinusShiftGrayCodePattern::create(const Params& params) {
params__ = params;

return std::make_shared<BinoSinusShiftGrayCodePattern>();
}

bool BinoSinusShiftGrayCodePattern::decode(
const std::vector<std::vector<cv::Mat>> &patternImages,
cv::Mat &disparityMap, const bool isGpu) const {
CV_Assert(patternImages.size() >= 2);

#ifdef OPENCV_WITH_CUDA_MODULE
if (isGpu) {
/*
algorithm::SinusCompleGrayCodePatternGPU::Params params;
params.shiftTime = params__.shiftTime_;
params.confidenceThreshold = params__.confidenceThreshold_;
params.costMinDiff = params__.costMinDiff_;
params.maxCost = params__.maxCost_;
params.height = params__.height_;
params.width = params__.width_;
params.nbrOfPeriods = params__.cycles_;
params.horizontal = params__.horizontal_;
params.minDisparity = params__.minDisparity_;
params.maxDisparity = params__.maxDisparity_;
auto pattern = algorithm::SinusCompleGrayCodePatternGPU::create(params);
return pattern->decode(patternImages, disparityMap,
algorithm::SINUSOIDAL_COMPLEMENTARY_GRAY_CODE_GPU);
*/
return false;
}
#endif

algorithm::SinusShiftGrayCodePattern::Params params;
params.shiftTime = params__.shiftTime_;
params.width = params__.width_;
params.height = params__.height_;
params.nbrOfPeriods = params__.cycles_;
params.horizontal = params__.horizontal_;
params.maxCost = params__.maxCost_;
params.minDisparity = params__.minDisparity_;
params.maxDisparity = params__.maxDisparity_;
params.confidenceThreshold = params__.confidenceThreshold_;

auto pattern = algorithm::SinusShiftGrayCodePattern::create(params);
return pattern->decode(
patternImages, disparityMap, cv::noArray(), cv::noArray(),
algorithm::SINUSOIDAL_COMPLEMENTARY_GRAY_CODE);
}
} // namespace cameras
} // namespace slmaster
Loading

0 comments on commit 753967e

Please sign in to comment.