Skip to content

Commit ddcddc9

Browse files
committed
Fix visible/color frame conversion
It's RGB8, not MONO8. It's also possible to do a shallow copy instead of a deep copy, so the conversion is faster.
1 parent 2cec3fd commit ddcddc9

File tree

1 file changed

+2
-13
lines changed

1 file changed

+2
-13
lines changed

src/sc.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -198,25 +198,14 @@ struct SessionDelegate : ST::CaptureSessionDelegate {
198198
return;
199199
}
200200

201-
cv::Mat img(visFrame.height(), visFrame.width(), CV_8UC1);
202-
203-
const uint8_t* buf = visFrame.rgbData();
204-
205-
for(int y = 0; y < visFrame.height(); y++)
206-
{
207-
for(int x = 0; x < visFrame.width(); x++)
208-
{
209-
std::size_t pixelOffset = (y * visFrame.width()) + x;
210-
img.at<uchar>(y, x) = buf[pixelOffset];
211-
}
212-
}
201+
cv::Mat img(visFrame.height(), visFrame.width(), CV_8UC3, static_cast<void*>(const_cast<uint8_t*>(visFrame.rgbData())));
213202

214203
std_msgs::Header header;
215204
header.frame_id = frame_id_;
216205
// TODO: convert timstamp to ROS time
217206
// header.stamp = infraredFrame.timestamp();
218207

219-
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(header, "mono8", img).toImageMsg();
208+
sensor_msgs::ImagePtr msg = cv_bridge::CvImage(header, "rgb8", img).toImageMsg();
220209
vis_pub_.publish(msg);
221210

222211
sensor_msgs::CameraInfo cam_info;

0 commit comments

Comments
 (0)