-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Add new algorithm to the structured light module #2656
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 4.x
Are you sure you want to change the base?
Changes from all commits
96b5571
6e30e2a
d0f46b3
c83583f
53a0e56
39fb210
7e53719
b1a2bf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
set(the_description "Structured Light API") | ||
ocv_define_module(structured_light opencv_core opencv_imgproc opencv_calib3d opencv_phase_unwrapping OPTIONAL opencv_viz WRAP python java objc) | ||
|
||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?xml version="1.0"?> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Perhaps should go into modules/structured_light/samples/data instead. |
||
<opencv_storage> | ||
<img_shape type_id="opencv-matrix"> | ||
<rows>2</rows> | ||
<cols>1</cols> | ||
<dt>d</dt> | ||
<data> | ||
720. 1280.</data></img_shape> | ||
<rms>8.9865323037520906e+00</rms> | ||
<cam_int type_id="opencv-matrix"> | ||
<rows>3</rows> | ||
<cols>3</cols> | ||
<dt>d</dt> | ||
<data> | ||
2.2902176176240550e+03 0. 4.7760365772945374e+02 0. | ||
2.0789910149720636e+03 5.9663906901935786e+02 0. 0. 1.</data></cam_int> | ||
<cam_dist type_id="opencv-matrix"> | ||
<rows>1</rows> | ||
<cols>5</cols> | ||
<dt>d</dt> | ||
<data> | ||
2.2272502988720682e+00 6.2041480268790341e+00 5.1365359803581978e-01 | ||
-1.1065215615966861e-01 -4.8897144273472620e+01</data></cam_dist> | ||
<proj_int type_id="opencv-matrix"> | ||
<rows>3</rows> | ||
<cols>3</cols> | ||
<dt>d</dt> | ||
<data> | ||
1.4173607712558548e+03 0. 5.1752307732265035e+02 0. | ||
1.3963061950617591e+03 7.1503556186206947e+02 0. 0. 1.</data></proj_int> | ||
<proj_dist type_id="opencv-matrix"> | ||
<rows>1</rows> | ||
<cols>5</cols> | ||
<dt>d</dt> | ||
<data> | ||
1.4490791728765842e-01 -7.4856581249561327e-01 | ||
-9.0651830613910390e-03 -3.4131371258920178e-02 | ||
1.3733497765243312e+00</data></proj_dist> | ||
<roration type_id="opencv-matrix"> | ||
<rows>3</rows> | ||
<cols>3</cols> | ||
<dt>d</dt> | ||
<data> | ||
9.9215888102252536e-01 -9.4771920438436966e-03 | ||
1.2462318259093863e-01 1.0446695919745458e-02 9.9992002393776458e-01 | ||
-7.1282727683994072e-03 -1.2454565970956474e-01 | ||
8.3742796265969446e-03 9.9217853740556439e-01</data></roration> | ||
<translation type_id="opencv-matrix"> | ||
<rows>3</rows> | ||
<cols>1</cols> | ||
<dt>d</dt> | ||
<data> | ||
-3.5484301147652934e+02 2.2059644511693236e+02 | ||
-1.3115183374509279e+03</data></translation> | ||
</opencv_storage> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
|
||
|
||
#ifndef OPENCV_structured_light_HPP | ||
#define OPENCV_structured_light_HPP | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. capital letters |
||
|
||
#include <opencv2/core.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
namespace cv{ | ||
namespace structured_light{ | ||
class CV_EXPORTS StructuredLightMono : public virtual Algorithm | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Do we really need this here? |
||
{ | ||
public: | ||
|
||
StructuredLightMono(Size img_size, int patterns, int stripes_number, std::string algs_type) | ||
{ | ||
projector_size = img_size; | ||
pattern_num = patterns; | ||
alg_type = algs_type; | ||
stripes_num = stripes_number; | ||
} | ||
|
||
//generate patterns for projecting | ||
void generatePatterns(OutputArrayOfArrays patterns, float stripes_angle); | ||
|
||
//project patterns and capture with camera | ||
//CV_WRAP | ||
// void captureImages(InputArrayOfArrays patterns, OutputArrayOfArrays refs, OutputArrayOfArrays imgs, bool isCaptureRefs = true); | ||
|
||
//main phase unwrapping algorithm | ||
void unwrapPhase(InputOutputArrayOfArrays refs, InputOutputArrayOfArrays imgs, OutputArray out); | ||
|
||
//read references and phases from file | ||
//CV_WRAP | ||
// void readImages(std::vector<std::string> refs_files, std::vector<std::string> imgs_files, OutputArrayOfArrays refs, OutputArrayOfArrays imgs); | ||
|
||
private: | ||
|
||
//size of the image for whole algorithm | ||
Size projector_size; | ||
|
||
//number of pattern used in SL algorithm starting from 3 | ||
int pattern_num; | ||
|
||
//number of stripes in the image pattern | ||
int stripes_num; | ||
|
||
//PCG or TPU | ||
std::string alg_type; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
enum? |
||
|
||
//remove shadows from images | ||
void removeShadows(InputOutputArrayOfArrays refs, InputOutputArrayOfArrays imgs); | ||
|
||
//phase unwrapping with PCG algorithm based on DCT | ||
void computePhasePCG(InputOutputArrayOfArrays refs, InputOutputArrayOfArrays imgs, OutputArray out); | ||
|
||
//standart temporal unwrap algorithm | ||
void computePhaseTPU(InputOutputArrayOfArrays refs, InputOutputArrayOfArrays imgs, OutputArray out); | ||
}; | ||
|
||
}} // cv::structured_light:: | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
|
||
#ifndef OPENCV_structured_light_mono_calibration_HPP | ||
#define OPENCV_structured_light_mono_calibration_HPP | ||
|
||
#include <opencv2/core.hpp> | ||
//#include <opencv2/highgui/highgui.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
#include "opencv2/core/utility.hpp" | ||
#include <opencv2/calib3d.hpp> | ||
|
||
using namespace std; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
namespace cv{ | ||
namespace structured_light{ | ||
|
||
enum calibrationPattern{CHESSBOARD, CIRCLES_GRID, ASYMETRIC_CIRCLES_GRID}; | ||
|
||
struct Settings | ||
{ | ||
Settings(); | ||
int patternType; | ||
Size patternSize; | ||
Size subpixelSize; | ||
Size imageSize; | ||
float squareSize; | ||
int nbrOfFrames; | ||
}; | ||
|
||
void loadSettings(String path, Settings &sttngs); | ||
|
||
void createObjectPoints( InputArrayOfArrays patternCorners, Size patternSize, float squareSize, int patternType ); | ||
|
||
void createProjectorObjectPoints(InputArrayOfArrays patternCorners, Size patternSize, float squareSize, int patternType ); | ||
|
||
double calibrate(InputArrayOfArrays objPoints, InputArrayOfArrays imgPoints, InputOutputArray cameraMatrix, InputOutputArray distCoeffs, OutputArrayOfArrays r, OutputArrayOfArrays t, Size imgSize ); | ||
|
||
void fromCamToWorld(InputArray cameraMatrix, InputArrayOfArrays rV, InputArrayOfArrays tV, InputArrayOfArrays imgPoints, OutputArrayOfArrays worldPoints ); | ||
|
||
void saveCalibrationResults( String path, InputArray camK, InputArray camDistCoeffs, InputArray projK, InputArray projDistCoeffs, InputArray fundamental); | ||
|
||
void saveCalibrationData( String path, InputArrayOfArrays T1, InputArrayOfArrays T2,InputArrayOfArrays ptsProjCam, InputArrayOfArrays ptsProjProj, InputArrayOfArrays ptsProjCamN, InputArrayOfArrays ptsProjProjN); | ||
|
||
void normalize(InputArray pts, const int& dim, InputOutputArray normpts, OutputArray T); | ||
|
||
void fromVectorToMat(InputArrayOfArrays v, OutputArray pts); | ||
|
||
void fromMatToVector(InputArray pts, OutputArrayOfArrays v); | ||
|
||
void loadCalibrationData(string filename, OutputArray cameraIntrinsic, OutputArray projectorIntrinsic, OutputArray cameraDistortion, OutputArray projectorDistortion, OutputArray rotation, OutputArray translation); | ||
|
||
void distortImage(InputArray input, InputArray camMat, InputArray dist, OutputArray output); | ||
|
||
} | ||
} | ||
|
||
#endif |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// This file is part of OpenCV project. | ||
// It is subject to the license terms in the LICENSE file found in the top-level directory | ||
// of this distribution and at http://opencv.org/license.html. | ||
|
||
#ifndef OPENCV_structured_light_mono_utils_HPP | ||
#define OPENCV_structured_light_mono_utils_HPP | ||
|
||
#include <opencv2/core.hpp> | ||
#include <opencv2/imgproc.hpp> | ||
|
||
using namespace std; | ||
|
||
namespace cv{ | ||
namespace structured_light{ | ||
|
||
//compute atan2 for object and reference images | ||
void computeAtanDiff(InputOutputArrayOfArrays src, OutputArray dst); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid indentation in namespaces. |
||
|
||
/** | ||
Phase unwrapping algorithm based on PCG. | ||
**/ | ||
void unwrapPCG(InputArray img, OutputArray out, Size imgSize); | ||
|
||
/** | ||
Phase unwrapping algorithm based on TPU. | ||
**/ | ||
void unwrapTPU(InputArray phase1, InputArray phase2, OutputArray out, int scale); | ||
|
||
void lowPassFilter(InputArray img, OutputArray out, int filterSize = 30); | ||
void highPassFilter(InputArray img, OutputArray out, int filterSize = 30); | ||
|
||
void calibrateCameraProjector(); | ||
void distortPatterns(); | ||
void undistortPatterns(); | ||
|
||
void savePointCloud(InputArray phase, string filename); //filter image from outliers and save as txt | ||
|
||
} | ||
} | ||
|
||
#endif |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary changes from PR