Apollo 10.0
自动驾驶开放平台
ground_truth.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#include <map>
24
25#include "cyber/common/log.h"
26
27namespace apollo {
28namespace perception {
29namespace camera {
30
31const std::map<std::string, base::ObjectSubType> object_subtype_map = {
37 {"motorcyclist", base::ObjectSubType::MOTORCYCLIST},
38 {"tricyclelist", base::ObjectSubType::TRICYCLIST},
39 {"pedestrian", base::ObjectSubType::PEDESTRIAN},
40 {"trafficcone", base::ObjectSubType::TRAFFICCONE},
41};
42
43bool LoadKittiLabel(onboard::CameraFrame* frame, const std::string& kitti_path,
44 const std::string& dist_type) {
45 frame->detected_objects.clear();
46 FILE *fp = fopen(kitti_path.c_str(), "r");
47 if (fp == nullptr) {
48 AERROR << "Failed to load object file: " << kitti_path;
49 return false;
50 }
51
52 while (!feof(fp)) {
53 base::ObjectPtr obj = nullptr;
54 obj.reset(new base::Object);
55 float trash = 0.0f;
56 float score = 0.0f;
57 char type[255];
58 float x1 = 0.0f;
59 float y1 = 0.0f;
60 float x2 = 0.0f;
61 float y2 = 0.0f;
62 memset(type, 0, sizeof(type));
63
64 int ret = 0;
65 ret = fscanf(fp, "%254s %f %f %lf %f %f %f %f %f %f %f %lf %lf %lf %f %f",
66 type, &trash, &trash, &obj->camera_supplement.alpha, &x1, &y1,
67 &x2, &y2, &obj->size[2], &obj->size[1], &obj->size[0],
68 &obj->center[0], &obj->center[1], &obj->center[2], &obj->theta,
69 &score);
70 AINFO << "fscanf return: " << ret;
71 if (dist_type == "H-from-h") {
72 obj->size[0] = static_cast<float>(obj->center[2]);
73 } else if (dist_type == "H-on-h") {
74 obj->size[0] = static_cast<float>(obj->center[2]) * (y2 - y1);
75 } else {
76 AERROR << "Not supported dist type! " << dist_type;
77 return false;
78 }
79 obj->camera_supplement.box.xmin = std::max<float>(x1, 0);
80 obj->camera_supplement.box.ymin = std::max<float>(y1, 0);
81 obj->camera_supplement.box.xmax =
82 std::min<float>(
83 x2, static_cast<float>(frame->data_provider->src_width()));
84 obj->camera_supplement.box.ymax =
85 std::min<float>(
86 y2, static_cast<float>(frame->data_provider->src_height()));
87 obj->camera_supplement.area_id = 5;
88
89 if (object_subtype_map.find(type) == object_subtype_map.end()) {
90 obj->sub_type = base::ObjectSubType::UNKNOWN;
91 } else {
92 obj->sub_type = object_subtype_map.at(type);
93 }
94 obj->type = base::kSubType2TypeMap.at(obj->sub_type);
95 obj->type_probs.assign(
96 static_cast<int>(base::ObjectType::MAX_OBJECT_TYPE), 0);
97 obj->sub_type_probs.assign(
98 static_cast<int>(base::ObjectSubType::MAX_OBJECT_TYPE), 0);
99 obj->sub_type_probs[static_cast<int>(obj->sub_type)] = score;
100 obj->type_probs[static_cast<int>(obj->type)] = score;
101
102 frame->detected_objects.push_back(obj);
103 }
104
105 fclose(fp);
106 return true;
107}
108
109
110} // namespace camera
111} // namespace perception
112} // namespace apollo
#define AERROR
Definition log.h:44
#define AINFO
Definition log.h:42
const std::map< ObjectSubType, ObjectType > kSubType2TypeMap
ObjectSubType mapping
std::shared_ptr< Object > ObjectPtr
Definition object.h:127
bool LoadKittiLabel(onboard::CameraFrame *frame, const std::string &kitti_path, const std::string &dist_type)
Read KITTI labels and fill to frame->detected_objects
const std::map< std::string, base::ObjectSubType > object_subtype_map
class register implement
Definition arena_queue.h:37
std::shared_ptr< camera::DataProvider > data_provider