for (rosbag::MessageInstance const m : rosbag::View(bag)) {
// Read only the input topic
if(m.getTopic() == topic) {
// Create an image pointer to the bag file image messages
sensor_msgs::ImageConstPtr imgPtr = m.instantiate<sensor_msgs::Image>();
// Extract the image frame with yuv422 encoding
image = cv_bridge::toCvCopy(imgPtr, "yuv422")->image;
// Convert the image frame to a BGR format image
cvtColor( image, newimage, COLOR_YUV2BGRA_YUY2 );
// Write the new image to the out path
imwrite(final_path, newimage);
count++;
}
}
1条答案
按热度按时间t3psigkw1#
因此,我终于想出了如何使用以下代码转换图像:
我必须先添加
toCvCopy(imgPtr, “yuv422”)->
来指定传入的编码,然后转换为使用YUY2枚举。