source: pacpussensors/trunk/StereoVisionDisparity/DisparityMap.h@ 62

Last change on this file since 62 was 57, checked in by phudelai, 10 years ago

SensorsApplicationStructures.h

File size: 8.8 KB
RevLine 
[50]1/*******************************************************************************
2// created: 2013/06/19 - 18:40
3// filename: DisparityMap.h
4//
5// author: Danilo Alves de Lima and Pierre Hudelaine
6// Copyright Heudiasyc UMR UTC/CNRS 6599
7//
8// version: $Id: $
9//
10// purpose: Disparity map calculation from stereo image data
11//
12*******************************************************************************/
13
14#ifndef DISPARITYMAP_H
15#define DISPARITYMAP_H
16
17#include <fstream>
18#include <qcoreevent.h>
19#include <qthread.h>
20#include <string>
21
22#include "opencv2/objdetect/objdetect.hpp"
23#include "opencv2/highgui/highgui.hpp"
24#include "opencv2/imgproc/imgproc.hpp"
25
26#include "Pacpus/kernel/ComponentBase.h"
27#include "Pacpus/kernel/DbiteFile.h"
28#include "Pacpus/PacpusTools/ShMem.h"
29#include "StereoVisionDisparityExp.h"
[57]30#include "SensorsApplicationStructures.h"
[50]31
32#include <QThread>
33#include <QMutex>
34
35namespace pacpus {
36
37/** Class to provide the disparity map from a stereo pair */
38class STEREOVISIONDISPARITY_API DisparityMap: public QThread,
39 public ComponentBase
40{
[56]41 Q_OBJECT
[50]42public:
43 //============================= DEFAULT ELEMENTS ===============================================
44 DisparityMap(QString name);
45 ~DisparityMap();
46
47 void run();
48
49 virtual void stopActivity(); /*!< to stop the processing thread */
50 virtual void startActivity(); /*!< to start the processing thread */
51 virtual ComponentBase::COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
52 //==============================================================================================
53
54protected:
55
56 // Indicates that thread is running
57 bool is_running;
58
59public:
60
61 //enum { STEREO_BM=0, STEREO_SGBM, STEREO_HH };
62 enum Type{SAD, SGBM, SGBM_HH, SAD_PtG}; // Disparity type
63
64 void InitDefault();
65
[56]66public Q_SLOTS:
67 void setMinimumDisparity(int minimum_disp);
68 void setNumberOfDisparity(int numberOfDisparity);
69 void setSADWindowSize(int SADWindowSize);
70 void setTextureTreshold(int textureTreshold);
71 void setUniquenessRatio(int uniquenessRatio);
72
73Q_SIGNALS:
74 void minimumDisparityChanged(int minDisp);
75 void numberOfDisparityChanged(int numOfDisp);
76 void SADWindowSizeChanged(int SADWinSize);
77 void textureTresholdChanged(int textTresh);
78 void uniquenessRatioChanged(int uniqRatio);
79
[50]80private:
81
82 // Cam settings
83 int cam_width; // Image width
84 int cam_height; // image height
85 int cam_channels; // image channels
86
87 // Image destination settings
88 int destiny_width; // Destiny image width
89 int destiny_height; // Destiny image height
90 int destiny_roi_x; // Destiny image roi x
91 int destiny_roi_y; // Destiny image roi y
92 int destiny_roi_width; // Destiny image roi width
93 int destiny_roi_height; // Destiny image roi height
94 int destiny_channels; // Destiny image channels
95
96 // Processing settings
97 bool use_roi; // If is to use roi
98 Type dispmap_type; // Type of disparity map calculation:
99 // 0 = SAD (Sum of Absolute Differences algorithm)
100 // 1 = SGBM (Semi-Global Block Matching algorithm)
101 // 2 = SGBM+HH (full-scale two-pass dynamic programming algorithm)
102 // 3 = SAD from PtGrey
103 int min_disp; // Minimum disparity value (max-min) must be divisible by 16
104 int num_disp; // Number of disparities (max-min) must be divisible by 16
105
106 //---------------------------------------------- SBM Configuration --------------------------------------------------------------
107 int sbm_preFilterCap; // Truncation value for the prefiltered image pixels.
108 // The algorithm first computes x-derivative at each pixel and clips its
109 // value by [-preFilterCap, preFilterCap] interval. The result values are
110 // passed to the Birchfield-Tomasi pixel cost function.
111 int sbm_preFilterSize;
112 int sbm_SADWindowSize; // Correlation window size, odd value >= 5
113 int sbm_textureThreshold; // Validation threashold for texture variation
114 int sbm_uniquenessRatio; // Margin in percentage by which the best (minimum) computed cost function value should “win”
115 // the second best value to consider the found match correct. Normally, a value within the 5-15
116 // range is good enough.
117 int sbm_speckleWindowSize; // Maximum size of smooth disparity regions to consider their noise speckles and invalidate. Set
118 // it to 0 to disable speckle filtering. Otherwise, set it somewhere in the 50-200 range.
119 int sbm_speckleRange; // Maximum disparity variation within each connected component. If you do speckle filtering, set
120 // the parameter to a positive value, it will be implicitly multiplied by 16. Normally, 1 or 2 is
121 // good enough.
122
123 //---------------------------------------------- SGBM Configuration -------------------------------------------------------------
124 int sgbm_preFilterCap; // Truncation value for the prefiltered image pixels.
125 // The algorithm first computes x-derivative at each pixel and clips its
126 // value by [-preFilterCap, preFilterCap] interval. The result values are
127 // passed to the Birchfield-Tomasi pixel cost function.
128 int sgbm_SADWindowSize; // Correlation window size, odd value >= 3
129 int sgbm_P1; // The first parameter controlling the disparity smoothness.
130 int sgbm_P2; // The second parameter controlling the disparity smoothness. The larger the values are,
131 // the smoother the disparity is. P1 is the penalty on the disparity change by plus or
132 // minus 1 between neighbor pixels. P2 is the penalty on the disparity change by more than
133 // 1 between neighbor pixels. The algorithm requires P2 > P1 .
134 int sgbm_uniquenessRatio; // Margin in percentage by which the best (minimum) computed cost function value should “win”
135 // the second best value to consider the found match correct. Normally, a value within the 5-15
136 // range is good enough.
137 int sgbm_speckleWindowSize; // Maximum size of smooth disparity regions to consider their noise speckles and invalidate. Set
138 // it to 0 to disable speckle filtering. Otherwise, set it somewhere in the 50-200 range.
139 int sgbm_speckleRange; // Maximum disparity variation within each connected component. If you do speckle filtering, set
140 // the parameter to a positive value, it will be implicitly multiplied by 16. Normally, 1 or 2 is
141 // good enough.
142 int sgbm_disp12MaxDiff; // Maximum allowed difference (in integer pixel units) in the left-right disparity check. Set it to
143 // a non-positive value to disable the check.
144
145 //------------------------------------------------------------------------------------------------------------------------------------
146
147 std::string img_source; // Image source
148 std::string img_source_left; // Left image source (if stereovision)
149 std::string img_source_right;// Right image source (if stereovision)
150
151 int mMaxImageInputSize; // Size of the input image data in the memory
152 int mMaxImageOutputSize1; // Size of the output image data in the memory
153 int mMaxImageOutputSize2; // Size of the output image data in the memory
154
155 TimestampedStructImage LeftImage; // Header for the left image
156 TimestampedStructImage RightImage; // Header for the right image
157 TimestampedStructImage RefImage; // Header for the reference image
158 TimestampedStructImage DispImage; // Header for the disp image
159
160 void* left_mem;
161 void* right_mem;
162 void* ref_mem;
163 void* disp_mem;
164 size_t left_mem_size; // Image shared memory position size
165 size_t right_mem_size; // Image shared memory position size
166 size_t ref_mem_size; // Image shared memory position size
167 size_t disp_mem_size; // Image shared memory position size
168
169 // Imput data
170 ShMem * shmem_left; // Shared memory control access to the image data
171 ShMem * shmem_right; // Shared memory control access to the image data
172
173 // Output data
174 ShMem * shmem_ref; // Shared memory control access to the image data
175 ShMem * shmem_disp; // Shared memory control access to the image data
176
177 cv::Mat CurrentLeftFrame; // Image of the left camera
178 cv::Mat CurrentRightFrame; // Image of the right camera
179 cv::Mat CurrentDisparityMap; // DisparityMap
180
181 /* CalcDisparityMap
182 Description:
183 Calculate the Disparity Map of a stereo pair
184 Parameters:
185 Left_img = left image
186 Right_img = right image
187 Disp_map = disparity map
188 type = Method: 0 = SAD (Sum of Absolute Differences algorithm)
189 1 = SGBM (Semi-Global Block Matching algorithm)
190 2 = SGBM+HH (full-scale two-pass dynamic programming algorithm)
191 */
192 void CalcDisparityMap(cv::Mat Left_img, cv::Mat Right_img, cv::Mat &Disp_map, Type type);
193
194
195 // tmp
196 bool recording, THREAD_ALIVE;
197 bool showdebug; // Show frame acquired
198};
199
200}
201#endif // DISPARITYMAP
Note: See TracBrowser for help on using the repository browser.