【发布时间】:2023-03-05 22:27:02
【问题描述】:
我正在尝试将灰度图像转换为 CV64F 类型。从 OpenCv 文档中,我了解到灰度图像的类型为 CV_8U。我还发现 imshow 以不同的方式绘制不同的类型,因此在转换之前我需要除以 255。但是在转换图像后,我仍然得到很多饱和像素。
我正在使用这张图片,保存为 jpg: http://www.ele.uri.edu/~hansenj/projects/ele585/lab2/cameraman.gif
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <cstring>
#include <cmath>
int main()
{
Mat I, input_image;
string path = "C:/<your_path>/camera_man.jpg";
input_image = imread(path.c_str(), 0); // Read the file as grayscale
imshow("Original", input_image);
// Convert image to CV_64F
input_image *= (double) 1 / 255;
input_image.convertTo(I, CV_64F);
imshow("Converted", I);
}
【问题讨论】: