Apollo 10.0
自动驾驶开放平台
data_provider.h
浏览该文件的文档.
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 *****************************************************************************/
16#pragma once
17
18#include <memory>
19#include <string>
20
25
26namespace apollo {
27namespace perception {
28namespace camera {
29
31 public:
32 struct InitOptions {
34 : image_height(0),
35 image_width(0),
36 device_id(-1),
37 do_undistortion(false) {}
38
43 std::string sensor_name;
44 };
45
46 struct ImageOptions {
49 this->do_crop = false;
50 }
51
53 this->target_color = target_color;
54 this->do_crop = do_crop;
55 this->crop_roi = crop_roi;
56 }
57
58 std::string ToString() {
59 std::stringstream ss;
60 ss << " " << static_cast<int>(target_color);
61 ss << " " << do_crop;
62 if (do_crop) {
63 ss << " " << crop_roi.x << " " << crop_roi.y << " " << crop_roi.width
64 << " " << crop_roi.height;
65 }
66 return ss.str();
67 }
68
70 bool do_crop = false; // default: DONOT crop
72 };
73
74 DataProvider() = default;
75 ~DataProvider() = default;
76
77 DataProvider(const DataProvider &) = delete;
79
80 bool Init(const InitOptions &options = InitOptions());
81
82 // @brief: fill raw image data.
83 // @param [in]: options
84 // @param [in/out]: blob
85 // image blob with specified size should be filled, required.
86 bool FillImageData(int rows, int cols, const uint8_t *data,
87 const std::string &encoding);
88
89#if 0
90 // @brief: get blob converted from raw message.
91 // @param [in]: options
92 // @param [in/out]: NHWC blob (4D)
93 // image blob with specified size should be filled, required.
94 bool GetImageBlob(const ImageOptions &options, base::Blob<float> *blob);
95#endif
96
97 // @brief: get blob converted from raw message.
98 // @param [in]: options
99 // @param [in/out]: NHWC blob (4D)
100 // image blob with specified size should be filled, required.
101 bool GetImageBlob(const ImageOptions &options, base::Blob<uint8_t> *blob);
102
103 // @brief: get Image8U converted from raw message.
104 // @param [in]: options
105 // @return: Image8U
106 // image blob with specified size should be filled, required.
107 bool GetImage(const ImageOptions &options, base::Image8U *image);
108
109 int src_height() const { return src_height_; }
110 int src_width() const { return src_width_; }
111 const std::string &sensor_name() const { return sensor_name_; }
112
113 bool to_gray_image();
114 bool to_rgb_image();
115 bool to_bgr_image();
116
117 protected:
118 std::string sensor_name_;
119 int src_height_ = 0;
120 int src_width_ = 0;
121 int device_id_ = -1;
122
123 std::shared_ptr<base::Image8U> ori_gray_;
124 std::shared_ptr<base::Image8U> ori_rgb_;
125 std::shared_ptr<base::Image8U> ori_bgr_;
126 std::shared_ptr<base::Image8U> gray_;
127 std::shared_ptr<base::Image8U> rgb_;
128 std::shared_ptr<base::Image8U> bgr_;
129 bool gray_ready_ = false;
130 bool rgb_ready_ = false;
131 bool bgr_ready_ = false;
132
135 std::shared_ptr<UndistortionHandler> handler_ = nullptr;
136}; // class DataProvider
137
138} // namespace camera
139} // namespace perception
140} // namespace apollo
A wrapper around SyncedMemory holders serving as the basic computational unit for images,...
Definition blob.h:88
A wrapper around Blob holders serving as the basic computational unit for images.
Definition image_8u.h:44
bool Init(const InitOptions &options=InitOptions())
std::shared_ptr< base::Image8U > ori_gray_
std::shared_ptr< base::Image8U > gray_
bool GetImageBlob(const ImageOptions &options, base::Blob< uint8_t > *blob)
std::shared_ptr< base::Image8U > ori_bgr_
std::shared_ptr< base::Image8U > bgr_
std::shared_ptr< base::Image8U > ori_rgb_
bool GetImage(const ImageOptions &options, base::Image8U *image)
std::shared_ptr< UndistortionHandler > handler_
std::shared_ptr< base::Image8U > rgb_
DataProvider & operator=(const DataProvider &)=delete
DataProvider(const DataProvider &)=delete
bool FillImageData(int rows, int cols, const uint8_t *data, const std::string &encoding)
const std::string & sensor_name() const
class register implement
Definition arena_queue.h:37
ImageOptions(base::Color target_color, bool do_crop, base::RectI crop_roi)