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