Skip to content

Commit 01b01e0

Browse files
authored
RSDK-11727 — Remove get_image, render_frame, and format (#523)
1 parent 962c13b commit 01b01e0

File tree

8 files changed

+14
-128
lines changed

8 files changed

+14
-128
lines changed

src/viam/examples/camera/example_camera.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ int main() try {
5757
<< intrinsics.height_px;
5858

5959
std::string output_file("img.png");
60-
std::string image_mime_type("image/png");
6160

62-
VIAM_SDK_LOG(info) << "Getting image from camera ";
61+
VIAM_SDK_LOG(info) << "Getting images from camera ";
6362

64-
vs::Camera::raw_image img = camera->get_image(image_mime_type);
63+
vs::Camera::image_collection images = camera->get_images();
64+
vs::Camera::raw_image img = images.images[0];
6565

6666
VIAM_SDK_LOG(info) << "Got image of mime type: " << img.mime_type;
6767

src/viam/sdk/components/camera.hpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,6 @@ class Camera : public Component {
144144
/// @return The result of the executed command.
145145
virtual ProtoStruct do_command(const ProtoStruct& command) = 0;
146146

147-
/// @brief Get the next image from the camera as a raw image.
148-
/// @param mime_type the desired mime_type of the image (does not guarantee output type).
149-
/// @return The frame as a `raw_image`.
150-
inline raw_image get_image(std::string mime_type) {
151-
return get_image(std::move(mime_type), {});
152-
}
153-
154-
/// @brief Get the next image from the camera as a raw image.
155-
/// @param mime_type the desired mime_type of the image (does not guarantee output type).
156-
/// @param extra any additional arguments to the method.
157-
/// @return The frame as a `raw_image`.
158-
virtual raw_image get_image(std::string mime_type, const ProtoStruct& extra) = 0;
159-
160147
/// @brief Get the next images from the camera as a vector of raw images with names and
161148
/// metadata.
162149
/// @return a vector of raw_images and associated response metadata.

src/viam/sdk/components/private/camera_client.cpp

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,6 @@ namespace impl {
2323
using sdk::from_proto;
2424
using sdk::to_proto;
2525

26-
std::string format_to_MIME_string(viam::component::camera::v1::Format format) {
27-
switch (format) {
28-
case viam::component::camera::v1::FORMAT_RAW_RGBA:
29-
return "image/vnd.viam.rgba";
30-
case viam::component::camera::v1::FORMAT_RAW_DEPTH:
31-
return "image/vnd.viam.dep";
32-
case viam::component::camera::v1::FORMAT_JPEG:
33-
return "image/jpeg";
34-
case viam::component::camera::v1::FORMAT_PNG:
35-
return "image/png";
36-
default:
37-
return "";
38-
}
39-
}
40-
41-
Camera::raw_image from_proto(const viam::component::camera::v1::GetImageResponse& proto) {
42-
Camera::raw_image raw_image;
43-
std::string img_string = proto.image();
44-
const std::vector<unsigned char> bytes(img_string.begin(), img_string.end());
45-
raw_image.bytes = bytes;
46-
raw_image.mime_type = proto.mime_type();
47-
raw_image.source_name = "";
48-
return raw_image;
49-
}
50-
5126
Camera::image_collection from_proto(const viam::component::camera::v1::GetImagesResponse& proto) {
5227
Camera::image_collection image_collection;
5328
std::vector<Camera::raw_image> images;
@@ -56,13 +31,7 @@ Camera::image_collection from_proto(const viam::component::camera::v1::GetImages
5631
std::string img_string = img.image();
5732
const std::vector<unsigned char> bytes(img_string.begin(), img_string.end());
5833
raw_image.bytes = bytes;
59-
// TODO(RSDK-11733): This is a temporary fix to support handling both the format and mime
60-
// type. We will remove this once we remove the format field from the proto.
61-
if (!img.mime_type().empty()) {
62-
raw_image.mime_type = img.mime_type();
63-
} else {
64-
raw_image.mime_type = format_to_MIME_string(img.format());
65-
}
34+
raw_image.mime_type = img.mime_type();
6635
raw_image.source_name = img.source_name();
6736
images.push_back(raw_image);
6837
}
@@ -121,15 +90,6 @@ ProtoStruct CameraClient::do_command(const ProtoStruct& command) {
12190
.invoke([](auto& response) { return from_proto(response.result()); });
12291
};
12392

124-
Camera::raw_image CameraClient::get_image(std::string mime_type, const ProtoStruct& extra) {
125-
return make_client_helper(this, *stub_, &StubType::GetImage)
126-
.with(extra,
127-
[&](auto& request) {
128-
*request.mutable_mime_type() = Camera::normalize_mime_type(mime_type);
129-
})
130-
.invoke([](auto& response) { return from_proto(response); });
131-
};
132-
13393
Camera::image_collection CameraClient::get_images(std::vector<std::string> filter_source_names,
13494
const ProtoStruct& extra) {
13595
return make_client_helper(this, *stub_, &StubType::GetImages)

src/viam/sdk/components/private/camera_client.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class CameraClient : public Camera {
3131

3232
ProtoStruct do_command(const ProtoStruct& command) override;
3333

34-
raw_image get_image(std::string mime_type, const ProtoStruct& extra) override;
35-
3634
image_collection get_images(std::vector<std::string> filter_source_names,
3735
const ProtoStruct& extra) override;
3836

@@ -52,7 +50,6 @@ class CameraClient : public Camera {
5250
// param. In order to access these versions of the methods within the client code, however,
5351
// we need to include these `using` lines.
5452
using Camera::get_geometries;
55-
using Camera::get_image;
5653
using Camera::get_images;
5754
using Camera::get_point_cloud;
5855

src/viam/sdk/components/private/camera_server.cpp

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -47,35 +47,11 @@ ::grpc::Status CameraServer::DoCommand(::grpc::ServerContext* context,
4747
});
4848
}
4949

50-
::grpc::Status CameraServer::GetImage(
51-
::grpc::ServerContext* context,
52-
const ::viam::component::camera::v1::GetImageRequest* request,
53-
::viam::component::camera::v1::GetImageResponse* response) noexcept {
54-
return make_service_helper<Camera>(
55-
"CameraServer::GetImage", this, context, request)([&](auto& helper, auto& camera) {
56-
const Camera::raw_image image = camera->get_image(request->mime_type(), helper.getExtra());
57-
58-
const std::string img_string = bytes_to_string(image.bytes);
59-
60-
*response->mutable_mime_type() = image.mime_type;
61-
*response->mutable_image() = img_string;
62-
});
63-
}
64-
65-
::viam::component::camera::v1::Format MIME_string_to_format(const std::string& mime_string) {
66-
if (mime_string == "image/vnd.viam.rgba") {
67-
return viam::component::camera::v1::FORMAT_RAW_RGBA;
68-
}
69-
if (mime_string == "image/vnd.viam.dep") {
70-
return viam::component::camera::v1::FORMAT_RAW_DEPTH;
71-
}
72-
if (mime_string == "image/jpeg") {
73-
return viam::component::camera::v1::FORMAT_JPEG;
74-
}
75-
if (mime_string == "image/png") {
76-
return viam::component::camera::v1::FORMAT_PNG;
77-
}
78-
return viam::component::camera::v1::FORMAT_UNSPECIFIED;
50+
::grpc::Status CameraServer::GetImage(::grpc::ServerContext*,
51+
const ::viam::component::camera::v1::GetImageRequest*,
52+
::viam::component::camera::v1::GetImageResponse*) noexcept {
53+
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED,
54+
"GetImage is deprecated. Use GetImages instead.");
7955
}
8056

8157
::grpc::Status CameraServer::GetImages(
@@ -92,26 +68,18 @@ ::grpc::Status CameraServer::GetImages(
9268
const std::string img_string = bytes_to_string(img.bytes);
9369
proto_image.set_source_name(img.source_name);
9470
proto_image.set_mime_type(img.mime_type);
95-
proto_image.set_format(
96-
MIME_string_to_format(Camera::normalize_mime_type(img.mime_type)));
9771
proto_image.set_image(img_string);
9872
*response->mutable_images()->Add() = std::move(proto_image);
9973
}
10074
*response->mutable_response_metadata() = to_proto(image_coll.metadata);
10175
});
10276
}
10377

104-
::grpc::Status CameraServer::RenderFrame(
105-
::grpc::ServerContext* context,
106-
const ::viam::component::camera::v1::RenderFrameRequest* request,
107-
::google::api::HttpBody* response) noexcept {
108-
return make_service_helper<Camera>(
109-
"CameraServer::RenderFrame", this, context, request)([&](auto& helper, auto& camera) {
110-
const Camera::raw_image image = camera->get_image(request->mime_type(), helper.getExtra());
111-
112-
response->set_data(bytes_to_string(image.bytes));
113-
response->set_content_type(image.mime_type);
114-
});
78+
::grpc::Status CameraServer::RenderFrame(::grpc::ServerContext*,
79+
const ::viam::component::camera::v1::RenderFrameRequest*,
80+
::google::api::HttpBody*) noexcept {
81+
return ::grpc::Status(::grpc::StatusCode::UNIMPLEMENTED,
82+
"RenderFrame is deprecated. Use GetImages instead.");
11583
}
11684

11785
::grpc::Status CameraServer::GetPointCloud(

src/viam/sdk/tests/mocks/camera_mocks.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ using namespace viam::sdk;
1414
ProtoStruct MockCamera::do_command(const ProtoStruct&) {
1515
return map_;
1616
}
17-
Camera::raw_image MockCamera::get_image(std::string, const ProtoStruct&) {
18-
return image_;
19-
}
2017
Camera::image_collection MockCamera::get_images(std::vector<std::string> filter_source_names,
2118
const ProtoStruct& extra) {
2219
last_filter_source_names_ = std::move(filter_source_names);
@@ -45,15 +42,6 @@ Camera::properties MockCamera::get_properties() {
4542
return camera_properties_;
4643
}
4744

48-
Camera::raw_image fake_raw_image() {
49-
Camera::raw_image image;
50-
image.mime_type = "JPEG";
51-
image.source_name = "";
52-
std::vector<unsigned char> bytes = {'a', 'b', 'c'};
53-
image.bytes = bytes;
54-
return image;
55-
}
56-
5745
Camera::image_collection fake_raw_images() {
5846
Camera::image_collection collection;
5947
std::vector<Camera::raw_image> images;
@@ -119,7 +107,6 @@ Camera::properties fake_properties() {
119107
std::shared_ptr<MockCamera> MockCamera::get_mock_camera() {
120108
auto camera = std::make_shared<MockCamera>("mock_camera");
121109

122-
camera->image_ = fake_raw_image();
123110
camera->images_ = fake_raw_images();
124111
camera->pc_ = fake_point_cloud();
125112
camera->camera_properties_ = fake_properties();

src/viam/sdk/tests/mocks/camera_mocks.hpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ using namespace viam::sdk;
1111
class MockCamera : public Camera {
1212
public:
1313
ProtoStruct do_command(const ProtoStruct& command) override;
14-
raw_image get_image(std::string mime_type, const sdk::ProtoStruct& extra) override;
1514
image_collection get_images(std::vector<std::string> filter_source_names,
1615
const sdk::ProtoStruct& extra) override;
1716
point_cloud get_point_cloud(std::string mime_type, const sdk::ProtoStruct& extra) override;
@@ -31,7 +30,6 @@ class MockCamera : public Camera {
3130
Camera::intrinsic_parameters intrinsic_parameters_;
3231
Camera::distortion_parameters distortion_parameters_;
3332
Camera::properties camera_properties_;
34-
Camera::raw_image image_;
3533
Camera::image_collection images_;
3634
Camera::point_cloud pc_;
3735
ProtoStruct map_;
@@ -40,7 +38,6 @@ class MockCamera : public Camera {
4038
ProtoStruct last_extra_;
4139
};
4240

43-
Camera::raw_image fake_raw_image();
4441
Camera::image_collection fake_raw_images();
4542
Camera::point_cloud fake_point_cloud();
4643
Camera::intrinsic_parameters fake_intrinsic_parameters();

src/viam/sdk/tests/test_camera.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,6 @@ BOOST_AUTO_TEST_CASE(mock_get_api) {
3131
BOOST_CHECK_EQUAL(static_api.resource_subtype(), "camera");
3232
}
3333

34-
BOOST_AUTO_TEST_CASE(test_get_image) {
35-
std::shared_ptr<MockCamera> mock = MockCamera::get_mock_camera();
36-
client_to_mock_pipeline<Camera>(mock, [](Camera& client) {
37-
Camera::raw_image image = client.get_image("JPEG");
38-
Camera::raw_image expected_image = fake_raw_image();
39-
40-
BOOST_CHECK(expected_image == image);
41-
});
42-
}
43-
4434
BOOST_AUTO_TEST_CASE(test_get_images) {
4535
std::shared_ptr<MockCamera> mock = MockCamera::get_mock_camera();
4636
client_to_mock_pipeline<Camera>(mock, [](Camera& client) {

0 commit comments

Comments
 (0)