2011-11-22 36 views
2

我正在使用基於OpenCV 1.0的校準工具箱,我正在對其進行小幅度的增加。我的補充需要使用FFTW函數庫(OpenCV具有DFT函數,但它們不符合我的喜好)。訪問OpenCV 1.0圖像像素值並在FFTW中使用它們

我一直在嘗試訪問圖像的像素值並將這些像素值存儲到FFTW_complex類型變量中。我嘗試了很多不同的建議(包括openCV文檔),但我一直無法正確執行此操作。

以下代碼在構建或調試期間不會與變量類型產生任何不一致;然而,獲得並存儲在「testarray」中的像素值是重複的值[13,240,173,186]。有誰知道如何訪問像素值並將它們存儲到符合FFTW的矩陣/容器中?

//.....................................// 
    //For image manipulation 
    IplImage* im1 = cvCreateImage(cvSize(400,400),IPL_DEPTH_8U,1);  
    int width = im1 -> width; 
    int height = im1 -> height; 
    int step = im1 -> widthStep/sizeof(uchar); 
    int fft_size = width *height; 

    //Setup pointers to images 
    uchar *im_data = (uchar *)im1->imageData; 
    //......................................// 

    fftw_complex testarray[subIM_size][subIM_size]; //size of complex FFTW array 

    im1= cvLoadImage(FILEname,0); 
    if (!im1)printf("Could not load image file"); 

    //Load imagedata into FFTW arrays 
    for(i = 0 ; i < height ; i++) { 
     for(j = 0 ; j < width ; j++) { 
      testarray[i][j].re = double (im_data[i * step + j]); 
      testarray[i][j].im = 0.0; 
     } 
    } 

我發現了這個問題。我一直在使用錯誤的方法來訪問它。

這是我用什麼:

testarray[i][j].re = ((uchar*)(im1->imageData + i *im1->widthStep))[j]; //double (im_data[i * step + j]); 

回答

0

我使用C++在Visual Studio 2008,這是該方法是使用:

如果我們有一個這樣的循環,通過去圖片:

for (int y = 0 ; y < height; y++){ 
     for (int x = 0 ; x < width ; x++){ 

然後,進入FFTW變量(姑且稱之爲A)將進行如下:

A [ height * y + x][0] = double (im_data[height * y + x]); 
    A [ height * y + x][1] = 0; 

希望它有幫助!

Antonio