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

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

Flea3Component: Shared memory changed for stereovision
StereoVisionDisparity: Added for the PFE of Pierre

File size: 8.3 KB
Line 
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"
30#include "../SensorsApplication/SensorsApplicationStructures.h"
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{
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
65private:
66
67 // Cam settings
68 int cam_width; // Image width
69 int cam_height; // image height
70 int cam_channels; // image channels
71
72 // Image destination settings
73 int destiny_width; // Destiny image width
74 int destiny_height; // Destiny image height
75 int destiny_roi_x; // Destiny image roi x
76 int destiny_roi_y; // Destiny image roi y
77 int destiny_roi_width; // Destiny image roi width
78 int destiny_roi_height; // Destiny image roi height
79 int destiny_channels; // Destiny image channels
80
81 // Processing settings
82 bool use_roi; // If is to use roi
83 Type dispmap_type; // Type of disparity map calculation:
84 // 0 = SAD (Sum of Absolute Differences algorithm)
85 // 1 = SGBM (Semi-Global Block Matching algorithm)
86 // 2 = SGBM+HH (full-scale two-pass dynamic programming algorithm)
87 // 3 = SAD from PtGrey
88 int min_disp; // Minimum disparity value (max-min) must be divisible by 16
89 int num_disp; // Number of disparities (max-min) must be divisible by 16
90
91 //---------------------------------------------- SBM Configuration --------------------------------------------------------------
92 int sbm_preFilterCap; // Truncation value for the prefiltered image pixels.
93 // The algorithm first computes x-derivative at each pixel and clips its
94 // value by [-preFilterCap, preFilterCap] interval. The result values are
95 // passed to the Birchfield-Tomasi pixel cost function.
96 int sbm_preFilterSize;
97 int sbm_SADWindowSize; // Correlation window size, odd value >= 5
98 int sbm_textureThreshold; // Validation threashold for texture variation
99 int sbm_uniquenessRatio; // Margin in percentage by which the best (minimum) computed cost function value should “win”
100 // the second best value to consider the found match correct. Normally, a value within the 5-15
101 // range is good enough.
102 int sbm_speckleWindowSize; // Maximum size of smooth disparity regions to consider their noise speckles and invalidate. Set
103 // it to 0 to disable speckle filtering. Otherwise, set it somewhere in the 50-200 range.
104 int sbm_speckleRange; // Maximum disparity variation within each connected component. If you do speckle filtering, set
105 // the parameter to a positive value, it will be implicitly multiplied by 16. Normally, 1 or 2 is
106 // good enough.
107
108 //---------------------------------------------- SGBM Configuration -------------------------------------------------------------
109 int sgbm_preFilterCap; // Truncation value for the prefiltered image pixels.
110 // The algorithm first computes x-derivative at each pixel and clips its
111 // value by [-preFilterCap, preFilterCap] interval. The result values are
112 // passed to the Birchfield-Tomasi pixel cost function.
113 int sgbm_SADWindowSize; // Correlation window size, odd value >= 3
114 int sgbm_P1; // The first parameter controlling the disparity smoothness.
115 int sgbm_P2; // The second parameter controlling the disparity smoothness. The larger the values are,
116 // the smoother the disparity is. P1 is the penalty on the disparity change by plus or
117 // minus 1 between neighbor pixels. P2 is the penalty on the disparity change by more than
118 // 1 between neighbor pixels. The algorithm requires P2 > P1 .
119 int sgbm_uniquenessRatio; // Margin in percentage by which the best (minimum) computed cost function value should “win”
120 // the second best value to consider the found match correct. Normally, a value within the 5-15
121 // range is good enough.
122 int sgbm_speckleWindowSize; // Maximum size of smooth disparity regions to consider their noise speckles and invalidate. Set
123 // it to 0 to disable speckle filtering. Otherwise, set it somewhere in the 50-200 range.
124 int sgbm_speckleRange; // Maximum disparity variation within each connected component. If you do speckle filtering, set
125 // the parameter to a positive value, it will be implicitly multiplied by 16. Normally, 1 or 2 is
126 // good enough.
127 int sgbm_disp12MaxDiff; // Maximum allowed difference (in integer pixel units) in the left-right disparity check. Set it to
128 // a non-positive value to disable the check.
129
130 //------------------------------------------------------------------------------------------------------------------------------------
131
132 std::string img_source; // Image source
133 std::string img_source_left; // Left image source (if stereovision)
134 std::string img_source_right;// Right image source (if stereovision)
135
136 int mMaxImageInputSize; // Size of the input image data in the memory
137 int mMaxImageOutputSize1; // Size of the output image data in the memory
138 int mMaxImageOutputSize2; // Size of the output image data in the memory
139
140 TimestampedStructImage LeftImage; // Header for the left image
141 TimestampedStructImage RightImage; // Header for the right image
142 TimestampedStructImage RefImage; // Header for the reference image
143 TimestampedStructImage DispImage; // Header for the disp image
144
145 void* left_mem;
146 void* right_mem;
147 void* ref_mem;
148 void* disp_mem;
149 size_t left_mem_size; // Image shared memory position size
150 size_t right_mem_size; // Image shared memory position size
151 size_t ref_mem_size; // Image shared memory position size
152 size_t disp_mem_size; // Image shared memory position size
153
154 // Imput data
155 ShMem * shmem_left; // Shared memory control access to the image data
156 ShMem * shmem_right; // Shared memory control access to the image data
157
158 // Output data
159 ShMem * shmem_ref; // Shared memory control access to the image data
160 ShMem * shmem_disp; // Shared memory control access to the image data
161
162 cv::Mat CurrentLeftFrame; // Image of the left camera
163 cv::Mat CurrentRightFrame; // Image of the right camera
164 cv::Mat CurrentDisparityMap; // DisparityMap
165
166 /* CalcDisparityMap
167 Description:
168 Calculate the Disparity Map of a stereo pair
169 Parameters:
170 Left_img = left image
171 Right_img = right image
172 Disp_map = disparity map
173 type = Method: 0 = SAD (Sum of Absolute Differences algorithm)
174 1 = SGBM (Semi-Global Block Matching algorithm)
175 2 = SGBM+HH (full-scale two-pass dynamic programming algorithm)
176 */
177 void CalcDisparityMap(cv::Mat Left_img, cv::Mat Right_img, cv::Mat &Disp_map, Type type);
178
179
180 // tmp
181 bool recording, THREAD_ALIVE;
182 bool showdebug; // Show frame acquired
183};
184
185}
186#endif // DISPARITYMAP
Note: See TracBrowser for help on using the repository browser.