将大矩阵转换为图像

时间:2013-03-19 20:32:34

标签: opencv matrix

嗨所以我在文本文件中有一个33 x 33的大矩阵。我一直在研究一个opencv项目,它基本上读取帧并计算相似性。所以基本上,我现在有这个充满数字的大文本文件。如何在2D灰度图像中可视化此矩阵?

1 个答案:

答案 0 :(得分:1)

您的矩阵是cv::Mat对象吗?

如果是,请执行:

cv::Mat matrix;

//Load the matrix from the file
matrix = ...

//show the matrix
imshow("window name", matrix);

//save the image
imwrite("image.png", matrix);

如果没有,那么请执行:

cv::Mat matrix = cv::Mat.create(33, 33, CV_32FC1);
float* floatPtr = matrix.ptr<float>();

for (int i=0;i<33*33;i++)
     //read data from file here
    *floatPtr++ = data[i] //if it's in an array
    //If you have a file stream then do: file>>*floatPtr++;

//show the image
imshow("window name", matrix);

//save the image
imwrite("image.png", matrix);
相关问题