【发布时间】:2013-01-17 00:28:42
【问题描述】:
我想在 opencv 中以浮点数组的形式访问图像像素。我做了以下事情:
Mat input = imread("Lena.jpg",CV_LOAD_IMAGE_GRAYSCALE);
int height = input.rows;
int width = input.cols;
Mat out;
input.convertTo(input, CV_32FC1);
copyMakeBorder(input, input, 3, 3, 3, 3, 0);
out = Mat(height, width, input.type());
float *outdata = (float*)out.data;
float *indata = (float*)input.data;
for(int j = 0; j < height; j++){
for(int i =0; i < width; i++){
outdata[j*width + i] = indata[(j* width + i)];
}
}
normalize(out, out,0,255,NORM_MINMAX,CV_8UC1);
imshow("output", out);
waitKey();
这应该在“out”中返回原始图像,但是,我得到了一些奇怪的图像。任何人都可以解释代码有什么问题。我想我需要使用一些步长(widthStep)。谢谢。
【问题讨论】:
-
假设数组代表二维数据,如何通过例如索引它们
outdata[j*width + i]? -
试过了。没有得到正确的结果:(
-
更多代码,请:
out和input的类型是什么? -
二维图像。 CV_32FC1。垫子。
-
您想将图像转换为包含浮点数据类型元素的二维数组吗?
标签: c++ image-processing opencv