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

Last change on this file since 69 was 64, checked in by phudelai, 10 years ago

Programme détection d'obstacles amélioré

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