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

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

StereoVisionDisparity updated

File size: 7.2 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#include <QMutex>
34
35namespace pacpus {
36
37/** Class to provide the obstacle detection from a disparity map data */
38class STEREOVISIONDISPARITY_API ObstacleDetectionComponent: public QThread,
39 public ComponentBase
40{
41public:
42 //============================= DEFAULT ELEMENTS ===============================================
43 ObstacleDetectionComponent(QString name);
44 ~ObstacleDetectionComponent();
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, THREAD_ALIVE;
57
58
59public:
60
61 /**
62 * Initialize default values
63 */
64 void InitDefault();
65
66private:
67
68 double ANG_VARIATION, ANG_VARIATION2;
69
70 int cam_width; // Image width
71 int cam_height; // image height
72 int cam_channels; // number of channels
73 bool showdebug; // Show frame acquired
74 int min_disp; // Minimum disparity value to detect obstacles in the u/v-disp map
75 int max_disp; // Maximum disparity value to detect obstacles in the u/v-disp map
76 int min_disp_norm; // Minimum disparity value to equalize the disp map 16
77 int max_disp_norm; // Maximum disparity value to equalize the disp map 16
78
79 int destiny_roi_x; // Destiny image roi x
80 int destiny_roi_y; // Destiny image roi y
81 int destiny_roi_width; // Destiny image roi width
82 int destiny_roi_height; // Destiny image roi height
83
84 bool use_roi; // If is to use roi
85
86 int mMaxImageInputSize1; // Size of the input image data in the memory
87 int mMaxImageInputSize2; // Size of the input image data in the memory
88 int mMaxImageOutputSize; // Size of the output image data in the memory
89
90 TimestampedStructImage RefImageHeader; // Header for the reference image
91 TimestampedStructImage DispInImageHeader; // Header for the input disp image
92 TimestampedStructImage Mask1ImageHeader; // Header for the mask image 1
93 TimestampedStructImage Mask2ImageHeader; // Header for the mask image 2
94 TimestampedStructImage DispOutImageHeader; // Header for the output disp image
95
96 void* ref_mem;
97 void* dispin_mem;
98 void* mask1_mem;
99 void* mask2_mem;
100 void* dispout_mem;
101
102 size_t ref_mem_size; // Image shared memory position size
103 size_t dispin_mem_size; // Image shared memory position size
104 size_t mask1_mem_size; // Image shared memory position size
105 size_t mask2_mem_size; // Image shared memory position size
106 size_t dispout_mem_size; // Image shared memory position size
107
108 // Imput data
109 ShMem * shmem_ref; // Shared memory control access to the image data
110 ShMem * shmem_dispin; // Shared memory control access to the image data
111
112 // Output data
113 ShMem * shmem_mask1; // Shared memory control access to the image data (free space mask)
114 ShMem * shmem_mask2; // Shared memory control access to the image data (obstacles mask)
115 ShMem * shmem_dispout; // Shared memory control access to the image data (disparity map 16)
116
117 cv::Mat CurrentReferenceFrame; // Reference image
118 cv::Mat CurrentDisparityMap16; // Disparity Map
119
120 cv::Mat CurrentSurfaceMask; // Surface mask
121 cv::Mat CurrentObstaclesMask; // Obstacles mask
122
123 // Function to calculate the U/V disparity map
124 std::pair<cv::Mat, cv::Mat> CalcUVDisparityMap(cv::Mat disp_map);
125
126 /* CalcUVDisparityMapNorm
127 Description:
128 Function to calculate the U/V disparity map from a disp map normalized
129 Parameters:
130 disp_map16 = original disparity map 16
131 disp_map_norm = resulted disparity map normalized
132 min_d_norm = Minimum disparity value to equalize the disp map 16
133 max_d_norm = Maximum disparity value to equalize the disp map 16
134 */
135 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);
136
137 //Function to check the points order, making the second one with the highest y ever
138 void CheckPoints(cv::Point &pt1, cv::Point &pt2);
139
140 // Function to calculate the line slope of pt1 to pt2
141 double Inclination(cv::Point pt1, cv::Point pt2);
142
143 // Function to calculate the free space (v_disp_1) and obstacles (v_disp_2) masks from
144 // a red highlighted V-Disparity map
145 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);
146
147 // Function to calculate the free space (v_disp_1) and obstacles (v_disp_2/u_disp) masks from
148 // a red highlighted V-Disparity map
149 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);
150
151 // Function to find the free space surface from a V-disparity map
152 cv::Mat FindSurface(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
153
154 /* FindSurface2
155 Description:
156 Function to find the free space surface from a V-disparity map, based on the frontal plane.
157 Return the V-dysparity map with the red line representing the free surface.
158 Parameters:
159 v_disp_map = Original V-disparity map
160 v_disp_map2 = Orignal V-disparity map less the surface detected
161 */
162 cv::Mat FindSurface2(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
163
164 // Function to find the free space surface from a V-disparity map with mean average
165 cv::Mat FindAverageSurface(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
166
167 // Function to find the near obstacles from a v-Disparity map
168 cv::Mat FindNearObstacles(cv::Mat v_disp_map, int min_d = 0, int max_d = 255);
169
170 // Function to find the near obstacles from the v/u-Disparity maps
171 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);
172
173 /* LinesFiltering
174 Description:
175 Filter the detected lines related to the distance and angle between them.
176 Parameters:
177 lines = line list (point 1 and 2)
178 */
179 std::vector<cv::Point> LinesFiltering(std::vector<cv::Vec4i> lines);
180
181 /* CalcMedian
182 Description:
183 Calcule the median value of a vector.
184 Parametros:
185 vector = vector with data to calculate the median
186 */
187 template<class A>
188 A CalcMedian(std::vector<A> vetor) const;
189
190};
191
192}
193#endif // OBSTACLEDETECTIONCOMPONENT
Note: See TracBrowser for help on using the repository browser.