opencv rgb plannar 读取 转 rgb888保存
#include <fstream>
#include <iostream>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main(int argc, char **argv)
{
const uint32_t cols = 24;
const uint32_t rows = 24;
ifstream fin0("00135461.plannar", ios::in | ios::binary);
if(!fin0.is_open())
{
cout << "open fail!\n";
return 1;
}
Mat img0_r = Mat::zeros(rows, cols, CV_8UC1);
Mat img0_g = Mat::zeros(rows, cols, CV_8UC1);
Mat img0_b = Mat::zeros(rows, cols, CV_8UC1);
fin0.read(&img0_r.at< char >(0, 0), sizeof(char) * rows * cols);
fin0.read(&img0_g.at< char >(0, 0), sizeof(char) * rows * cols);
fin0.read(&img0_b.at< char >(0, 0), sizeof(char) * rows * cols);
fin0.close();
Mat channels[3] = { img0_b, img0_g, img0_r };
Mat img0;
merge(channels, 3, img0);
imwrite("out2.jpg", img0);
ofstream fout0("out2.img", ios::out | ios::binary);
Mat imgRGB;
cvtColor(img0, imgRGB, COLOR_BGR2RGB);
fout0.write(&imgRGB.at< char >(0, 0), sizeof(char) * rows * cols * 3);
fout0.close();
return 0;
}