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

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

New function

File size: 7.6 KB
RevLine 
[53]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
[64]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
[68]76 double cam_baseline; // distance between two cameras in meter
[53]77 bool showdebug; // Show frame acquired
78 int min_disp; // Minimum disparity value to detect obstacles in the u/v-disp map
79 int max_disp; // Maximum disparity value to detect obstacles in the u/v-disp map
80 int min_disp_norm; // Minimum disparity value to equalize the disp map 16
81 int max_disp_norm; // Maximum disparity value to equalize the disp map 16
82
83 int destiny_roi_x; // Destiny image roi x
84 int destiny_roi_y; // Destiny image roi y
85 int destiny_roi_width; // Destiny image roi width
86 int destiny_roi_height; // Destiny image roi height
87
88 bool use_roi; // If is to use roi
89
90 int mMaxImageInputSize1; // Size of the input image data in the memory
91 int mMaxImageInputSize2; // Size of the input image data in the memory
92 int mMaxImageOutputSize; // Size of the output image data in the memory
93
94 TimestampedStructImage RefImageHeader; // Header for the reference image
95 TimestampedStructImage DispInImageHeader; // Header for the input disp image
96 TimestampedStructImage Mask1ImageHeader; // Header for the mask image 1
97 TimestampedStructImage Mask2ImageHeader; // Header for the mask image 2
98 TimestampedStructImage DispOutImageHeader; // Header for the output disp image
99
[56]100 void * ref_mem;
101 void * dispin_mem;
102 void * mask1_mem;
103 void * mask2_mem;
104 void * dispout_mem;
[53]105
106 size_t ref_mem_size; // Image shared memory position size
107 size_t dispin_mem_size; // Image shared memory position size
108 size_t mask1_mem_size; // Image shared memory position size
109 size_t mask2_mem_size; // Image shared memory position size
110 size_t dispout_mem_size; // Image shared memory position size
111
112 // Imput data
113 ShMem * shmem_ref; // Shared memory control access to the image data
114 ShMem * shmem_dispin; // Shared memory control access to the image data
115
116 // Output data
117 ShMem * shmem_mask1; // Shared memory control access to the image data (free space mask)
118 ShMem * shmem_mask2; // Shared memory control access to the image data (obstacles mask)
119 ShMem * shmem_dispout; // Shared memory control access to the image data (disparity map 16)
120
[56]121 ShMem * shmem_dispMapNormalized;
122 ShMem * shmem_result;
123
[53]124 cv::Mat CurrentReferenceFrame; // Reference image
125 cv::Mat CurrentDisparityMap16; // Disparity Map
126
127 cv::Mat CurrentSurfaceMask; // Surface mask
128 cv::Mat CurrentObstaclesMask; // Obstacles mask
129
130 // Function to calculate the U/V disparity map
131 std::pair<cv::Mat, cv::Mat> CalcUVDisparityMap(cv::Mat disp_map);
132
133 /* CalcUVDisparityMapNorm
134 Description:
135 Function to calculate the U/V disparity map from a disp map normalized
136 Parameters:
137 disp_map16 = original disparity map 16
138 disp_map_norm = resulted disparity map normalized
139 min_d_norm = Minimum disparity value to equalize the disp map 16
140 max_d_norm = Maximum disparity value to equalize the disp map 16
141 */
142 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);
143
144 //Function to check the points order, making the second one with the highest y ever
145 void CheckPoints(cv::Point &pt1, cv::Point &pt2);
146
147 // Function to calculate the line slope of pt1 to pt2
148 double Inclination(cv::Point pt1, cv::Point pt2);
149
150 // Function to calculate the free space (v_disp_1) and obstacles (v_disp_2) masks from
151 // a red highlighted V-Disparity map
152 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);
153
154 // Function to calculate the free space (v_disp_1) and obstacles (v_disp_2/u_disp) masks from
155 // a red highlighted V-Disparity map
156 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);
157
158 // Function to find the free space surface from a V-disparity map
159 cv::Mat FindSurface(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
160
161 /* FindSurface2
162 Description:
163 Function to find the free space surface from a V-disparity map, based on the frontal plane.
164 Return the V-dysparity map with the red line representing the free surface.
165 Parameters:
166 v_disp_map = Original V-disparity map
167 v_disp_map2 = Orignal V-disparity map less the surface detected
168 */
169 cv::Mat FindSurface2(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
170
171 // Function to find the free space surface from a V-disparity map with mean average
172 cv::Mat FindAverageSurface(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
173
174 // Function to find the near obstacles from a v-Disparity map
175 cv::Mat FindNearObstacles(cv::Mat v_disp_map, int min_d = 0, int max_d = 255);
176
177 // Function to find the near obstacles from the v/u-Disparity maps
178 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);
179
180 /* LinesFiltering
181 Description:
182 Filter the detected lines related to the distance and angle between them.
183 Parameters:
184 lines = line list (point 1 and 2)
185 */
186 std::vector<cv::Point> LinesFiltering(std::vector<cv::Vec4i> lines);
187
188 /* CalcMedian
189 Description:
190 Calcule the median value of a vector.
191 Parametros:
192 vector = vector with data to calculate the median
193 */
194 template<class A>
195 A CalcMedian(std::vector<A> vetor) const;
196
[68]197 bool PointTriangulate(int row, int col, double &x, double &y, double &z, double disparity);
[53]198};
199
200}
201#endif // OBSTACLEDETECTIONCOMPONENT
Note: See TracBrowser for help on using the repository browser.