读取 rgb planner 二进制数据 resize 重采样
作者:互联网
#include <fstream>
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace cv; using namespace std;
int main(int argc, char **argv) { const uint32_t cols = 640; const uint32_t rows = 426;
ifstream fin0("000000000139.planner", 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);
Mat imgDst = Mat::zeros(224, 224, CV_8UC3); resize(img0, imgDst, imgDst.size(), 0, 0, INTER_LINEAR);
imwrite("out2.jpg", imgDst);
return 0; }
using namespace cv; using namespace std;
int main(int argc, char **argv) { const uint32_t cols = 640; const uint32_t rows = 426;
ifstream fin0("000000000139.planner", 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);
Mat imgDst = Mat::zeros(224, 224, CV_8UC3); resize(img0, imgDst, imgDst.size(), 0, 0, INTER_LINEAR);
imwrite("out2.jpg", imgDst);
return 0; }
标签:planner,Mat,fin0,cols,char,rgb,rows,img0,resize 来源: https://www.cnblogs.com/qmjc/p/16181007.html