Apollo 10.0
自动驾驶开放平台
util.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 <fstream>
20
21#include "cyber/common/log.h"
23
24namespace apollo {
25namespace perception {
26namespace camera {
27
28bool FillImage(onboard::CameraFrame* frame, const std::string& file_name) {
29 // Read image from file_name
30 cv::Mat image = cv::imread(file_name);
31 if (image.empty()) {
32 AERROR << "Read image failed! " << file_name;
33 return false;
34 }
35
36 // Fill image to frame->data_provider
37 bool res = frame->data_provider->FillImageData(image.rows, image.cols,
38 image.data, "bgr8");
39 if (!res) {
40 AERROR << "Fill image failed! " << file_name;
41 return false;
42 }
43 return true;
44}
45
46bool RecoveryImage(onboard::CameraFrame* frame, cv::Mat* cv_img) {
47 DataProvider::ImageOptions image_options;
48 image_options.target_color = base::Color::BGR;
49 image_options.do_crop = false;
50 base::Image8U image(frame->data_provider->src_height(),
51 frame->data_provider->src_width(), base::Color::RGB);
52 frame->data_provider->GetImage(image_options, &image);
53
54 memcpy(cv_img->data, image.cpu_data(), image.total() * sizeof(uint8_t));
55 return true;
56}
57
58bool GetFileListFromPath(const std::string& file_path,
59 std::vector<std::string>* file_list) {
60 // todo(zero): need complete
61 return true;
62}
63
64bool GetFileListFromFile(const std::string& file_name,
65 std::vector<std::string>* file_list) {
66 std::ifstream in(file_name.c_str());
67
68 if (!in) {
69 AERROR << "Failed to open file: " << file_name;
70 return false;
71 }
72
73 std::string line;
74 while (std::getline(in, line)) {
75 if (!line.empty()) {
76 file_list->push_back(line);
77 }
78 }
79
80 in.close();
81 return true;
82}
83
85 const std::string& file_name) {
86 FILE* fp = fopen(file_name.c_str(), "w");
87 if (fp == nullptr) {
88 AERROR << "Failed to open result file: " << file_name;
89 return false;
90 }
91
92 for (auto obj : frame->detected_objects) {
93 auto& supp = obj->camera_supplement;
94 fprintf(fp,
95 "%s 0 0 %6.3f %8.2f %8.2f %8.2f %8.2f %6.3f %6.3f %6.3f "
96 "%6.3f %6.3f %6.3f %6.3f %6.3f "
97 "%4d %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f %6.3f\n",
98 base::kSubType2NameMap.at(obj->sub_type).c_str(), supp.alpha,
99 supp.box.xmin, supp.box.ymin, supp.box.xmax, supp.box.ymax,
100 obj->size[2], obj->size[1], obj->size[0], obj->center[0],
101 obj->center[1] + obj->size[2] * .5, obj->center[2],
102 supp.alpha + atan2(obj->center[0], obj->center[2]),
103 obj->type_probs[static_cast<int>(obj->type)], supp.area_id,
104 supp.visible_ratios[0], supp.visible_ratios[1],
105 supp.visible_ratios[2], supp.visible_ratios[3],
106 supp.cut_off_ratios[0], supp.cut_off_ratios[1],
107 supp.cut_off_ratios[2], supp.cut_off_ratios[3]);
108 }
109
110 fclose(fp);
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
A wrapper around Blob holders serving as the basic computational unit for images.
Definition image_8u.h:44
const uint8_t * cpu_data() const
Definition image_8u.h:99
#define AERROR
Definition log.h:44
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 FillImage(onboard::CameraFrame *frame, const std::string &file_name)
Read image from file_name and fill in frame->data_provider
Definition util.cc:28
bool SaveLaneDetectionResult(onboard::CameraFrame *frame, const std::string &file_name)
Definition util.cc:119
bool GetFileListFromPath(const std::string &file_path, std::vector< std::string > *file_list)
Get the File List From Path object
Definition util.cc:58
bool GetFileListFromFile(const std::string &file_name, std::vector< std::string > *file_list)
Get the File List From File object
Definition util.cc:64
bool SaveTfDetectionResult(onboard::CameraFrame *frame, const std::string &file_name)
Definition util.cc:114
bool SaveCameraDetectionResult(onboard::CameraFrame *frame, const std::string &file_name)
Save detection result to file_name
Definition util.cc:84
class register implement
Definition arena_queue.h:37
std::shared_ptr< camera::DataProvider > data_provider