fix camera
This commit is contained in:
@@ -377,7 +377,37 @@ private:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ensure output buffer
|
// Handle different pixel formats
|
||||||
|
// Mono8 (0x1080009) needs to be converted to RGB8 by duplicating the channel
|
||||||
|
// RGB8 (PixelType_Gvsp_RGB8_Packed = 0x02100014) can be used directly
|
||||||
|
const bool is_mono8 = (out_frame.stFrameInfo.enPixelType == 0x1080009);
|
||||||
|
const bool is_rgb8 = (out_frame.stFrameInfo.enPixelType == 0x02100014);
|
||||||
|
|
||||||
|
if (is_mono8) {
|
||||||
|
// Convert Mono8 to RGB8 by duplicating the single channel
|
||||||
|
const size_t mono_size = static_cast<size_t>(out_frame.stFrameInfo.nWidth) * out_frame.stFrameInfo.nHeight;
|
||||||
|
const size_t rgb_size = mono_size * 3;
|
||||||
|
if (image_msg_.data.size() != rgb_size) {
|
||||||
|
image_msg_.data.resize(rgb_size);
|
||||||
|
}
|
||||||
|
uint8_t* src = static_cast<uint8_t*>(out_frame.pBufAddr);
|
||||||
|
uint8_t* dst = image_msg_.data.data();
|
||||||
|
for (size_t i = 0; i < mono_size; i++) {
|
||||||
|
dst[i * 3 + 0] = src[i]; // B
|
||||||
|
dst[i * 3 + 1] = src[i]; // G
|
||||||
|
dst[i * 3 + 2] = src[i]; // R
|
||||||
|
}
|
||||||
|
image_msg_.encoding = "rgb8";
|
||||||
|
} else if (is_rgb8) {
|
||||||
|
// Already RGB8, just copy directly
|
||||||
|
const size_t rgb_size = static_cast<size_t>(out_frame.stFrameInfo.nWidth) * out_frame.stFrameInfo.nHeight * 3;
|
||||||
|
if (image_msg_.data.size() != rgb_size) {
|
||||||
|
image_msg_.data.resize(rgb_size);
|
||||||
|
}
|
||||||
|
memcpy(image_msg_.data.data(), out_frame.pBufAddr, rgb_size);
|
||||||
|
image_msg_.encoding = "rgb8";
|
||||||
|
} else {
|
||||||
|
// Try SDK conversion for other formats
|
||||||
const size_t need_size =
|
const size_t need_size =
|
||||||
static_cast<size_t>(out_frame.stFrameInfo.nWidth) * out_frame.stFrameInfo.nHeight * 3;
|
static_cast<size_t>(out_frame.stFrameInfo.nWidth) * out_frame.stFrameInfo.nHeight * 3;
|
||||||
if (image_msg_.data.size() != need_size) {
|
if (image_msg_.data.size() != need_size) {
|
||||||
@@ -409,6 +439,8 @@ private:
|
|||||||
fail_count_++;
|
fail_count_++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
image_msg_.encoding = "rgb8";
|
||||||
|
}
|
||||||
|
|
||||||
auto stamp = this->now();
|
auto stamp = this->now();
|
||||||
image_msg_.header.stamp = stamp;
|
image_msg_.header.stamp = stamp;
|
||||||
|
|||||||
Reference in New Issue
Block a user