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 = 0;
41 int height_px = 0;
42 double focal_x_px = 0.0;
43 double focal_y_px = 0.0;
44 double center_x_px = 0.0;
45 double center_y_px = 0.0;
46 };
47
54
58 std::string model;
59 std::vector<double> parameters;
60 };
61
63 using mime_types = std::vector<std::string>;
64
91
94 // TODO: update documentation to show how to deserialize a `point_cloud`
95 struct point_cloud {
96 std::string mime_type;
97 std::vector<unsigned char> pc;
98 };
99
100 const static std::string lazy_suffix;
101
104 // TODO: update documentaiton to show how to deserialize a `raw_image`
105 struct raw_image {
106 std::string mime_type;
107 std::vector<unsigned char> bytes;
108 std::string source_name;
109 };
110
114 std::vector<raw_image> images;
115 response_metadata metadata;
116 };
117
125 using depth_map = xt::xarray<uint16_t>;
126
143 static std::vector<unsigned char> encode_depth_map(const Camera::depth_map& m);
144
154 static Camera::depth_map decode_depth_map(const std::vector<unsigned char>& data);
155
157 static std::string normalize_mime_type(const std::string& str);
158
162 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
163
166 virtual ProtoStruct get_status() = 0;
167
172 return get_images({}, {});
173 }
174
180 inline image_collection get_images(std::vector<std::string> filter_source_names) {
181 return get_images(std::move(filter_source_names), {});
182 }
183
190 virtual image_collection get_images(std::vector<std::string> filter_source_names,
191 const ProtoStruct& extra) = 0;
192
196 inline point_cloud get_point_cloud(std::string mime_type) {
197 return get_point_cloud(std::move(mime_type), {});
198 }
199
204 virtual point_cloud get_point_cloud(std::string mime_type, const ProtoStruct& extra) = 0;
205
208 inline std::vector<GeometryConfig> get_geometries() {
209 return get_geometries({});
210 }
211
215 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
216
220
221 API api() const override;
222
223 protected:
224 explicit Camera(std::string name);
225};
226
227template <>
229 static API api();
230};
231
232bool operator==(const Camera::raw_image& lhs, const Camera::raw_image& rhs);
233bool operator==(const Camera::image_collection& lhs, const Camera::image_collection& rhs);
234bool operator==(const Camera::point_cloud& lhs, const Camera::point_cloud& rhs);
235bool operator==(const Camera::intrinsic_parameters& lhs, const Camera::intrinsic_parameters& rhs);
236bool operator==(const Camera::extrinsic_parameters& lhs, const Camera::extrinsic_parameters& rhs);
237bool operator==(const Camera::distortion_parameters& lhs, const Camera::distortion_parameters& rhs);
238bool operator==(const Camera::properties& lhs, const Camera::properties& rhs);
239
240} // namespace sdk
241} // 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:180
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:208
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:196
image_collection get_images()
Get the next images from the camera as a vector of raw images with names and metadata.
Definition camera.hpp:171
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:113
The points and mime type of a point cloud.
Definition camera.hpp:95
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
std::string default_reference_frame
Name of the reference frame that points from get_point_cloud are expressed in. An empty string means ...
Definition camera.hpp:89
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:105
Definition linear_algebra.hpp:25
Definition orientation_types.hpp:37
Definition utils.hpp:43
Definition orientation_types.hpp:45