Apollo 10.0
自动驾驶开放平台
debug_info.cc
浏览该文件的文档.
1/******************************************************************************
2 * Copyright 2018 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 *****************************************************************************/
17
18#include <iomanip>
19
20#include "cyber/common/log.h"
23
24namespace apollo {
25namespace perception {
26namespace camera {
27
28int WriteLanelines(const bool enabled, const std::string &save_path,
29 const std::vector<base::LaneLine> &lane_objects) {
30 if (!enabled) {
31 return -1;
32 }
33 FILE *file_save = fopen(save_path.data(), "wt");
34 if (file_save == nullptr) {
35 AERROR << "Failed to open lane save path: " << save_path;
36 return -1;
37 }
38 int lane_line_size = static_cast<int>(lane_objects.size());
39 AINFO << "Lane line num: " << lane_line_size;
40 fprintf(file_save, "[\n");
41 for (int j = 0; j < lane_line_size; ++j) {
42 const base::LaneLineCubicCurve &curve_camera =
43 lane_objects[j].curve_camera_coord;
44 const base::LaneLineCubicCurve &curve_img =
45 lane_objects[j].curve_image_coord;
46 const std::vector<base::Point3DF> &camera_point_set =
47 lane_objects[j].curve_camera_point_set;
48 const std::vector<base::Point2DF> &image_point_set =
49 lane_objects[j].curve_image_point_set;
50 fprintf(file_save, "{\n");
51 fprintf(file_save, "\"type\":%d,\n", lane_objects[j].type);
52 fprintf(file_save, "\"pos_type\":%d,\n", lane_objects[j].pos_type);
53 // Camera curve
54 fprintf(file_save, "\"camera_curve\":\n");
55 fprintf(file_save, "{\"a\":%.10f,\"b\":%.10f,\"c\":%.10f,\"d\":%.10f,",
56 curve_camera.a, curve_camera.b, curve_camera.c, curve_camera.d);
57 fprintf(file_save, "\"x0\":%.10f,\"x1\":%.10f},\n", curve_camera.x_start,
58 curve_camera.x_end);
59 // Camera image point set
60 fprintf(file_save, "\"camera_point_set\":\n");
61 fprintf(file_save, "[");
62 for (size_t k = 0; k < camera_point_set.size(); k++) {
63 if (k < camera_point_set.size() - 1) {
64 fprintf(file_save, "{\"x\":%.4f,\"y\":%.4f,\"z\":%.4f},",
65 camera_point_set[k].x, camera_point_set[k].y,
66 camera_point_set[k].z);
67 } else {
68 fprintf(file_save, "{\"x\":%.4f,\"y\":%.4f,\"z\":%.4f}",
69 camera_point_set[k].x, camera_point_set[k].y,
70 camera_point_set[k].z);
71 }
72 }
73 fprintf(file_save, "],");
74 fprintf(file_save, "\n");
75 // Image curve
76 fprintf(file_save, "\"image_curve\":\n");
77 fprintf(file_save, "{\"a\":%.10f,\"b\":%.10f,\"c\":%.10f,\"d\":%.10f,",
78 curve_img.a, curve_img.b, curve_img.c, curve_img.d);
79 fprintf(file_save, "\"x0\":%.10f,\"x1\":%.10f},\n", curve_img.x_start,
80 curve_img.x_end);
81 // Curve image point set
82 fprintf(file_save, "\"image_point_set\":\n");
83 fprintf(file_save, "[");
84 for (size_t k = 0; k < image_point_set.size(); ++k) {
85 if (k < image_point_set.size() - 1) {
86 fprintf(file_save, "{\"x\":%.4f,\"y\":%.4f},", image_point_set[k].x,
87 image_point_set[k].y);
88 } else {
89 fprintf(file_save, "{\"x\":%.4f,\"y\":%.4f}", image_point_set[k].x,
90 image_point_set[k].y);
91 }
92 }
93 fprintf(file_save, "]");
94 fprintf(file_save, "\n");
95 if (j < lane_line_size - 1) {
96 fprintf(file_save, "},\n");
97 } else {
98 fprintf(file_save, "}\n");
99 }
100 }
101 fprintf(file_save, "]\n");
102 fclose(file_save);
103 return 0;
104}
105
106int WriteCalibrationOutput(bool enabled, const std::string &out_path,
107 const CameraFrame *frame) {
108 if (!enabled) {
109 return -1;
110 }
111 float pitch_angle = 0.f;
112 float camera_ground_height = 0.f;
114 &camera_ground_height, &pitch_angle)) {
115 AERROR << "Failed to query camera to ground height and pitch.";
116 return -1;
117 }
118
119 FILE *file_save = fopen(out_path.data(), "wt");
120 if (file_save == nullptr) {
121 AERROR << "Failed to open output path: " << out_path.data();
122 return -1;
123 }
124 fprintf(file_save, "camera_ground_height:\t%f\n", camera_ground_height);
125 fprintf(file_save, "pitch_angle:\t%f\n", pitch_angle);
126 fclose(file_save);
127 return 0;
128}
129} // namespace camera
130} // namespace perception
131} // namespace apollo
virtual bool QueryCameraToGroundHeightAndPitchAngle(float *height, float *pitch) const
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
int WriteCalibrationOutput(bool enabled, const std::string &out_path, const CameraFrame *frame)
int WriteLanelines(const bool enabled, const std::string &save_path, const std::vector< base::LaneLine > &lane_objects)
Definition debug_info.cc:28
class register implement
Definition arena_queue.h:37
BaseCalibrationService * calibration_service