gpt4 book ai didi

c++ - OpenCV:如何读取 float 图像

转载 作者:行者123 更新时间:2023-11-28 00:48:34 25 4
gpt4 key购买 nike

我在 openCV 中创建了一个 Mat,如下所示:

cv::Mat m = cv::Mat(10,10, CV_32FC1);
for(int i = 0; i < 10; i++){
for(int j = 0; j < 10; j++){
m.at<float>(i,j) = 1;
}
}

并通过以下方式将其保存到磁盘:

imwrite("out.png", m);

我现在尝试按如下方式阅读它:

cv::Mat m = imread("out.png", CV_LOAD_IMAGE_UNCHANGED);

但是 m 中的数据似乎是完全随机的,当像 m.at<float>(5,5) 这样访问时例如。

如何读回写入的数据?例如,在 matlab 中我可以这样做:

m = imread("out.png") 

它给了我正确的 1 矩阵

谢谢

最佳答案

参见 imwrite

The function imwrite saves the image to the specified file. The image format is chosen based on the filename extension (see imread() for the list of extensions). Only 8-bit (or 16-bit unsigned (CV_16U) in case of PNG, JPEG 2000, and TIFF) single-channel or 3-channel (with ‘BGR’ channel order) images can be saved using this function. If the format, depth or channel order is different, use Mat::convertTo() , and cvtColor() to convert it before saving. Or, use the universal XML I/O functions to save the image to XML or YAML format.

depth , convertTo

关于c++ - OpenCV:如何读取 float 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15207616/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com