2013-03-19 126 views
0

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

+0

什么是你的txt文件的格式? yml/xml?那么它是简单的cv :: FileStorage – berak 2013-03-19 20:55:51

回答

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);