fix(camera): preserve BGR snapshot contract

This commit is contained in:
linbo 2026-08-26 15:15:48 +08:00
parent 4f5c4eaa13
commit 8a98b77a04

View File

@ -12,7 +12,6 @@
#include <cstdint>
#include <limits>
#include <thread>
#include <utility>
using namespace std;
using namespace cmvr::service;
@ -220,13 +219,6 @@ grpc::Status gRPCCameraServiceImpl::GetRGBImage(grpc::ServerContext* context,
response->mutable_header()->set_success(true);
setCurrentTimestamp(response->mutable_header()->mutable_timestamp());
// OpenCV/RealSense expose color frames as BGR. The gRPC contract uses
// RGB byte order so clients can construct RGB888 images directly.
if (image.type() == CV_8UC3) {
cv::Mat rgb_image;
cv::cvtColor(image, rgb_image, cv::COLOR_BGR2RGB);
image = std::move(rgb_image);
}
auto imageType = image.type();
if (imageType == CV_8UC1) {
response->mutable_color_frame()->set_type(api::FrameData::U8C1);
@ -345,12 +337,8 @@ grpc::Status gRPCCameraServiceImpl::GetRGBDImages(grpc::ServerContext* context,
response->mutable_header()->set_success(true);
setCurrentTimestamp(response->mutable_header()->mutable_timestamp());
// color image
if (color_image.type() == CV_8UC3) {
cv::Mat rgb_image;
cv::cvtColor(color_image, rgb_image, cv::COLOR_BGR2RGB);
color_image = std::move(rgb_image);
}
// color image is serialized in the existing OpenCV BGR byte order;
// clients convert it once when constructing an RGB image.
if (color_image.type() == CV_8UC3) {
response->mutable_color_frame()->set_type(api::FrameData::U8C3);
}