【发布时间】:2020-07-17 16:50:51
【问题描述】:
使用 OpenCV RAW 到 RGB 转换 (CV_BayerBG2BGR) 时,图像显示正确,但图像基本类型不正确(elemSize & depth)。
即使将转换后的 Mat 写入文件然后加载它(下面代码中的 rgb_path),加载的 rgb 图像和转换后的 rgb 图像之间存在差异,尽管两者都显示正常。
这会导致下游问题,我将 Mat 转换为 uint8_t*,因为转换后的 rgb 图像中的缓冲区大小较大。
这是转换本身的问题还是我对转换/OpenCV 基本数据类型的理解?我正在使用 OpenCV 341。
int main() {
Mat img = imread(rgb_path);
ifstream ifd(raw_path, ios::binary | ios::ate);
int size = ifd.tellg();
ifd.seekg(0, ios::beg);
vector<char> buffer;
buffer.resize(size);
ifd.read(buffer.data(), size);
Mat rgb_image;
Mat raw_image(600, 800, CV_16UC1, buffer.data());
cvtColor(raw_image, rgb_image, CV_BayerBG2BGR);
cout << "elemSize() orig: " << img.elemSize() << endl;
cout << "elemSize() conv: " << rgb_image.elemSize() << endl;
cout << "channels() conv: " << rgb_image.channels() << endl;
cout << "channels() orig: " << img.channels() << endl;
cout << "depth() conv: " << rgb_image.depth() << endl;
cout << "depth() orig: " << img.depth() << endl;
cout << "total() orig: " << img.total() << endl;
cout << "total() conv: " << rgb_image.total() << endl;
return 0;
}
Output:
elemSize() orig: 3
elemSize() conv: 6
channels() conv: 3
channels() orig: 3
depth() conv: 2
depth() orig: 0
【问题讨论】: