opencv读取raw格式

cv::Mat readRawDataImage(std::string imageName, int rawDataHeight, int rawDataWidth)
{
	FILE *filePointer;

	fopen_s(&filePointer, imageName.c_str(), "rb+");
	if (filePointer == NULL)
	{
		std::cout << "Can not open the raw data!\n";
		return cv::Mat();
	}

	cv::Mat rawData(rawDataHeight, rawDataWidth, CV_8UC1, cv::Scalar(0));

	// read imgae data
	for (int i = 0; i < rawDataHeight; i++)
	{
		uchar *pointer = rawData.ptr(i);
		fread(pointer, 1, rawDataWidth, filePointer);
	}

	fclose(filePointer);

	return rawData;
}
	int rawDataHeight = 6400;
	int rawDataWidth = 6144;

	// Load image
	std::string imageName = "IMG_20191130_194049338.raw";
	cv::Mat rawImage = readRawDataImage(imageName, rawDataHeight, rawDataWidth);

	//// Raw data to Gray using opencv 
	//cv::Mat grayImage;
	//cv::cvtColor(rawImage, grayImage, cv::COLOR_BayerGB2GRAY/*cv::COLOR_BayerGB2BGR_EA*/);

	cv::imshow("test", rawImage);

 

你可能感兴趣的:(笔记,代码)