2013-03-14 66 views
0

我確實有一類矩陣,我用兩個循環訪問它,並在其中存儲了我想要的所有值。將矩陣類轉換爲IplImage *

Matrix MatriceJ(width, height); 
for (int i=0;i<width;i++) 
{ 
    for (int j=0;j<height;j++) 
    { 
     MatriceJ.at(i,j)=.... 
    } 
} 

但現在,我想的MatriceJ存儲在一個的IplImage *的,我可以乘其不同的元素,一個接一個,與其他IplImages。

你能幫我嗎?

+0

我不明白你爲什麼寫了'Matrix MatriceJ'。它應該不是'Mat MatriceJ'嗎? – Chani 2013-03-14 14:26:09

+0

但是我創建了一個名爲Matrix的類來輕鬆操作它並存儲它的值。 – 2013-03-14 14:35:55

+0

有任何問題嗎? – 2013-03-14 14:49:03

回答

1

這應該讓你開始。我假設數據是無符號字符和一個通道,請相應調整。

// Create the image 
int depth = IPL_DEPTH_8U; // please adjust 
int channels = 1;   // please adjust 
IplImage* img = cvCreateImage(cvSize(width,height), depth, channels); 

// Now assume there is a matrix MatriceJ 
// Copy the data to our newly created IplImage* 
for (int i=0;i<height;i++) 
{ 
    uchar* ptr = (uchar*)(img->imageData + i*img->widthStep); 
    for (int j=0;j<width;j++) 
    { 
     ptr[j] = MatriceJ(i,j); 
    } 
} 
+0

非常感謝你! – 2013-03-15 10:17:36