2

我正在使用基于 OpenCV 1.0 的校准工具箱,我正在对其进行少量添加。我的补充需要使用 FFTW 库(OpenCV 有 DFT 函数,但我不喜欢它们)。

我一直在尝试访问图像的像素值并将这些像素值存储到 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]);

4

1 回答 1

0

我在 Visual Studio 2008 中使用 C++,这是使用的方式:

如果我们有一个这样的循环来遍历图像:

    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;

希望能帮助到你!

安东尼奥

于 2011-11-24T08:15:34.943 回答