source: pacpussensors/trunk/StereoVisionDisparity/ObstacleDetectionComponent.h@ 64

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

Programme détection d'obstacles amélioré

File size: 7.6 KB
Line 
1/*********************************************************************
2// created: 2013/06/25 - 18:40
3// filename: ObstacleDetectionComponent.h
4//
5// author: Danilo Alves de Lima
6// Copyright Heudiasyc UMR UTC/CNRS 6599
7//
8// version: $Id: $
9//
10// purpose:
11*********************************************************************/
12
13#ifndef OBSTACLEDETECTIONCOMPONENT_H
14#define OBSTACLEDETECTIONCOMPONENT_H
15
16#include <fstream>
17#include <qcoreevent.h>
18#include <qthread.h>
19#include <string>
20
21#include "opencv2/objdetect/objdetect.hpp"
22#include "opencv2/highgui/highgui.hpp"
23#include "opencv2/imgproc/imgproc.hpp"
24
25#include "Pacpus/kernel/ComponentBase.h"
26#include "Pacpus/kernel/DbiteFile.h"
27#include "Pacpus/PacpusTools/ShMem.h"
28#include "StereoVisionDisparityExp.h"
29
30#include "../../StdDbtPlayerComponents/ImageBaseStructure.h"
31
32#include <QThread>
33
34namespace pacpus {
35
36/** Class to provide the obstacle detection from a disparity map data */
37class STEREOVISIONDISPARITY_API ObstacleDetectionComponent: public QThread,
38 public ComponentBase
39{
40public:
41 //============================= DEFAULT ELEMENTS ===============================================
42 ObstacleDetectionComponent(QString name);
43 ~ObstacleDetectionComponent();
44
45 void run();
46
47 virtual void stopActivity(); /*!< to stop the processing thread */
48 virtual void startActivity(); /*!< to start the processing thread */
49 virtual ComponentBase::COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
50 //==============================================================================================
51
52protected:
53
54 // Indicates that thread is running
55 bool is_running, THREAD_ALIVE;
56
57
58public:
59
60 /**
61 * Initialize default values
62 */
63 void InitDefault();
64
65private:
66
67 double ANG_VARIATION, ANG_VARIATION2;
68
69 int cam_width; // Image width
70 int cam_height; // image height
71 int cam_channels; // number of channels
72 double cam_ref_cx; // cx camera divide by x image size
73 double cam_ref_cy; // cy camera divide by y image size
74 double cam_ref_fx; // fx camera divide by x image size
75 double cam_ref_fy; // fy camera divide by y image size
76 bool showdebug; // Show frame acquired
77 int min_disp; // Minimum disparity value to detect obstacles in the u/v-disp map
78 int max_disp; // Maximum disparity value to detect obstacles in the u/v-disp map
79 int min_disp_norm; // Minimum disparity value to equalize the disp map 16
80 int max_disp_norm; // Maximum disparity value to equalize the disp map 16
81
82 int destiny_roi_x; // Destiny image roi x
83 int destiny_roi_y; // Destiny image roi y
84 int destiny_roi_width; // Destiny image roi width
85 int destiny_roi_height; // Destiny image roi height
86
87 bool use_roi; // If is to use roi
88
89 int mMaxImageInputSize1; // Size of the input image data in the memory
90 int mMaxImageInputSize2; // Size of the input image data in the memory
91 int mMaxImageOutputSize; // Size of the output image data in the memory
92
93 TimestampedStructImage RefImageHeader; // Header for the reference image
94 TimestampedStructImage DispInImageHeader; // Header for the input disp image
95 TimestampedStructImage Mask1ImageHeader; // Header for the mask image 1
96 TimestampedStructImage Mask2ImageHeader; // Header for the mask image 2
97 TimestampedStructImage DispOutImageHeader; // Header for the output disp image
98
99 void * ref_mem;
100 void * dispin_mem;
101 void * mask1_mem;
102 void * mask2_mem;
103 void * dispout_mem;
104
105 size_t ref_mem_size; // Image shared memory position size
106 size_t dispin_mem_size; // Image shared memory position size
107 size_t mask1_mem_size; // Image shared memory position size
108 size_t mask2_mem_size; // Image shared memory position size
109 size_t dispout_mem_size; // Image shared memory position size
110
111 // Imput data
112 ShMem * shmem_ref; // Shared memory control access to the image data
113 ShMem * shmem_dispin; // Shared memory control access to the image data
114
115 // Output data
116 ShMem * shmem_mask1; // Shared memory control access to the image data (free space mask)
117 ShMem * shmem_mask2; // Shared memory control access to the image data (obstacles mask)
118 ShMem * shmem_dispout; // Shared memory control access to the image data (disparity map 16)
119
120 ShMem * shmem_dispMapNormalized;
121 ShMem * shmem_result;
122
123 cv::Mat CurrentReferenceFrame; // Reference image
124 cv::Mat CurrentDisparityMap16; // Disparity Map
125
126 cv::Mat CurrentSurfaceMask; // Surface mask
127 cv::Mat CurrentObstaclesMask; // Obstacles mask
128
129 // Function to calculate the U/V disparity map
130 std::pair<cv::Mat, cv::Mat> CalcUVDisparityMap(cv::Mat disp_map);
131
132 /* CalcUVDisparityMapNorm
133 Description:
134 Function to calculate the U/V disparity map from a disp map normalized
135 Parameters:
136 disp_map16 = original disparity map 16
137 disp_map_norm = resulted disparity map normalized
138 min_d_norm = Minimum disparity value to equalize the disp map 16
139 max_d_norm = Maximum disparity value to equalize the disp map 16
140 */
141 void CalcUVDisparityMapNorm(cv::Mat disp_map16, cv::Mat &v_disp_map, cv::Mat &u_disp_map, cv::Mat &disp_map_norm, int min_d_norm, int max_d_norm);
142
143 //Function to check the points order, making the second one with the highest y ever
144 void CheckPoints(cv::Point &pt1, cv::Point &pt2);
145
146 // Function to calculate the line slope of pt1 to pt2
147 double Inclination(cv::Point pt1, cv::Point pt2);
148
149 // Function to calculate the free space (v_disp_1) and obstacles (v_disp_2) masks from
150 // a red highlighted V-Disparity map
151 std::pair<cv::Mat, cv::Mat> MaskSurface2(cv::Mat disp_map, cv::Mat v_disp_1, cv::Mat v_disp_2, int min_d = 0, int max_d = 255, int value = 0);
152
153 // Function to calculate the free space (v_disp_1) and obstacles (v_disp_2/u_disp) masks from
154 // a red highlighted V-Disparity map
155 std::pair<cv::Mat, cv::Mat> MaskSurface3(cv::Mat disp_map, cv::Mat v_disp_1, cv::Mat v_disp_2, cv::Mat u_disp, int min_d = 0, int max_d = 255, int value = 0);
156
157 // Function to find the free space surface from a V-disparity map
158 cv::Mat FindSurface(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
159
160 /* FindSurface2
161 Description:
162 Function to find the free space surface from a V-disparity map, based on the frontal plane.
163 Return the V-dysparity map with the red line representing the free surface.
164 Parameters:
165 v_disp_map = Original V-disparity map
166 v_disp_map2 = Orignal V-disparity map less the surface detected
167 */
168 cv::Mat FindSurface2(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
169
170 // Function to find the free space surface from a V-disparity map with mean average
171 cv::Mat FindAverageSurface(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
172
173 // Function to find the near obstacles from a v-Disparity map
174 cv::Mat FindNearObstacles(cv::Mat v_disp_map, int min_d = 0, int max_d = 255);
175
176 // Function to find the near obstacles from the v/u-Disparity maps
177 std::pair<cv::Mat, cv::Mat> FindNearObstaclesUV(cv::Mat v_disp_map, cv::Mat u_disp_map, int min_d = 0, int max_d = 255);
178
179 /* LinesFiltering
180 Description:
181 Filter the detected lines related to the distance and angle between them.
182 Parameters:
183 lines = line list (point 1 and 2)
184 */
185 std::vector<cv::Point> LinesFiltering(std::vector<cv::Vec4i> lines);
186
187 /* CalcMedian
188 Description:
189 Calcule the median value of a vector.
190 Parametros:
191 vector = vector with data to calculate the median
192 */
193 template<class A>
194 A CalcMedian(std::vector<A> vetor) const;
195
196 //bool PointTriangulate(int row, int col, double &x, double &y, double &z, double disparity);
197};
198
199}
200#endif // OBSTACLEDETECTIONCOMPONENT
Note: See TracBrowser for help on using the repository browser.