我有一個 yuv422 編碼的原始影像,它是從我的 Jetson Nano 上的 csi_camera 中提取的,我想將其轉換為 RGB 編碼以用于機器學習。我該怎么辦?我嘗試在 OpenCV 中使用不同的 cvtColor 代碼,但生成的影像仍然一團糟。有沒有辦法將此影像轉換為“正常”顏色?
這是影像: csi_image
uj5u.com熱心網友回復:
所以我終于想出了如何使用以下代碼轉換影像:
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 ;
}
}
我必須先添加toCvCopy(imgPtr, “yuv422”)->以指定傳入的編碼,然后轉換為使用 YUY2 列舉。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/511630.html
上一篇:在R中繪制影像堆疊的優雅方式
