【问题标题】:FFTW with qt C++ program crash带有 qt C++ 程序崩溃的 FFTW
【发布时间】:2016-01-28 15:33:07
【问题描述】:

我尝试从具有 fftw 和 qt 的图像列表中及时计算像素向量 fft,并对所有图像的所有像素重复此处理;向量包含 [pix1.1 of im1,pix1.1 of im2,...pix1.1 of imN],问题是当图像数量很大时程序崩溃

const int Npoints(widget.imagelistWidget->count());
fftw_complex *in, *out;
in = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*Npoints);
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)*Npoints);
double  resfft;
fftw_plan p;

QList<QImage*> imageList;
QImage *imagef ;

for(int k=0;k<liste.size();k++)
{
    imagef = new QImage;
    imagef->load(liste[k]);
    imageList.append(imagef);
}

for(int i=0;i<imagef->width();i++)
{
    for(int j=0;j<imagef->height();j++)
    {
        for(int k=0;k<liste.size();k++)
        {
             imagef  =imageList.at(k);
             QRgb pixelfft=imagef->pixel(i,j);
             double  moyp= qGray(pixelfft);

             in[k][0] = moyp;
             in[k][1] = 0.0;
        }
        p = fftw_plan_dft_1d(Npoints, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
        fftw_execute(p);
        //resultat
        QVector<qreal> realV;
        QVector<qreal> imgV;
        for (int s = 0; s < Npoints; s++) 
        {
            realV.append(out[s][0]);
            imgV.append(out[s][1]);
        }

        for(int l=0;l<liste.size();++l)
        { 
            resfft = sqrt((realV[l] * realV[l]) + (imgV[l] * imgV[l]));
            imagef=imageList.at(l);
            imagef->setPixel(i,j,qGray(qRgb(resfft,resfft,resfft)));
        }
    }
}    

【问题讨论】:

  • 一些想法:你不需要每次都打电话给fftw_plan_dft_1d。一个缺陷:imagef 指针不断变化。你确定这是你想要的吗?您确定所有图像的大小都相同吗?你得到什么错误?
  • 哪条线路崩溃了?堆栈跟踪在哪里?

标签: c++ qt fftw


【解决方案1】:

我认为这就是@bibi 的评论所要表达的意思,但这部分看起来不对:

for(int i=0;i<imagef->width();i++)
{
for(int j=0;j<imagef->height();j++)
{
    for(int k=0;k<liste.size();k++)
    {

     imagef  =imageList.at(k);
     QRgb pixelfft=imagef->pixel(i,j);
     double  moyp= qGray(pixelfft);

     in[k][0] = moyp;
     in[k][1] = 0.0;
    } 

您的循环似乎顺序错误。当您调用widthheight 时,您不会在内部循环中的当前图像上调用它们。你可能想要的是这样的:

for(int k=0;k<liste.size();k++)
{

    //Get the current image from the list
    imagef  = imageList.at(k);

    //Loop over every pixel in the image
    for(int i=0;i<imagef->width();i++)
    {
        for(int j=0;j<imagef->height();j++)
        {
            QRgb pixelfft=imagef->pixel(i,j);
            double  moyp= qGray(pixelfft);

            in[k][0] = moyp;
            in[k][1] = 0.0;
        } 
    }
    /*...*/

【讨论】:

  • 不,顺序是正确的,因为我及时填充了像素的矢量,这意味着在 [k] 中由 image1 的像素 1.1 填充,图像 2 的像素 1.1 最后是 imageN 的像素 1.1,然后是像素1.2, ...pixel NM 所以这就是为什么我们应该尊重这个顺序。如果我在按钮中再次单击按钮以计算 2300 列表中的 fft 它会崩溃但第一次没有
猜你喜欢
  • 1970-01-01
  • 2023-03-11
  • 2016-08-27
  • 1970-01-01
  • 1970-01-01
  • 2014-06-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多