Apollo  6.0
Open source self driving car software
semantic_map.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2019 The Apollo Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13  *implied. See the License for the specific language governing
14  *permissions and limitations under the License.
15  *****************************************************************************/
16 
17 #pragma once
18 
19 #include <future>
20 #include <unordered_map>
21 
22 #include "opencv2/opencv.hpp"
23 
24 #include "cyber/common/macros.h"
25 #include "modules/prediction/proto/feature.pb.h"
26 
27 namespace apollo {
28 namespace prediction {
29 
30 class SemanticMap {
31  public:
32  SemanticMap();
33 
34  virtual ~SemanticMap() = default;
35 
36  void Init();
37 
38  void RunCurrFrame(
39  const std::unordered_map<int, ObstacleHistory>& obstacle_id_history_map);
40 
41  bool GetMapById(const int obstacle_id, cv::Mat* feature_map);
42 
43  private:
44  cv::Point2i GetTransPoint(const double x, const double y, const double base_x,
45  const double base_y) {
46  return cv::Point2i(static_cast<int>((x - base_x) / 0.1),
47  static_cast<int>(2000 - (y - base_y) / 0.1));
48  }
49 
50  void DrawBaseMap(const double x, const double y, const double base_x,
51  const double base_y);
52 
53  void DrawBaseMapThread();
54 
55  void DrawRoads(const common::PointENU& center_point, const double base_x,
56  const double base_y,
57  const cv::Scalar& color = cv::Scalar(64, 64, 64));
58 
59  void DrawJunctions(const common::PointENU& center_point, const double base_x,
60  const double base_y,
61  const cv::Scalar& color = cv::Scalar(128, 128, 128));
62 
63  void DrawCrosswalks(const common::PointENU& center_point, const double base_x,
64  const double base_y,
65  const cv::Scalar& color = cv::Scalar(192, 192, 192));
66 
67  void DrawLanes(const common::PointENU& center_point, const double base_x,
68  const double base_y,
69  const cv::Scalar& color = cv::Scalar(255, 255, 255));
70 
71  cv::Scalar HSVtoRGB(double H = 1.0, double S = 1.0, double V = 1.0);
72 
73  void DrawRect(const Feature& feature, const cv::Scalar& color,
74  const double base_x, const double base_y, cv::Mat* img);
75 
76  void DrawPoly(const Feature& feature, const cv::Scalar& color,
77  const double base_x, const double base_y, cv::Mat* img);
78 
79  void DrawHistory(const ObstacleHistory& history, const cv::Scalar& color,
80  const double base_x, const double base_y, cv::Mat* img);
81 
82  cv::Mat CropArea(const cv::Mat& input_img, const cv::Point2i& center_point,
83  const double heading);
84 
85  cv::Mat CropByHistory(const ObstacleHistory& history, const cv::Scalar& color,
86  const double base_x, const double base_y);
87 
88  private:
89  // base_image, base_x, and base_y to be updated by async thread
90  cv::Mat base_img_;
91  double base_x_ = 0.0;
92  double base_y_ = 0.0;
93 
94  std::mutex draw_base_map_thread_mutex_;
95 
96  // base_image, base_x, and base_y to be used in the current cycle
97  cv::Mat curr_img_;
98  double curr_base_x_ = 0.0;
99  double curr_base_y_ = 0.0;
100 
101  std::unordered_map<int, ObstacleHistory> obstacle_id_history_map_;
102  Feature ego_feature_;
103 
104  std::future<void> task_future_;
105 
106  bool started_drawing_ = false;
107 };
108 
109 } // namespace prediction
110 } // namespace apollo
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Definition: semantic_map.h:30
virtual ~SemanticMap()=default
void RunCurrFrame(const std::unordered_map< int, ObstacleHistory > &obstacle_id_history_map)
bool GetMapById(const int obstacle_id, cv::Mat *feature_map)