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/proto_value.hpp>
20#include <viam/sdk/common/utils.hpp>
21#include <viam/sdk/config/resource.hpp>
22#include <viam/sdk/resource/resource_api.hpp>
23
24namespace viam {
25namespace sdk {
26
33class Camera : public Component {
34 public:
38 int width_px;
39 int height_px;
40 double focal_x_px;
41 double focal_y_px;
42 double center_x_px;
43 double center_y_px;
44 };
45
49 std::string model;
50 std::vector<double> parameters;
51 };
52
54 using mime_types = std::vector<std::string>;
55
74
77 // TODO: update documentation to show how to deserialize a `point_cloud`
78 struct point_cloud {
79 std::string mime_type;
80 std::vector<unsigned char> pc;
81 };
82
83 const static std::string lazy_suffix;
84
87 // TODO: update documentaiton to show how to deserialize a `raw_image`
88 struct raw_image {
89 std::string mime_type;
90 std::vector<unsigned char> bytes;
91 std::string source_name;
92 };
93
97 std::vector<raw_image> images;
98 response_metadata metadata;
99 };
100
108 using depth_map = xt::xarray<uint16_t>;
109
126 static std::vector<unsigned char> encode_depth_map(const Camera::depth_map& m);
127
137 static Camera::depth_map decode_depth_map(const std::vector<unsigned char>& data);
138
140 static std::string normalize_mime_type(const std::string& str);
141
145 virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
146
150 inline raw_image get_image(std::string mime_type) {
151 return get_image(std::move(mime_type), {});
152 }
153
158 virtual raw_image get_image(std::string mime_type, const ProtoStruct& extra) = 0;
159
164
168 inline point_cloud get_point_cloud(std::string mime_type) {
169 return get_point_cloud(std::move(mime_type), {});
170 }
171
176 virtual point_cloud get_point_cloud(std::string mime_type, const ProtoStruct& extra) = 0;
177
180 inline std::vector<GeometryConfig> get_geometries() {
181 return get_geometries({});
182 }
183
187 virtual std::vector<GeometryConfig> get_geometries(const ProtoStruct& extra) = 0;
188
192
193 API api() const override;
194
195 protected:
196 explicit Camera(std::string name);
197};
198
199template <>
201 static API api();
202};
203
204bool operator==(const Camera::raw_image& lhs, const Camera::raw_image& rhs);
205bool operator==(const Camera::image_collection& lhs, const Camera::image_collection& rhs);
206bool operator==(const Camera::point_cloud& lhs, const Camera::point_cloud& rhs);
207bool operator==(const Camera::intrinsic_parameters& lhs, const Camera::intrinsic_parameters& rhs);
208bool operator==(const Camera::distortion_parameters& lhs, const Camera::distortion_parameters& rhs);
209bool operator==(const Camera::properties& lhs, const Camera::properties& rhs);
210
211} // namespace sdk
212} // namespace viam
Definition resource_api.hpp:21
A Camera represents any physical hardware that can capture frames.
Definition camera.hpp:33
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:150
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:180
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:168
std::vector< std::string > mime_types
The supported mime types of the camera— a type alias.
Definition camera.hpp:54
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:48
a collection of images that were collected from a camera all at the same time.
Definition camera.hpp:96
The points and mime type of a point cloud.
Definition camera.hpp:78
The camera's supported features and settings.
Definition camera.hpp:58
bool supports_pcd
Indicates whether the camera has a valid implementation of get_point_cloud.
Definition camera.hpp:60
float frame_rate
Contains the camera's frame rate.
Definition camera.hpp:72
Camera::mime_types mime_types
Contains the mime types the camera supports.
Definition camera.hpp:69
the raw bytes, mime type of an image, and name of the source that produced it.
Definition camera.hpp:88
Definition utils.hpp:43