|
3 | 3 | #include <google/protobuf/descriptor.h> |
4 | 4 | #include <google/protobuf/util/time_util.h> |
5 | 5 |
|
6 | | -#include <viam/api/common/v1/common.pb.h> |
7 | | -#include <viam/api/component/camera/v1/camera.grpc.pb.h> |
8 | | -#include <viam/api/component/camera/v1/camera.pb.h> |
9 | | - |
10 | 6 | #include <viam/sdk/common/exception.hpp> |
11 | 7 | #include <viam/sdk/common/utils.hpp> |
12 | 8 | #include <viam/sdk/resource/resource.hpp> |
@@ -134,127 +130,6 @@ std::string Camera::normalize_mime_type(const std::string& str) { |
134 | 130 | return mime_type; |
135 | 131 | } |
136 | 132 |
|
137 | | -std::string Camera::format_to_MIME_string(viam::component::camera::v1::Format format) { |
138 | | - switch (format) { |
139 | | - case viam::component::camera::v1::FORMAT_RAW_RGBA: |
140 | | - return "image/vnd.viam.rgba"; |
141 | | - case viam::component::camera::v1::FORMAT_RAW_DEPTH: |
142 | | - return "image/vnd.viam.dep"; |
143 | | - case viam::component::camera::v1::FORMAT_JPEG: |
144 | | - return "image/jpeg"; |
145 | | - case viam::component::camera::v1::FORMAT_PNG: |
146 | | - return "image/png"; |
147 | | - default: |
148 | | - return ""; |
149 | | - } |
150 | | -} |
151 | | - |
152 | | -::viam::component::camera::v1::Format Camera::MIME_string_to_format( |
153 | | - const std::string& mime_string) { |
154 | | - if (mime_string == "image/vnd.viam.rgba") { |
155 | | - return viam::component::camera::v1::FORMAT_RAW_RGBA; |
156 | | - } |
157 | | - if (mime_string == "image/vnd.viam.dep") { |
158 | | - return viam::component::camera::v1::FORMAT_RAW_DEPTH; |
159 | | - } |
160 | | - if (mime_string == "image/jpeg") { |
161 | | - return viam::component::camera::v1::FORMAT_JPEG; |
162 | | - } |
163 | | - if (mime_string == "image/png") { |
164 | | - return viam::component::camera::v1::FORMAT_PNG; |
165 | | - } |
166 | | - return viam::component::camera::v1::FORMAT_UNSPECIFIED; |
167 | | -} |
168 | | - |
169 | | -Camera::raw_image Camera::from_proto(const viam::component::camera::v1::GetImageResponse& proto) { |
170 | | - Camera::raw_image raw_image; |
171 | | - std::string img_string = proto.image(); |
172 | | - const std::vector<unsigned char> bytes(img_string.begin(), img_string.end()); |
173 | | - raw_image.bytes = bytes; |
174 | | - raw_image.mime_type = proto.mime_type(); |
175 | | - raw_image.source_name = ""; |
176 | | - return raw_image; |
177 | | -} |
178 | | - |
179 | | -Camera::image_collection Camera::from_proto( |
180 | | - const viam::component::camera::v1::GetImagesResponse& proto) { |
181 | | - Camera::image_collection image_collection; |
182 | | - std::vector<Camera::raw_image> images; |
183 | | - for (const auto& img : proto.images()) { |
184 | | - Camera::raw_image raw_image; |
185 | | - std::string img_string = img.image(); |
186 | | - const std::vector<unsigned char> bytes(img_string.begin(), img_string.end()); |
187 | | - raw_image.bytes = bytes; |
188 | | - raw_image.mime_type = format_to_MIME_string(img.format()); |
189 | | - raw_image.source_name = img.source_name(); |
190 | | - images.push_back(raw_image); |
191 | | - } |
192 | | - image_collection.images = std::move(images); |
193 | | - image_collection.metadata = response_metadata::from_proto(proto.response_metadata()); |
194 | | - return image_collection; |
195 | | -} |
196 | | - |
197 | | -Camera::point_cloud Camera::from_proto( |
198 | | - const viam::component::camera::v1::GetPointCloudResponse& proto) { |
199 | | - Camera::point_cloud point_cloud; |
200 | | - std::string pc_string = proto.point_cloud(); |
201 | | - const std::vector<unsigned char> bytes(pc_string.begin(), pc_string.end()); |
202 | | - point_cloud.pc = bytes; |
203 | | - point_cloud.mime_type = proto.mime_type(); |
204 | | - return point_cloud; |
205 | | -} |
206 | | - |
207 | | -Camera::intrinsic_parameters Camera::from_proto( |
208 | | - const viam::component::camera::v1::IntrinsicParameters& proto) { |
209 | | - Camera::intrinsic_parameters params; |
210 | | - // NOLINTNEXTLINE(bugprone-narrowing-conversions) |
211 | | - params.width_px = proto.width_px(); |
212 | | - // NOLINTNEXTLINE(bugprone-narrowing-conversions) |
213 | | - params.height_px = proto.height_px(); |
214 | | - params.focal_x_px = proto.focal_x_px(); |
215 | | - params.focal_y_px = proto.focal_y_px(); |
216 | | - params.center_x_px = proto.center_x_px(); |
217 | | - params.center_y_px = proto.center_y_px(); |
218 | | - return params; |
219 | | -} |
220 | | - |
221 | | -Camera::distortion_parameters Camera::from_proto( |
222 | | - const viam::component::camera::v1::DistortionParameters& proto) { |
223 | | - Camera::distortion_parameters params; |
224 | | - params.model = proto.model(); |
225 | | - params.parameters = {proto.parameters().begin(), proto.parameters().end()}; |
226 | | - return params; |
227 | | -} |
228 | | - |
229 | | -Camera::properties Camera::from_proto( |
230 | | - const viam::component::camera::v1::GetPropertiesResponse& proto) { |
231 | | - return {proto.supports_pcd(), |
232 | | - from_proto(proto.intrinsic_parameters()), |
233 | | - from_proto(proto.distortion_parameters()), |
234 | | - {proto.mime_types().begin(), proto.mime_types().end()}, |
235 | | - (proto.frame_rate())}; |
236 | | -} |
237 | | - |
238 | | -viam::component::camera::v1::IntrinsicParameters Camera::to_proto( |
239 | | - const Camera::intrinsic_parameters& params) { |
240 | | - viam::component::camera::v1::IntrinsicParameters proto; |
241 | | - proto.set_width_px(params.width_px); |
242 | | - proto.set_height_px(params.height_px); |
243 | | - proto.set_focal_x_px(params.focal_x_px); |
244 | | - proto.set_focal_y_px(params.focal_y_px); |
245 | | - proto.set_center_x_px(params.center_x_px); |
246 | | - proto.set_center_y_px(params.center_y_px); |
247 | | - return proto; |
248 | | -} |
249 | | - |
250 | | -viam::component::camera::v1::DistortionParameters Camera::to_proto( |
251 | | - const Camera::distortion_parameters& params) { |
252 | | - viam::component::camera::v1::DistortionParameters proto; |
253 | | - *proto.mutable_model() = params.model; |
254 | | - *proto.mutable_parameters() = {params.parameters.begin(), params.parameters.end()}; |
255 | | - return proto; |
256 | | -} |
257 | | - |
258 | 133 | Camera::Camera(std::string name) : Component(std::move(name)){}; |
259 | 134 |
|
260 | 135 | bool operator==(const Camera::point_cloud& lhs, const Camera::point_cloud& rhs) { |
|
0 commit comments