什么是RAW?有什么特点?
- RAW是未经过加工过的档案,原始图档仅是将原始曝光、颜色等资讯纪录下来的结果。
- JPEG是经过相机处理器润饰和加工过的产物,也就是被相机「后期制作」过的图片。所以即使同样参数拍同样的场景,因为各厂商对颜色、对比、曝光的诠释都不尽相同,所以最终的JPEG图还是会所有差异。
- RAW有更多的画面细节和更佳的画质表现,更高的动态范围
- RAW一般的图片软件打不开
基于OpenCV使用c++将其转换为JPEG输出并显示,代码如下:
// RAW遥感影像读取.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
#define width 1024
#define height 1024
int main(int argc, char* argv[])
{
string srcRAW = argv[1];
string outputBasePath = argv[2];
string outputPath = outputBasePath + "raw2jpg.jpg";
FILE* file = fopen(srcRAW.c_str(), "rb+"); //使用文件流打开raw文件
if (file == NULL)
{
cout << "打开RAW文件失败" << endl;
}
unsigned char* data = (unsigned char*)malloc(width * height * sizeof(float)); //内存分配
fread(data, sizeof(unsigned char), width * height, file); //在缓存中读取数据
Mat img(height, width, CV_8UC1, Scalar(0, 0, 0));
memcpy(img.data, data, width * height);
imwrite(outputPath, img);
//imshow("JPEG image", img);
waitKey(0);
fclose(file);
delete[]data;
return 0;
}
运行时更换argv[1]为raw的绝对路径,argv[2]为输出路径即可。修改文件的后缀名为.jpg .bmp也可以输出相对应的文件格式。