[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 | #include <QMutex>
|
---|
| 34 |
|
---|
| 35 | namespace pacpus {
|
---|
| 36 |
|
---|
| 37 | /** Class to provide the obstacle detection from a disparity map data */
|
---|
| 38 | class STEREOVISIONDISPARITY_API ObstacleDetectionComponent: public QThread,
|
---|
| 39 | public ComponentBase
|
---|
| 40 | {
|
---|
| 41 | public:
|
---|
| 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 |
|
---|
| 53 | protected:
|
---|
| 54 |
|
---|
| 55 | // Indicates that thread is running
|
---|
| 56 | bool is_running, THREAD_ALIVE;
|
---|
| 57 |
|
---|
| 58 |
|
---|
| 59 | public:
|
---|
| 60 |
|
---|
| 61 | /**
|
---|
| 62 | * Initialize default values
|
---|
| 63 | */
|
---|
| 64 | void InitDefault();
|
---|
| 65 |
|
---|
| 66 | private:
|
---|
| 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 |
|
---|
[56] | 96 | void * ref_mem;
|
---|
| 97 | void * dispin_mem;
|
---|
| 98 | void * mask1_mem;
|
---|
| 99 | void * mask2_mem;
|
---|
| 100 | void * dispout_mem;
|
---|
[53] | 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 |
|
---|
[56] | 117 | ShMem * shmem_dispMapNormalized;
|
---|
| 118 | ShMem * shmem_result;
|
---|
| 119 |
|
---|
[53] | 120 | cv::Mat CurrentReferenceFrame; // Reference image
|
---|
| 121 | cv::Mat CurrentDisparityMap16; // Disparity Map
|
---|
| 122 |
|
---|
| 123 | cv::Mat CurrentSurfaceMask; // Surface mask
|
---|
| 124 | cv::Mat CurrentObstaclesMask; // Obstacles mask
|
---|
| 125 |
|
---|
| 126 | // Function to calculate the U/V disparity map
|
---|
| 127 | std::pair<cv::Mat, cv::Mat> CalcUVDisparityMap(cv::Mat disp_map);
|
---|
| 128 |
|
---|
| 129 | /* CalcUVDisparityMapNorm
|
---|
| 130 | Description:
|
---|
| 131 | Function to calculate the U/V disparity map from a disp map normalized
|
---|
| 132 | Parameters:
|
---|
| 133 | disp_map16 = original disparity map 16
|
---|
| 134 | disp_map_norm = resulted disparity map normalized
|
---|
| 135 | min_d_norm = Minimum disparity value to equalize the disp map 16
|
---|
| 136 | max_d_norm = Maximum disparity value to equalize the disp map 16
|
---|
| 137 | */
|
---|
| 138 | 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);
|
---|
| 139 |
|
---|
| 140 | //Function to check the points order, making the second one with the highest y ever
|
---|
| 141 | void CheckPoints(cv::Point &pt1, cv::Point &pt2);
|
---|
| 142 |
|
---|
| 143 | // Function to calculate the line slope of pt1 to pt2
|
---|
| 144 | double Inclination(cv::Point pt1, cv::Point pt2);
|
---|
| 145 |
|
---|
| 146 | // Function to calculate the free space (v_disp_1) and obstacles (v_disp_2) masks from
|
---|
| 147 | // a red highlighted V-Disparity map
|
---|
| 148 | 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);
|
---|
| 149 |
|
---|
| 150 | // Function to calculate the free space (v_disp_1) and obstacles (v_disp_2/u_disp) masks from
|
---|
| 151 | // a red highlighted V-Disparity map
|
---|
| 152 | 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);
|
---|
| 153 |
|
---|
| 154 | // Function to find the free space surface from a V-disparity map
|
---|
| 155 | cv::Mat FindSurface(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
|
---|
| 156 |
|
---|
| 157 | /* FindSurface2
|
---|
| 158 | Description:
|
---|
| 159 | Function to find the free space surface from a V-disparity map, based on the frontal plane.
|
---|
| 160 | Return the V-dysparity map with the red line representing the free surface.
|
---|
| 161 | Parameters:
|
---|
| 162 | v_disp_map = Original V-disparity map
|
---|
| 163 | v_disp_map2 = Orignal V-disparity map less the surface detected
|
---|
| 164 | */
|
---|
| 165 | cv::Mat FindSurface2(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
|
---|
| 166 |
|
---|
| 167 | // Function to find the free space surface from a V-disparity map with mean average
|
---|
| 168 | cv::Mat FindAverageSurface(cv::Mat &v_disp_map, cv::Mat &v_disp_map2);
|
---|
| 169 |
|
---|
| 170 | // Function to find the near obstacles from a v-Disparity map
|
---|
| 171 | cv::Mat FindNearObstacles(cv::Mat v_disp_map, int min_d = 0, int max_d = 255);
|
---|
| 172 |
|
---|
| 173 | // Function to find the near obstacles from the v/u-Disparity maps
|
---|
| 174 | 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);
|
---|
| 175 |
|
---|
| 176 | /* LinesFiltering
|
---|
| 177 | Description:
|
---|
| 178 | Filter the detected lines related to the distance and angle between them.
|
---|
| 179 | Parameters:
|
---|
| 180 | lines = line list (point 1 and 2)
|
---|
| 181 | */
|
---|
| 182 | std::vector<cv::Point> LinesFiltering(std::vector<cv::Vec4i> lines);
|
---|
| 183 |
|
---|
| 184 | /* CalcMedian
|
---|
| 185 | Description:
|
---|
| 186 | Calcule the median value of a vector.
|
---|
| 187 | Parametros:
|
---|
| 188 | vector = vector with data to calculate the median
|
---|
| 189 | */
|
---|
| 190 | template<class A>
|
---|
| 191 | A CalcMedian(std::vector<A> vetor) const;
|
---|
| 192 |
|
---|
| 193 | };
|
---|
| 194 |
|
---|
| 195 | }
|
---|
| 196 | #endif // OBSTACLEDETECTIONCOMPONENT
|
---|