前言
基於Vxworks的WindRiver獲取攝像頭圖像進行處理,需要先進行轉換,對於轉換格式博主有點疑問。本文對此作出解釋,若有錯誤,請交流指正。
README.md
The video camera capture software is customized to work with the UVC driver. The capture is taken in YUY2 format, and may therefore require conversion.
code
從README.md內容看出來,攝像頭捕獲圖像之后需要進行格式轉換才能繼續后續圖像處理過程。轉換代碼如下:
cvtColor(frame, frame1, COLOR_YUV2BGR_YUY2);
問題1:
COLOR_YUV2BGR_YUY2,這些格式是什么?COLOR_YUV?BGR_YUY2?怎么來的?
capture >> frame; std::cout << "capture image format: " << capture.get(CAP_PROP_FORMAT) << std::endl; // 0-CV_8UC1 std::cout << "capture image type: " << frame.type() << std::endl; // 8-CV_8UC2 cvtColor(frame, frame, COLOR_YUV2BGR_YUY2); std::cout << "frame type: " << frame.type() << std::endl; // 16-CV_8UC3
圖像格式的輸出可能與攝像頭的驅動也有關系。
問題2:
從攝像頭捕獲圖像之后的格式轉換語句,不太理解說明文檔說是捕獲的YUY2格式,為什么cvtColor是從COLOR_YUV格式轉換成BGR_YUY2格式?
分析:
由於歷史原因,opencv總是默認按照BGR格式處理視頻,通過opencv打開一款格式為YUY2的camera,opencv會默認轉換成BGR格式,如果想拿到YUY2的camera的原始數據,需要一些配置和格式轉換,由於opencv不能顯示YUY2格式的圖片,因此如果需要預覽必須先轉換格式后,再調用顯示函數。
參考
1. cvtColor函數;
5. why-does-capgetcv_cap_prop_format-return-0;
完