【14】opencv/C++ 打开图像,转成Mat格式
2023-10-23 本文已影响0人
豚大叔的小屋
//1.加载图像
std::ifstream file("apple.prj", std::ios::binary);
if (!file) {
std::cout << "无法打开文件" << std::endl;
return 0;
}
// 跳过100个字节的头部数据
file.seekg(100, std::ios::beg);
int width =512; // 图像宽度
int height =512; // 图像高度
int numPixels = width * height; // 像素数
cv::Mat image(height, width, CV_16UC1);
file.read(reinterpret_cast<char*>(image.data), numPixels * sizeof(uint16_t));
file.close();