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/mime_types.hpp>
21#include <viam/sdk/common/proto_value.hpp>
22#include <viam/sdk/common/utils.hpp>
23#include <viam/sdk/config/resource.hpp>
24#include <viam/sdk/resource/resource_api.hpp>
25
26namespace viam {
27namespace sdk {
28
35class Camera : public Component {
36 public:
40 int width_px;
41 int height_px;
42 double focal_x_px;
43 double focal_y_px;
44 double center_x_px;
45 double center_y_px;
46 };
47
54
58 std::string model;
59 std::vector<double> parameters;
60 };
61
63 using mime_types = std::vector<std::string>;
64
86
89 // TODO: update documentation to show how to deserialize a `point_cloud`
90 struct point_cloud {
91 std::string mime_type;
92 std::vector<unsigned char> pc;
93 };
94
95 const static std::string lazy_suffix;
96
99 // TODO: update documentaiton to show how to deserialize a `raw_image`
100 struct raw_image {
101 std::string mime_type;
102 std::vector<unsigned char> bytes;
103 std::string source_name;
104 };
105
109 std::vector<raw_image> images;
110 response_metadata metadata;
111 };
112
120 using depth_map = xt::xarray<uint16_t>;
121
138 static std::vector<unsigned char> encode_depth_map(const Camera::depth_map& m);
139
149 static Camera::depth_map decode_depth_map(const std::vector<unsigned char>& data);
150
152 static std::string normalize_mime_type(const std::string& str);
153
157 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
158
161 virtual ProtoStruct get_status() = 0;
162
167 return get_images({}, {});
168 }
169
175 inline image_collection get_images(std::vector<std::string> filter_source_names) {
176 return get_images(std::move(filter_source_names), {});
177 }
178
185 virtual image_collection get_images(std::vector<std::string> filter_source_names,
186 const ProtoStruct& extra) = 0;
187
191 inline point_cloud get_point_cloud(std::string mime_type) {
192 return get_point_cloud(std::move(mime_type), {});
193 }
194
199 virtual point_cloud get_point_cloud(std::string mime_type, const ProtoStruct& extra) = 0;
200
203 inline std::vector<GeometryConfig> get_geometries() {
204 return get_geometries({});
205 }
206
210 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
211
215
216 API api() const override;
217
218 protected:
219 explicit Camera(std::string name);
220};
221
222template <>
224 static API api();
225};
226
227bool operator==(const Camera::raw_image& lhs, const Camera::raw_image& rhs);
228bool operator==(const Camera::image_collection& lhs, const Camera::image_collection& rhs);
229bool operator==(const Camera::point_cloud& lhs, const Camera::point_cloud& rhs);
230bool operator==(const Camera::intrinsic_parameters& lhs, const Camera::intrinsic_parameters& rhs);
231bool operator==(const Camera::extrinsic_parameters& lhs, const Camera::extrinsic_parameters& rhs);
232bool operator==(const Camera::distortion_parameters& lhs, const Camera::distortion_parameters& rhs);
233bool operator==(const Camera::properties& lhs, const Camera::properties& rhs);
234
235} // namespace sdk
236} // namespace viam
Definition resource_api.hpp:21
A Camera represents any physical hardware that can capture frames.
Definition camera.hpp:35
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:175
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:203
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:191
image_collection get_images()
Get the next images from the camera as a vector of raw images with names and metadata.
Definition camera.hpp:166
virtual ProtoStruct get_status()=0
Get the status of the camera.
std::vector< std::string > mime_types
The supported mime types of the camera— a type alias.
Definition camera.hpp:63
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:57
ExtrinsicParameters define the position of the camera relative to a reference frame (the world or ano...
Definition camera.hpp:50
a collection of images that were collected from a camera all at the same time.
Definition camera.hpp:108
The points and mime type of a point cloud.
Definition camera.hpp:90
The camera's supported features and settings.
Definition camera.hpp:67
bool supports_pcd
Indicates whether the camera has a valid implementation of get_point_cloud.
Definition camera.hpp:69
float frame_rate
Contains the camera's frame rate.
Definition camera.hpp:84
Camera::mime_types mime_types
Contains the mime types the camera supports.
Definition camera.hpp:81
the raw bytes, mime type of an image, and name of the source that produced it.
Definition camera.hpp:100
Definition linear_algebra.hpp:25
Definition orientation_types.hpp:37
Definition utils.hpp:43
Definition orientation_types.hpp:45