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#include <xtensor/xarray.hpp>
13
14#include <viam/sdk/common/proto_value.hpp>
15#include <viam/sdk/common/utils.hpp>
16#include <viam/sdk/config/resource.hpp>
17#include <viam/sdk/resource/resource_api.hpp>
18
19namespace viam {
20namespace sdk {
21
28class Camera : public Component {
29 public:
33 int width_px;
34 int height_px;
35 double focal_x_px;
36 double focal_y_px;
37 double center_x_px;
38 double center_y_px;
39 };
40
44 std::string model;
45 std::vector<double> parameters;
46 };
47
49 using mime_types = std::vector<std::string>;
50
69
72 // TODO: update documentation to show how to deserialize a `point_cloud`
73 struct point_cloud {
74 std::string mime_type;
75 std::vector<unsigned char> pc;
76 };
77
78 const static std::string lazy_suffix;
79
82 // TODO: update documentaiton to show how to deserialize a `raw_image`
83 struct raw_image {
84 std::string mime_type;
85 std::vector<unsigned char> bytes;
86 std::string source_name;
87 };
88
92 std::vector<raw_image> images;
93 response_metadata metadata;
94 };
95
103 using depth_map = xt::xarray<uint16_t>;
104
121 static std::vector<unsigned char> encode_depth_map(const Camera::depth_map& m);
122
132 static Camera::depth_map decode_depth_map(const std::vector<unsigned char>& data);
133
135 static std::string normalize_mime_type(const std::string& str);
136
140 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
141
145 inline raw_image get_image(std::string mime_type) {
146 return get_image(std::move(mime_type), {});
147 }
148
153 virtual raw_image get_image(std::string mime_type, const ProtoStruct& extra) = 0;
154
159
163 inline point_cloud get_point_cloud(std::string mime_type) {
164 return get_point_cloud(std::move(mime_type), {});
165 }
166
171 virtual point_cloud get_point_cloud(std::string mime_type, const ProtoStruct& extra) = 0;
172
175 inline std::vector<GeometryConfig> get_geometries() {
176 return get_geometries({});
177 }
178
182 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
183
187
188 API api() const override;
189
190 protected:
191 explicit Camera(std::string name);
192};
193
194template <>
196 static API api();
197};
198
199bool operator==(const Camera::raw_image& lhs, const Camera::raw_image& rhs);
200bool operator==(const Camera::image_collection& lhs, const Camera::image_collection& rhs);
201bool operator==(const Camera::point_cloud& lhs, const Camera::point_cloud& rhs);
202bool operator==(const Camera::intrinsic_parameters& lhs, const Camera::intrinsic_parameters& rhs);
203bool operator==(const Camera::distortion_parameters& lhs, const Camera::distortion_parameters& rhs);
204bool operator==(const Camera::properties& lhs, const Camera::properties& rhs);
205
206} // namespace sdk
207} // namespace viam
Extends APIType to additionally define a resource's subtype (e.g., camera).
Definition resource_api.hpp:33
A Camera represents any physical hardware that can capture frames.
Definition camera.hpp:28
virtual std::vector< GeometryConfig > get_geometries(const ProtoStruct &extra)=0
Returns GeometryConfigs associated with the calling camera.
raw_image get_image(std::string mime_type)
Get the next image from the camera as a raw image.
Definition camera.hpp:145
static Camera::depth_map decode_depth_map(const std::vector< unsigned char > &data)
virtual image_collection get_images()=0
Get the next images from the camera as a vector of raw images with names and metadata.
API api() const override
Returns the API associated with a particular resource.
virtual properties get_properties()=0
Get the camera's properties.
virtual point_cloud get_point_cloud(std::string mime_type, const ProtoStruct &extra)=0
Get the next point_cloud from the camera.
virtual raw_image get_image(std::string mime_type, const ProtoStruct &extra)=0
Get the next image from the camera as a raw image.
std::vector< GeometryConfig > get_geometries()
Returns GeometryConfigs associated with the calling camera.
Definition camera.hpp:175
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:163
std::vector< std::string > mime_types
The supported mime types of the camera— a type alias.
Definition camera.hpp:49
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:50
The distortion parameters of the camera.
Definition camera.hpp:43
a collection of images that were collected from a camera all at the same time.
Definition camera.hpp:91
The points and mime type of a point cloud.
Definition camera.hpp:73
The camera's supported features and settings.
Definition camera.hpp:53
bool supports_pcd
Indicates whether the camera has a valid implementation of get_point_cloud.
Definition camera.hpp:55
float frame_rate
Contains the camera's frame rate.
Definition camera.hpp:67
Camera::mime_types mime_types
Contains the mime types the camera supports.
Definition camera.hpp:64
the raw bytes, mime type of an image, and name of the source that produced it.
Definition camera.hpp:83
Definition utils.hpp:21