Apollo 10.0
自动驾驶开放平台
visualizer.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2022 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 implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *****************************************************************************/
16
18
19#include <algorithm>
20#include <cstring>
21#include <fstream>
22#include <iostream>
23
24#include "opencv2/opencv.hpp"
25
26#include "cyber/common/log.h"
28
29namespace apollo {
30namespace perception {
31namespace camera {
32
33static const cv::Scalar kFaceColors[] = {
34 cv::Scalar(255, 255, 255), // black
35 cv::Scalar(255, 0, 0), // blue
36 cv::Scalar(0, 255, 0), // green
37 cv::Scalar(0, 0, 255), // red
38};
39
41 const std::string& file_name) {
42 cv::Mat cv_img(frame->data_provider->src_height(),
43 frame->data_provider->src_width(), CV_8UC3,
44 cv::Scalar(0, 0, 0));
45
46 RecoveryImage(frame, &cv_img);
47
48 int obj_id = 0;
49 for (auto obj : frame->detected_objects) {
50 auto& supp = obj->camera_supplement;
51 auto& box = supp.box;
52 auto area_id = supp.area_id;
53
54 cv::rectangle(
55 cv_img,
56 cv::Point(static_cast<int>(box.xmin), static_cast<int>(box.ymin)),
57 cv::Point(static_cast<int>(box.xmax), static_cast<int>(box.ymax)),
58 cv::Scalar(0, 0, 0), 8);
59 float xmid = (box.xmin + box.xmax) / 2;
60 ACHECK(area_id > 0 && area_id < 9);
61 if (area_id & 1) {
62 cv::rectangle(
63 cv_img,
64 cv::Point(static_cast<int>(box.xmin), static_cast<int>(box.ymin)),
65 cv::Point(static_cast<int>(box.xmax), static_cast<int>(box.ymax)),
66 kFaceColors[area_id / 2], 2);
67 } else {
68 auto& tl = supp.cut_off_ratios[2];
69 auto& tr = supp.cut_off_ratios[3];
70 auto&& left_ratio = supp.visible_ratios[(area_id / 2) % 4];
71 auto w = box.xmax - box.xmin;
72 auto x = box.xmin;
73 auto tm = std::max(tl, tr);
74 if (tm > 1e-2) {
75 if (tl > tr) {
76 xmid = (x - w * tl) + (w + w * tl) * left_ratio;
77 } else if (tl < tr) {
78 xmid = x + (w + w * tr) * left_ratio;
79 }
80 } else {
81 xmid = x + w * left_ratio;
82 }
83 cv::rectangle(
84 cv_img,
85 cv::Point(static_cast<int>(box.xmin), static_cast<int>(box.ymin)),
86 cv::Point(static_cast<int>(xmid), static_cast<int>(box.ymax)),
87 kFaceColors[(area_id / 2) % 4], 3);
88 cv::rectangle(
89 cv_img, cv::Point(static_cast<int>(xmid), static_cast<int>(box.ymin)),
90 cv::Point(static_cast<int>(box.xmax), static_cast<int>(box.ymax)),
91 kFaceColors[area_id / 2 - 1], 2);
92 }
93 fprintf(stderr,
94 "obj-%02d: %.3f %.3f %.3f %.3f -- %.3f %.3f %.3f %.3f "
95 "-- %.0f %.0f %.0f %d\n",
96 obj_id, supp.visible_ratios[0], supp.visible_ratios[1],
97 supp.visible_ratios[2], supp.visible_ratios[3],
98 supp.cut_off_ratios[0], supp.cut_off_ratios[1],
99 supp.cut_off_ratios[2], supp.cut_off_ratios[3], box.xmin, xmid,
100 box.xmax, area_id);
101 std::stringstream text;
102 auto& name = base::kSubType2NameMap.at(obj->sub_type);
103 text << name[0] << name[1] << name[2] << " - " << obj_id++;
104 cv::putText(
105 cv_img, text.str(),
106 cv::Point(static_cast<int>(box.xmin), static_cast<int>(box.ymin)),
107 cv::FONT_HERSHEY_PLAIN, 2, cv::Scalar(255, 0, 0), 2);
108 }
109
110 cv::imwrite(file_name.c_str(), cv_img);
111 return true;
112}
113
115 const std::string& file_name) {
116 return true;
117}
118
120 const std::string& file_name) {
121 return true;
122}
123
124} // namespace camera
125} // namespace perception
126} // namespace apollo
#define ACHECK(cond)
Definition log.h:80
const std::map< ObjectSubType, std::string > kSubType2NameMap
bool RecoveryImage(onboard::CameraFrame *frame, cv::Mat *cv_img)
Recovery cv image from frame->data_provider
Definition util.cc:46
bool CameraVisualization(onboard::CameraFrame *frame, const std::string &file_name)
Save visualization results to file_name(.jpg)
Definition visualizer.cc:40
bool TfVisualization(onboard::CameraFrame *frame, const std::string &file_name)
bool LaneVisualization(onboard::CameraFrame *frame, const std::string &file_name)
class register implement
Definition arena_queue.h:37
std::shared_ptr< camera::DataProvider > data_provider