访问冲突错误
Access violation error
我实现了一个fftw(fftw.org)示例来使用快速傅立叶变换。。。这就是代码。。。。
我加载了一个图像,我将其从uint8_t转换为double(此代码运行良好…)
string bmpFileNameImage = "files/testDummyFFTWWithWisdom/onechannel_image.bmp";
BMPImage bmpImage(bmpFileNameImage);
vector<double>pixelColors;
vector<uint8_t> image = bmpImage.copyBits();
toDouble(image,pixelColors,256,256, 1);
int width = bmpImage.width();
int height = bmpImage.height();
我使用智慧文件来提高的性能
FILE * file = fopen("wisdom.fftw", "r");
if (file) {
fftw_import_wisdom_from_file(file);
fclose(file);
}
///* fftw variables */
fftw_complex *out;
double *wisdomInput = (double *) fftw_malloc(sizeof(double)*width*2*(height/2 +1 ));
const fftw_plan forward =fftw_plan_dft_r2c_2d(width,height, wisdomInput,reinterpret_cast<fftw_complex *>(wisdomInput),FFTW_PATIENT);
const fftw_plan inverse = fftw_plan_dft_c2r_2d(width, height,reinterpret_cast<fftw_complex *>(wisdomInput),wisdomInput, FFTW_PATIENT);
file = fopen("wisdom.fftw", "w");
if (file) {
fftw_export_wisdom_to_file(file);
fclose(file);
}
最后,我执行了fftw库。。。。我收到第一个的访问违规错误函数(fftw_execute_dft_r2c
),我不知道为什么。。。我阅读了本教程:http://www.fftw.org/fftw3_doc/Multi_002dDimensional-DFTs-of-Real-Data.html#Multi_002dDimensional-真实数据的DFT。我用(ny/2+1)如何解释它做了一个malloc。我不明白为什么它不起作用。。。。我正在测试不同尺寸的。。。
out = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * width *(height / 2 + 1));
double *result =(double *)fftw_malloc(width * (height+2) * sizeof(double));
fftw_execute_dft_r2c(forward,&pixelColors[0],out);
fftw_execute_dft_c2r(inverse,out,result);
谨致问候。
这是经过更正的代码。它有几个错误:
- 它读取了一个错误的wisdom.fftw文件(来自某个旧测试…)。现在,它总是创建一个新的fftw_plan和一个新文件
- 我误解了fftw库使用就地和异地参数的工作方式。我不得不更改malloc以获得"就地"的正确填充(我在malloc函数中添加了+2)
- 为了恢复图像,我不得不用它的大小((宽度+2)*高度)来划分它在这个链接中的解释方式
`
/* load image */
string bmpFileNameImage = "files/polyp.bmp";
BMPImage bmpImage(bmpFileNameImage);
int width = bmpImage.width();
int height = bmpImage.height();
vector<double> pixelColors;
vector<uint8_t> image = bmpImage.copyBits();
//get one channel from the image
Uint8ToDouble(image,pixelColors,bmpImage.width(),bmpImage.height(),1);
//We don't reuse old wisdom.fftw... It can be corrupt
/*
FILE * file = fopen("wisdom.fftw", "r");
if (file) {
fftw_import_wisdom_from_file(file);
fclose(file);
} */
double *wisdomInput = (double *) fftw_malloc(sizeof(double)*height*(width+2));
const fftw_plan forward =fftw_plan_dft_r2c_2d(width,height,wisdomInput,reinterpret_cast<fftw_complex *>(wisdomInput),FFTW_PATIENT);
const fftw_plan inverse = fftw_plan_dft_c2r_2d(width,height,reinterpret_cast<fftw_complex *>(wisdomInput),wisdomInput, FFTW_PATIENT);
double *bitsColors =(double *)fftw_malloc((width) * height * sizeof(double));
for (int y = 0; y < height; y++) {
for (int x = 0; x < width+2; x++) {
if (x < width) {
int currentIndex = ((y * width) + (x));
bitsColors[currentIndex] = (static_cast<double>(result[y * (width+2) + x])) / (height*width);
}
}
}
fftw_free (wisdomInput);
fftw_free (out);
fftw_free (result);
fftw_free (bitsColors);
fftw_destroy_plan(forward);
fftw_destroy_plan(inverse);
fftw_cleanup();
}
`
fftw_execute_dft_r2c(forward,&pixelColors[0],out);
你在这里干什么?数组已经有一个指针。将其更改为fftw_execute_dft_r2c(forward,pixelColors[0],out);
,现在应该可以工作了。
也许问题就在这里(http://www.fftw.org/doc/New_002darray-Execute-Functions.html):
[…]满足以下条件:
- 如果计划最初创建为就地或分别不合时宜
在计划中,您使用的是就地转换参数(分配错误,BTW,因为:
double *wisdomInput = (double *) fftw_malloc(sizeof(double)*width*2*(height/2 +1 ));
应该是:
double *wisdomInput = (double *) fftw_malloc(sizeof(fftw_complex)*width*2*(height/2 +1 ));
也适于输出)。
但是您调用的fftw_execute_dft_r2c
函数的参数不合适。
相关文章:
- 0xC0000005:访问冲突写入位置0xCDCDCDCD动态分配错误
- 使用 EvtSetChannelConfigProperty() 函数时出现访问冲突错误
- 引发异常:读取访问冲突.**此**0x40错误
- 在尝试使用CUDA分配内存时,我遇到了访问冲突写入位置错误
- cv::resize() 失败并出现访问冲突错误(由 NULL> 处的 <struct 引起)
- 在 C 代码中调用 Python 函数时第三次出现访问冲突写入位置错误
- 错误 : 异常 : 引发未处理的异常: 读取访问冲突.0xDDDDDDDD临时温度
- 读取访问冲突. _Mycont 在 C++ 中将 udp 数据放入向量时出现 nullptr 错误
- 将 std::string 作为参数从一个 DLL 传递到另一个 DLL 引发访问冲突错误
- 遵循官方 Direct2D 示例,但出现访问冲突错误
- Windows错误:异常:使用从C++到Python的ctypes创建DLL时出现访问冲突或Windows错误193
- C++访问冲突读取位置错误
- Eigen SparseLU解决错误读取访问冲突,这>m_sup_to_col被0x111011101110112
- C++ 抛出读取访问冲突错误,但我不确定为什么。平铺滑块益智游戏
- 为什么我的顶点缓冲区对象出现访问冲突错误?
- 尝试创建结构对象,在位置0x3FE00000中创建访问冲突写入错误
- 销毁 Box2D 主体 - 读取访问冲突错误
- C++数组错误:访问冲突读取位置0xC0000005
- C++LinkedList错误:访问冲突错误
- 错误访问冲突写入位置0x00229C20.尝试在控制台中输入字符串时