DAVID4 SDK  1.8.7
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
StructuredLightScannerD4Lib.h
1 //=============================================================================
2 // See License in Related Pages
3 //=============================================================================
4 
5 #pragma once
6 
7 #ifndef DAVID_SDK_STRUCTURED_LIGHT_SCANNER_D4LIB_H
8 #define DAVID_SDK_STRUCTURED_LIGHT_SCANNER_D4LIB_H
9 
10 #include "davidSDK/IModules.h"
11 #include "davidSDK/d4lib_helpers.h"
12 #include <map>
13 #include <mutex>
14 
15 namespace david {
16 
17 
18 //=============================================================================
19 // StructuredLightScannerD4Lib
20 //=============================================================================
21 
22 /// Implements interface functions of IStructuredLightScanner using DAVID Low Level Library.
24 {
25 public:
26  /// Extended parameters for result filtering.
28  {
29  float qualityCheck; ///< Quality threshold for 3D data [0,1].
30  bool backgroundRemovalEnabled; ///< Background Removal enabled (true/false).
31  float backgroundRemovalEpsilon; ///< Epsilon for Background Removal.
32  int minContrast; ///< Minimum required contrast (magnitude of amplitude signal). Set to <= 0 in order to use default value (10).
33  float minDepth; ///< Minimum depth value in [mm], as distance from camera's focal point. Has to be >= 0.
34  float maxDepth; ///< Maximum depth value in [mm], as distance from camera's focal point. Has to be > 'minDepth'.
35  float depthThres; ///< Neighbor pixels to a triangle will not be connected, if their difference in depth is larger than this value [mm].
36  double outlierRemoval; ///< Outlier filter [0,1]. 0=off. 1=remove all except the largest scan fragment. e.g. 0.1=remove all fragments that are smaller than 10% of the largest fragment.
37 
38  /// Constructor.
40  };
41 
42  /// Parameters for acquisition.
44  {
45  int minContentChange; ///< Minimum content change for automatic pattern change detection [%].
46  int skipCount; ///< Set the number of images that are skipped after a content change was detected. Default value is 1.
47  double maxWaitTime; ///< Maximum wait time to capture a new image [s].
48 
49  /// Constructor.
51  };
52 
53 public:
54  /// Constructor.
55  /// @param[in,out] shapeFusion Optional pointer to 'Shape Fusion' module. Needed for #AddScanToShapeFusion.
57 
58  // See IStructuredLightScanner
59  virtual ~StructuredLightScannerD4Lib();
60 
61  /// Set StructuredLightScannerD4Lib::ResultFilteringParamsEx
62  /// @param[in] params See StructuredLightScannerD4Lib::ResultFilteringParamsEx.
64 
65  /// Set StructuredLightScannerD4Lib::AcquisitionParams
66  /// @param[in] params See StructuredLightScannerD4Lib::AcquisitionParams.
67  void SetAcquisitionParams(const AcquisitionParams& params);
68 
69  /// Set number of frequencies (affects number of patterns). Optimal setting depends on camera/projector resolution and setup.
70  /// @param[in] frequencies New value for frequencies.
71  void SetFrequencies(int frequencies);
72 
73  // See IStructuredLightScanner
74  virtual void SetScreenID(int screenID);
75 
76  // See IStructuredLightScanner
77  virtual std::vector<std::string> GetAvailableCameraNames();
78 
79  // See IStructuredLightScanner
80  virtual void SelectCamera(const std::string& cameraName, const ImageFormat& imageFormat = ImageFormat());
81 
82  // See IStructuredLightScanner
83  virtual bool CheckCamera();
84 
85  // See IStructuredLightScanner
86  virtual void SetCameraProperty(const std::string& propertyName, double value, enum CamPropsUsage camPropsUsage = CamPropsForAll);
87 
88  // See IStructuredLightScanner
89  virtual double GetCameraProperty(const std::string& propertyName, enum CamPropsUsage camPropsUsage = CamPropsForScanning);
90 
91  // See IStructuredLightScanner
92  virtual std::vector<std::string> GetCameraPropertyNames(bool onlyAvailable);
93 
94  // See IStructuredLightScanner
95  virtual void SelectImageSequence(const std::string& directory);
96 
97  // See IStructuredLightScanner
98  virtual int GetPatternCount();
99 
100  // See IStructuredLightScanner
101  virtual void GetPatternImage(uint8_t* data, int width, int height, PatternPixelFormat pixelFormat, int patternIndex);
102 
103  // See IStructuredLightScanner
104  virtual void SetCapturedImage(const uint8_t* data, int width, int height, CapturedPixelFormat pixelFormat, int patternIndex);
105 
106  // See IStructuredLightScanner
107  virtual void SetTextureImage(const uint8_t* data, int width, int height, PixelFormat pixelFormat);
108 
109  // See IStructuredLightScanner
110  virtual void GetLiveImage(std::vector<uint8_t>& pixelValues, int& width, int& height);
111 
112  // See IStructuredLightScanner
113  virtual void SetCodedLightPhaseShiftMode(const CodedLightPhaseShiftParams& params);
114 
115  // See IStructuredLightScanner
117 
118  // See IStructuredLightScanner
119  virtual void SetResultFiltering(const ResultFilteringParams& params);
120 
121  // See IStructuredLightScanner
123 
124  // See IStructuredLightScanner
125  virtual void ImportCalibration(const std::string& camCalibFilename, const std::string& projectorCalibFilename);
126 
127  // See IStructuredLightScanner
128  virtual void ExportCalibration(const std::string& camCalibFilename, const std::string& projectorCalibFilename);
129 
130  // See IStructuredLightScanner
131  virtual void ChangeCameraCalibrationResolution(int newWidth, int newHeight);
132 
133  // See IStructuredLightScanner
134  virtual std::vector<CalibPoint> Calibrate(double scale);
135 
136  // See IStructuredLightScanner
137  virtual int Scan(bool grabTexture=false, bool setAsBackground=false);
138 
139  // See IStructuredLightScanner
140  virtual void GrabTexture();
141 
142  // See IStructuredLightScanner
143  virtual void AutoWhiteBalance();
144 
145  // See IStructuredLightScanner
146  virtual int AddScanToShapeFusion();
147 
148  // See IStructuredLightScanner
149  virtual void ExportMesh(const std::string& filename);
150 
151  // See IStructuredLightScanner
152  virtual void ExportBackgroundDepthmap(const std::string& filename);
153 
154  // See IStructuredLightScanner
155  virtual void ImportBackgroundDepthmap(const std::string& filename);
156 
157  // See IStructuredLightScanner
158  virtual void GetBackgroundDepthmap(std::vector<float>& depthValues, int &width, int &height);
159 
160  // See IStructuredLightScanner
161  virtual void SetBackgroundDepthmap(const std::vector<float>& depthValues, int width, int height);
162 
163  // See IStructuredLightScanner
164  virtual void SetBackgroundPlanes(const std::vector<Plane>& planes);
165 
166 protected:
167  /// Capture a SLS sequence using the current settings.
168  /// The captured images are stored in 'm_sequence'.
169  void CaptureSequence();
170 
171  /// Capture a texture using the current settings.
172  /// @param[in] applyWhiteBalance Apply white balance to the captured texture image?
173  void CaptureTexture(bool applyWhiteBalance);
174 
175  /// Switch camera properties.
176  /// @param[in] usage Select camera property usage. See #CamPropsUsage.
178 
179  /// Show setup image.
180  void DisplaySetupImage();
181 
182  /// Display chessboard image for validation of calibration.
183  /// @return False, if chessboard image can not be displayed.
184  bool DisplayChessboardImage();
185 
186  /// Is called after successful calibration.
187  /// @param[in] calibPoints Array of calibration points. See #d4calib_CalibPoint.
188  virtual void OnCalibrationDone(const std::vector<d4calib_CalibPoint>& calibPoints);
189 
190 protected:
191  //-------------------------------------------------------------------------
192  // Typedefs
193  //-------------------------------------------------------------------------
194 
195  /// Used mutex.
196  typedef std::recursive_mutex Mutex;
197 
198  /// Guard for automatic unlocking.
199  typedef std::lock_guard<Mutex> Guard;
200 
201  //-------------------------------------------------------------------------
202  // Protected member variables
203  //-------------------------------------------------------------------------
204 
205  Mutex m_mutex; ///< Mutex used for synchronization.
206  std::shared_ptr<d4cam> m_cam; ///< Handle to camera.
207  std::shared_ptr<d4calib> m_camCalib; ///< Handle to camera calibration.
208  std::shared_ptr<d4projector> m_projector; ///< Handle to projector.
209  std::shared_ptr<d4calib> m_projectorCalib; ///< Handle to projector calibration.
210  std::shared_ptr<d4img> m_live; ///< Handle to live image.
211  std::shared_ptr<d4sls> m_sls; ///< Handle to SLS instance.
212  std::shared_ptr<d4fimg> m_background; ///< Handle to background depth image.
213  std::shared_ptr<d4mesh> m_scan; ///< Handle to current scan.
214  std::shared_ptr<d4img> m_texture; ///< Handle to current texture.
215  std::vector<std::shared_ptr<d4img>> m_sequence; ///< Array of handles to captured images.
216  double m_scale; ///< Calibration scale.
217  int m_noiseReduction; ///< Temporal noise reduction.
218  ResultFilteringParamsEx m_resultFilteringParams; ///< Parameters for result filtering.
219  AcquisitionParams m_acqParams; ///< Acquisition parameters.
220  std::map<std::string, double> m_camPropsForScanning; ///< Camera properties for scanning mode.
221  std::map<std::string, double> m_camPropsForTexturing; ///< Camera properties for texturing mode.
222  double m_whiteBalance[3]; ///< White balance correction factors.
223  IShapeFusion* m_shapeFusion; ///< Interface to Shape Fusion module.
224  bool m_externalCapture; ///< Camera images captured by external acquisition?
225 };
226 
227 
228 } // namespace
229 
230 #endif // DAVID_SDK_STRUCTURED_LIGHT_SCANNER_D4LIB_H