Viam C++ SDK current
Loading...
Searching...
No Matches
camera.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <bitset>
7#include <chrono>
8#include <string>
9#include <vector>
10
11#include <boost/endian/conversion.hpp>
12
13#if defined(__has_include) && (__has_include(<xtensor/containers/xarray.hpp>))
14#include <xtensor/containers/xarray.hpp>
15#else
16#include <xtensor/xarray.hpp>
17#endif
18
19#include <viam/sdk/common/linear_algebra.hpp>
20#include <viam/sdk/common/proto_value.hpp>
21#include <viam/sdk/common/utils.hpp>
22#include <viam/sdk/config/resource.hpp>
23#include <viam/sdk/resource/resource_api.hpp>
24
25namespace viam {
26namespace sdk {
27
34class Camera : public Component {
35 public:
39 int width_px;
40 int height_px;
41 double focal_x_px;
42 double focal_y_px;
43 double center_x_px;
44 double center_y_px;
45 };
46
53
57 std::string model;
58 std::vector<double> parameters;
59 };
60
62 using mime_types = std::vector<std::string>;
63
85
88 // TODO: update documentation to show how to deserialize a `point_cloud`
89 struct point_cloud {
90 std::string mime_type;
91 std::vector<unsigned char> pc;
92 };
93
94 const static std::string lazy_suffix;
95
98 // TODO: update documentaiton to show how to deserialize a `raw_image`
99 struct raw_image {
100 std::string mime_type;
101 std::vector<unsigned char> bytes;
102 std::string source_name;
103 };
104
108 std::vector<raw_image> images;
109 response_metadata metadata;
110 };
111
119 using depth_map = xt::xarray<uint16_t>;
120
137 static std::vector<unsigned char> encode_depth_map(const Camera::depth_map& m);
138
148 static Camera::depth_map decode_depth_map(const std::vector<unsigned char>& data);
149
151 static std::string normalize_mime_type(const std::string& str);
152
156 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
157
162 return get_images({}, {});
163 }
164
170 inline image_collection get_images(std::vector<std::string> filter_source_names) {
171 return get_images(std::move(filter_source_names), {});
172 }
173
180 virtual image_collection get_images(std::vector<std::string> filter_source_names,
181 const ProtoStruct& extra) = 0;
182
186 inline point_cloud get_point_cloud(std::string mime_type) {
187 return get_point_cloud(std::move(mime_type), {});
188 }
189
194 virtual point_cloud get_point_cloud(std::string mime_type, const ProtoStruct& extra) = 0;
195
198 inline std::vector<GeometryConfig> get_geometries() {
199 return get_geometries({});
200 }
201
205 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
206
210
211 API api() const override;
212
213 protected:
214 explicit Camera(std::string name);
215};
216
217template <>
219 static API api();
220};
221
222bool operator==(const Camera::raw_image& lhs, const Camera::raw_image& rhs);
223bool operator==(const Camera::image_collection& lhs, const Camera::image_collection& rhs);
224bool operator==(const Camera::point_cloud& lhs, const Camera::point_cloud& rhs);
225bool operator==(const Camera::intrinsic_parameters& lhs, const Camera::intrinsic_parameters& rhs);
226bool operator==(const Camera::extrinsic_parameters& lhs, const Camera::extrinsic_parameters& rhs);
227bool operator==(const Camera::distortion_parameters& lhs, const Camera::distortion_parameters& rhs);
228bool operator==(const Camera::properties& lhs, const Camera::properties& rhs);
229
230} // namespace sdk
231} // namespace viam
Definition resource_api.hpp:21
A Camera represents any physical hardware that can capture frames.
Definition camera.hpp:34
virtual std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra)=0
Returns GeometryConfigs associated with the calling camera.
static Camera::depth_map decode_depth_map(const std::vector< unsigned char > &data)
API api() const override
Returns the API associated with a particular resource.
virtual properties get_properties()=0
Get the camera's properties.
image_collection get_images(std::vector< std::string > filter_source_names)
Get the next images from specific sources as a vector of raw images with names and metadata.
Definition camera.hpp:170
virtual point_cloud get_point_cloud(std::string mime_type, const ProtoStruct &extra)=0
Get the next point_cloud from the camera.
virtual image_collection get_images(std::vector< std::string > filter_source_names, const ProtoStruct &extra)=0
Get the next images from the camera as a vector of raw images with names and metadata.
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling camera.
Definition camera.hpp:198
static std::vector< unsigned char > encode_depth_map(const Camera::depth_map &m)
point_cloud get_point_cloud(std::string mime_type)
Get the next point_cloud from the camera.
Definition camera.hpp:186
image_collection get_images()
Get the next images from the camera as a vector of raw images with names and metadata.
Definition camera.hpp:161
std::vector< std::string > mime_types
The supported mime types of the camera— a type alias.
Definition camera.hpp:62
static std::string normalize_mime_type(const std::string &str)
remove any extra suffix's from the mime type string.
virtual ProtoStruct do_command(const ProtoStruct &command)=0
Send/receive arbitrary commands to the resource.
Definition component.hpp:10
virtual std::string name() const
Return the resource's name.
Represents the dimensions and depth values of a depth map.
Definition resource_api.hpp:46
The distortion parameters of the camera.
Definition camera.hpp:56
ExtrinsicParameters define the position of the camera relative to a reference frame (the world or ano...
Definition camera.hpp:49
a collection of images that were collected from a camera all at the same time.
Definition camera.hpp:107
The points and mime type of a point cloud.
Definition camera.hpp:89
The camera's supported features and settings.
Definition camera.hpp:66
bool supports_pcd
Indicates whether the camera has a valid implementation of get_point_cloud.
Definition camera.hpp:68
float frame_rate
Contains the camera's frame rate.
Definition camera.hpp:83
Camera::mime_types mime_types
Contains the mime types the camera supports.
Definition camera.hpp:80
the raw bytes, mime type of an image, and name of the source that produced it.
Definition camera.hpp:99
Definition linear_algebra.hpp:25
Definition orientation_types.hpp:37
Definition utils.hpp:43
Definition orientation_types.hpp:45