在工业相机采集数据时,应该会出现raw格式的图像。
#include <iostream>
#include <io.h>
#include <chrono>
int main()
{
std::string filePath = "I:/bf/cn1";
std::vector<std::string> allFiles;
getFiles(filePath, allFiles);
auto aa = std::chrono::system_clock::now();
for (int i = 0; i < allFiles.size(); ++i)
{
auto startTime = std::chrono::system_clock::now();
FILE *fp = NULL;
int ret = 0, width = 2448, height = 2048;
unsigned char *pRawData = (unsigned char *)malloc(width*height * sizeof(unsigned char));
if (NULL == pRawData)
{
printf("Fail to calloc buf\r\n");
return -1;
}
if (NULL == (fp = fopen(allFiles[i].c_str(), "rb")))
{
printf("Fail to read %s.\r\n", allFiles[i].c_str());
return -2;
}
ret = fread(pRawData, sizeof(unsigned char)*width*height, 1, fp);
if (ret != 1)
{
printf("Fail to read raw data\r\n");
return -3;
}
fclose(fp);
fp = nullptr;
Mat img(Size(width, height), CV_8UC1, pRawData);
Mat img2(Size(width, height), CV_8UC3, Scalar(0));
Mat img3(Size(width, height), CV_8UC3, Scalar(0));
cvtColor(img, img2, CV_BayerRG2BGR);
cvtColor(img2, img3, CV_BGR2RGB);
std::string fileName = "offline" + std::to_string(i) + ".jpg";
imwrite(fileName, img3);
auto endTime = std::chrono::system_clock::now();
// 示例
std::cout << "time:" << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << std::endl;
}
auto bb = std::chrono::system_clock::now();
std::cout << "time:" << std::chrono::duration_cast<std::chrono::milliseconds>(bb - aa).count() << std::endl;
return -1;
}